FileDocCategorySizeDatePackage
ASN1Implicit.javaAPI DocAndroid 1.5 API5237Wed May 06 22:41:06 BST 2009org.apache.harmony.security.asn1

ASN1Implicit

public class ASN1Implicit extends ASN1Type
Implicitly tagged ASN.1 type.
see
ASN.1

Fields Summary
private static final int
TAGGING_PRIMITIVE
private static final int
TAGGING_CONSTRUCTED
private static final int
TAGGING_STRING
private final ASN1Type
type
private final int
taggingType
Constructors Summary
public ASN1Implicit(int tagNumber, ASN1Type type)
Constructs implicitly tagged ASN.1 type with context-specific tag class and specified tag number.

param
tagNumber - ASN.1 tag number
param
type - ASN.1 type to be tagged
throws
IllegalArgumentException - if tagNumber or type is invalid


                                               
         
        this(CLASS_CONTEXTSPECIFIC, tagNumber, type);
    
public ASN1Implicit(int tagClass, int tagNumber, ASN1Type type)
Constructs implicitly tagged ASN.1 type

param
tagClass - ASN.1 tag class.
param
tagNumber - ASN.1 tag number
param
type - ASN.1 type to be tagged
throws
IllegalArgumentException - if tagNumber, tagClass or type is invalid

        super(tagClass, tagNumber);

        if ((type instanceof ASN1Choice) || (type instanceof ASN1Any)) {
            // According to X.680:
            // 'The IMPLICIT alternative shall not be used if the type
            // defined by "Type" is an untagged choice type or an 
            // untagged open type'
            throw new IllegalArgumentException(
                    Messages.getString("security.9F")); //$NON-NLS-1$
        }

        this.type = type;

        if (type.checkTag(type.id)) {
            if (type.checkTag(type.constrId)) {
                // the base encoding can be primitive ot constructed
                // use both encodings
                taggingType = TAGGING_STRING;
            } else {
                // if the base encoding is primitive use primitive encoding
                taggingType = TAGGING_PRIMITIVE;
            }
        } else {
            // if the base encoding is constructed use constructed encoding
            taggingType = TAGGING_CONSTRUCTED;
        }
    
Methods Summary
public final booleancheckTag(int identifier)
TODO

        switch (taggingType) {
        case TAGGING_PRIMITIVE:
            return id == identifier;
        case TAGGING_CONSTRUCTED:
            return constrId == identifier;
        default: // TAGGING_STRING
            return id == identifier || constrId == identifier;
        }
    
public java.lang.Objectdecode(BerInputStream in)
TODO

        if (!checkTag(in.tag)) {
            // FIXME need look for tagging type
            throw new ASN1Exception(Messages.getString("security.100", //$NON-NLS-1$
                    new Object[] { in.tagOffset, Integer.toHexString(id),
                            Integer.toHexString(in.tag) }));
        }

        // substitute indentifier for further decoding
        if (id == in.tag) {
            in.tag = type.id;
        } else {
            in.tag = type.constrId;
        }
        in.content = type.decode(in);

        if (in.isVerify) {
            return null;
        }
        return getDecodedObject(in);
    
public voidencodeASN(BerOutputStream out)

        //FIXME need another way for specifying identifier to be encoded
        if (taggingType == TAGGING_CONSTRUCTED) {
            out.encodeTag(constrId);
        } else {
            out.encodeTag(id);
        }
        encodeContent(out);
    
public voidencodeContent(BerOutputStream out)

        type.encodeContent(out);
    
public voidsetEncodingContent(BerOutputStream out)

        type.setEncodingContent(out);