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

DerInputStream

public final class DerInputStream extends BerInputStream
Decodes ASN.1 types encoded with DER (X.690)
see
ASN.1

Fields Summary
private static final byte[]
UNUSED_BITS_MASK
Constructors Summary
public DerInputStream(byte[] encoded)

        super(encoded, 0, encoded.length);
    
public DerInputStream(byte[] encoded, int offset, int encodingLen)

        super(encoded, offset, encodingLen);
    
public DerInputStream(InputStream in)

        super(in);
    
Methods Summary
public final intnext()

see
org.apache.harmony.security.asn1.BerInputStream#next()


        int tag = super.next();

        if (length == INDEFINIT_LENGTH) {
            throw new ASN1Exception(Messages.getString("security.105")); //$NON-NLS-1$
        }

        // FIXME add check: length encoding uses minimum number of octets

        return tag;
    
public voidreadBitString()

see
org.apache.harmony.security.asn1.BerInputStream#readBitString()



           
         

        if (tag == ASN1Constants.TAG_C_BITSTRING) {
            throw new ASN1Exception(Messages.getString("security.106", tagOffset)); //$NON-NLS-1$
        }

        super.readBitString();

        //check: unused bits values - MUST be 0
        if (length > 1
                && buffer[contentOffset] != 0
                && (buffer[offset - 1] & UNUSED_BITS_MASK[buffer[contentOffset] - 1]) != 0) {
            throw new ASN1Exception(Messages.getString("security.107", contentOffset)); //$NON-NLS-1$
        }
    
public voidreadBoolean()

see
org.apache.harmony.security.asn1.BerInputStream#readBoolean()


        super.readBoolean();

        // check encoded content
        if (buffer[contentOffset] != 0 && buffer[contentOffset] != (byte) 0xFF) {
            throw new ASN1Exception(Messages.getString("security.108", contentOffset)); //$NON-NLS-1$
        }
    
public voidreadGeneralizedTime()

see
org.apache.harmony.security.asn1.BerInputStream#readGeneralizedTime()


        if (tag == ASN1Constants.TAG_C_GENERALIZEDTIME) {
            // It is a string type and it can be encoded as primitive or constructed.
            throw new ASN1Exception(Messages.getString("security.10D", tagOffset)); //$NON-NLS-1$
        }

        super.readGeneralizedTime();

        // FIXME makes sense only if we support all GeneralizedTime formats 
        // late check syntax: the last char MUST be Z
        //if (buffer[offset - 1] != 'Z') {
        //    throw new ASN1Exception(
        //            "ASN.1 GeneralizedTime wrongly encoded at ["
        //                    + contentOffset + ']');
        //}

        // the fractional-seconds elements, if present MUST
        // omit all trailing zeros
        // FIXME implement me
        //        if () {
        //            throw new IOException(
        //                    "DER ASN.1 GeneralizedTime wrongly encoded at ["
        //                            + contentOffset
        //                            + "]. Trailing zeros MUST be omitted");
        //        }
    
public voidreadOctetString()

see
org.apache.harmony.security.asn1.BerInputStream#readOctetString()


        if (tag == ASN1Constants.TAG_C_OCTETSTRING) {
            throw new ASN1Exception(
                    Messages.getString("security.109", tagOffset)); //$NON-NLS-1$
        }
        super.readOctetString();
    
public voidreadSequence(ASN1Sequence sequence)

see
org.apache.harmony.security.asn1.BerInputStream#readSequence(org.apache.harmony.security.asn1.ASN1Sequence)

        //
        // According to ASN.1 DER spec. sequence MUST not include
        // any encoding which value is equal to its default value
        //
        // Verification of this assertion is not implemented
        //
        super.readSequence(sequence);
    
public voidreadSetOf(ASN1SetOf setOf)

see
org.apache.harmony.security.asn1.BerInputStream#readSetOf(org.apache.harmony.security.asn1.ASN1SetOf)

        //
        // According to ASN.1 DER spec. set of MUST appear in
        // ascending order (short component are padded for comparison)
        //
        // Verification of this assertion is not implemented
        //
        super.readSetOf(setOf);
    
public voidreadString(ASN1StringType type)

see
org.apache.harmony.security.asn1.BerInputStream#readString(ASN1StringType)


        if (tag == type.constrId) {
            throw new ASN1Exception(Messages.getString("security.10A", tagOffset)); //$NON-NLS-1$
        }
        super.readString(type);
    
public voidreadUTCTime()

see
org.apache.harmony.security.asn1.BerInputStream#readUTCTime()


        if (tag == ASN1Constants.TAG_C_UTCTIME) {
            // It is a string type and it can be encoded as primitive or constructed.
            throw new ASN1Exception(Messages.getString("security.10B", tagOffset)); //$NON-NLS-1$
        }

        // check format: DER uses YYMMDDHHMMSS'Z' only
        if (length != ASN1UTCTime.UTC_HMS) {
            throw new ASN1Exception(Messages.getString("security.10C", tagOffset)); //$NON-NLS-1$
        }

        super.readUTCTime();