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

ASN1Type

public abstract class ASN1Type extends Object implements ASN1Constants
This abstract class is the super class for all ASN.1 types
see
ASN.1

Fields Summary
public final int
id
Integer representation of primitive identifier.
public final int
constrId
Integer representation of constructed identifier.
Constructors Summary
public ASN1Type(int tagNumber)
Constructs a primitive, universal ASN.1 type.

param
tagNumber - ASN.1 tag number
throws
IllegalArgumentException - if tagNumber is invalid

        this(CLASS_UNIVERSAL, tagNumber);
    
public ASN1Type(int tagClass, int tagNumber)
Constructs an ASN.1 type.

param
tagClass - tag class. MUST be CLASS_UNIVERSAL, CLASS_APPLICATION, CLASS_CONTEXTSPECIFIC, CLASS_PRIVATE
param
isConstructed - is ASN.1 type is a constructed type.
param
tagNumber - ASN.1 tag number.
throws
IllegalArgumentException - if tagClass or tagNumber is invalid


        if (tagNumber < 0) {
            throw new IllegalArgumentException(Messages.getString("security.102")); //$NON-NLS-1$
        }

        if (tagClass != CLASS_UNIVERSAL && tagClass != CLASS_APPLICATION
                && tagClass != CLASS_CONTEXTSPECIFIC
                && tagClass != CLASS_PRIVATE) {
            throw new IllegalArgumentException(Messages.getString("security.103")); //$NON-NLS-1$
        }

        if (tagNumber < 31) {
            // short form
            this.id = tagClass + tagNumber;
        } else {
            // long form
            throw new IllegalArgumentException(
                    Messages.getString("security.104")); //$NON-NLS-1$
        }
        this.constrId = this.id + PC_CONSTRUCTED;
    
Methods Summary
public abstract booleancheckTag(int identifier)
Tests provided identifier.

param
identifier - identifier to be verified
return
- true if identifier is associated with this ASN.1 type, otherwise false

public final java.lang.Objectdecode(byte[] encoded)

        return decode(new DerInputStream(encoded));
    
public final java.lang.Objectdecode(byte[] encoded, int offset, int encodingLen)

        return decode(new DerInputStream(encoded, offset, encodingLen));
    
public final java.lang.Objectdecode(java.io.InputStream in)

        return decode(new DerInputStream(in));
    
public abstract java.lang.Objectdecode(BerInputStream in)
Decodes ASN.1 type.

param
in - BER input stream
throws
IOException - if an I/O error occurs or the end of the stream is reached

public final byte[]encode(java.lang.Object object)


        DerOutputStream out = new DerOutputStream(this, object);
        return out.encoded;
    
public abstract voidencodeASN(BerOutputStream out)
Encodes ASN.1 type.

param
out - BER output stream

public abstract voidencodeContent(BerOutputStream out)

protected java.lang.ObjectgetDecodedObject(BerInputStream in)
Creates decoded object. Derived classes should override this method to provide creation for a selected class of objects during decoding. The default implementation returns an object created by decoding stream.

param
- input stream
return
- created object

        return in.content;
    
public intgetEncodedLength(BerOutputStream out)

 //FIXME name

        //tag length
        int len = 1; //FIXME tag length = 1. what about long form?
        //for (; tag > 0; tag = tag >> 8, len++);

        // length length :-)
        len++;
        if (out.length > 127) {

            len++;
            for (int cur = out.length >> 8; cur > 0; len++) {
                cur = cur >> 8;
            }
        }
        len += out.length;

        return len;
    
public abstract voidsetEncodingContent(BerOutputStream out)

public java.lang.StringtoString()

        // TODO decide whether this method is necessary
        //FIXME fix performance
        return this.getClass().getName() + "(tag: 0x" //$NON-NLS-1$
                + Integer.toHexString(0xff & this.id) + ")"; //$NON-NLS-1$
    
public final voidverify(byte[] encoded)

        DerInputStream decoder = new DerInputStream(encoded);
        decoder.setVerify();
        decode(decoder);
    
public final voidverify(java.io.InputStream in)

        DerInputStream decoder = new DerInputStream(in);
        decoder.setVerify();
        decode(decoder);