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

ASN1Oid

public class ASN1Oid extends ASN1Primitive
This class represents ASN.1 Object Identifier type.
see
ASN.1

Fields Summary
private static final ASN1Oid
ASN1
private static final ASN1Oid
STRING_OID
Constructors Summary
public ASN1Oid()
Constructs ASN.1 Object Identifier type The constructor is provided for inheritance purposes when there is a need to create a custom ASN.1 Object Identifier type. To get a default implementation it is recommended to use getInstance() method.


                                               
      
        super(TAG_OID);
    
Methods Summary
public java.lang.Objectdecode(BerInputStream in)

        in.readOID();

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

        out.encodeOID();
    
public java.lang.ObjectgetDecodedObject(BerInputStream in)
Extracts array of integers from BER input stream.

param
in - BER input stream
return
array of integers

        // Allocate and decode
        int oidElement = in.oidElement;
        int[] oid = new int[oidElement];
        for (int id = 1, i = 0; id < oid.length; id++, i++) {
            int octet = in.buffer[in.contentOffset + i];
            oidElement = octet & 0x7F;
            while ((octet & 0x80) != 0) {
                i++;
                octet = in.buffer[in.contentOffset + i];
                oidElement = oidElement << 7 | (octet & 0x7f);
            }
            oid[id] = oidElement;
        }
        // Special handling for the first packed OID element
        if (oid[1] > 79) {
            oid[0] = 2;
            oid[1] = oid[1] - 80;
        } else {
            oid[0] = oid[1] / 40;
            oid[1] = oid[1] % 40;
        }
        return oid;
    
public static org.apache.harmony.security.asn1.ASN1OidgetInstance()
Returns ASN.1 Object Identifier type default implementation The default implementation works with encoding that is represented as array of integers.

return
ASN.1 Object Identifier type default implementation

        return ASN1;
    
public static org.apache.harmony.security.asn1.ASN1OidgetInstanceForString()
Returns ASN.1 Object Identifier type implementation This implementation works with encoding that is mapped to java.lang.String object.

return
ASN.1 Object Identifier type implementation


                                 
        
        return STRING_OID;
    
public voidsetEncodingContent(BerOutputStream out)

        int[] oid = (int[]) out.content;

        int length = 0;

        // first subidentifier
        int elem = oid[0] * 40 + oid[1];
        if (elem == 0) {
            length = 1;
        } else {
            for (; elem > 0; elem = elem >> 7) {
                length++;
            }
        }

        // the rest of subidentifiers
        for (int i = 2; i < oid.length; i++) {
            if (oid[i] == 0) {
                length++;
                continue;
            }
            for (elem = oid[i]; elem > 0; elem = elem >> 7) {
                length++;
            }
        }
        out.length = length;