FileDocCategorySizeDatePackage
ASN1TaggedObject.javaAPI DocAndroid 1.5 API4220Wed May 06 22:41:06 BST 2009org.bouncycastle.asn1

ASN1TaggedObject

public abstract class ASN1TaggedObject extends DERObject
ASN.1 TaggedObject - in ASN.1 nottation this is any object proceeded by a [n] where n is some number - these are assume to follow the construction rules (as with sequences).

Fields Summary
int
tagNo
boolean
empty
boolean
explicit
DEREncodable
obj
Constructors Summary
public ASN1TaggedObject(int tagNo, DEREncodable obj)
Create a tagged object in the explicit style.

param
tagNo the tag number for this object.
param
obj the tagged object.

        this.explicit = true;
        this.tagNo = tagNo;
        this.obj = obj;
    
public ASN1TaggedObject(boolean explicit, int tagNo, DEREncodable obj)
Create a tagged object with the style given by the value of explicit.

If the object implements ASN1Choice the tag style will always be changed to explicit in accordance with the ASN.1 encoding rules.

param
explicit true if the object is explicitly tagged.
param
tagNo the tag number for this object.
param
obj the tagged object.

        if (obj instanceof ASN1Choice)
        {
            this.explicit = true;
        }
        else
        {
            this.explicit = explicit;
        }
        
        this.tagNo = tagNo;
        this.obj = obj;
    
Methods Summary
abstract voidencode(DEROutputStream out)

public booleanequals(java.lang.Object o)

        if (!(o instanceof ASN1TaggedObject))
        {
            return false;
        }
        
        ASN1TaggedObject other = (ASN1TaggedObject)o;
        
        if (tagNo != other.tagNo || empty != other.empty || explicit != other.explicit)
        {
            return false;
        }
        
        if(obj == null)
        {
            if(other.obj != null)
            {
                return false;
            }
        }
        else
        {
            if(!(obj.equals(other.obj)))
            {
                return false;
            }
        }
        
        return true;
    
public static org.bouncycastle.asn1.ASN1TaggedObjectgetInstance(org.bouncycastle.asn1.ASN1TaggedObject obj, boolean explicit)


       
            
                     
    
        if (explicit)
        {
            return (ASN1TaggedObject)obj.getObject();
        }

        throw new IllegalArgumentException("implicitly tagged tagged object");
    
public static org.bouncycastle.asn1.ASN1TaggedObjectgetInstance(java.lang.Object obj)

        if (obj == null || obj instanceof ASN1TaggedObject) 
        {
                return (ASN1TaggedObject)obj;
        }

        throw new IllegalArgumentException("unknown object in getInstance");
    
public DERObjectgetObject()
return whatever was following the tag.

Note: tagged objects are generally context dependent if you're trying to extract a tagged object you should be going via the appropriate getInstance method.

        if (obj != null)
        {
            return obj.getDERObject();
        }

        return null;
    
public intgetTagNo()

        return tagNo;
    
public inthashCode()

        int code = tagNo;

        if (obj != null)
        {
            code ^= obj.hashCode();
        }

        return code;
    
public booleanisEmpty()

        return empty;
    
public booleanisExplicit()
return whether or not the object may be explicitly tagged.

Note: if the object has been read from an input stream, the only time you can be sure if isExplicit is returning the true state of affairs is if it returns false. An implicitly tagged object may appear to be explicitly tagged, so you need to understand the context under which the reading was done as well, see getObject below.

        return explicit;
    
public java.lang.StringtoString()

        return "[" + tagNo + "]" + obj;