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

BerOutputStream

public class BerOutputStream extends Object
Encodes ASN.1 types with BER (X.690)
see
ASN.1

Fields Summary
public byte[]
encoded
Encoded byte array
protected int
offset
current offset
public int
length
Current encoded length
public Object
content
Current encoded content
Constructors Summary
public BerOutputStream()

    
Methods Summary
public voidencodeANY()

        System.arraycopy(content, 0, encoded, offset, length);
        offset += length;
    
public voidencodeBitString()

        //FIXME check encoding
        BitString bStr = (BitString) content;
        encoded[offset] = (byte) bStr.unusedBits;
        System.arraycopy(bStr.bytes, 0, encoded, offset + 1, length - 1);
        offset += length;
    
public voidencodeBoolean()

        if (((Boolean) content).booleanValue()) {
            encoded[offset] = (byte) 0xFF;
        } else {
            encoded[offset] = 0x00;
        }
        offset++;
    
public voidencodeChoice(ASN1Choice choice)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidencodeExplicit(ASN1Explicit explicit)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidencodeGeneralizedTime()

        System.arraycopy(content, 0, encoded, offset, length);
        offset += length;
    
public voidencodeInteger()

        System.arraycopy(content, 0, encoded, offset, length);
        offset += length;
    
public voidencodeOID()


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

        int oidLen = length;

        // all subidentifiers except first
        int elem;
        for (int i = oid.length - 1; i > 1; i--, oidLen--) {
            elem = oid[i];
            if (elem > 127) {
                encoded[offset + oidLen - 1] = (byte) (elem & 0x7F);
                elem = elem >> 7;
                for (; elem > 0;) {
                    oidLen--;
                    encoded[offset + oidLen - 1] = (byte) (elem | 0x80);
                    elem = elem >> 7;
                }
            } else {
                encoded[offset + oidLen - 1] = (byte) elem;
            }
        }

        // first subidentifier
        elem = oid[0] * 40 + oid[1];
        if (elem > 127) {
            encoded[offset + oidLen - 1] = (byte) (elem & 0x7F);
            elem = elem >> 7;
            for (; elem > 0;) {
                oidLen--;
                encoded[offset + oidLen - 1] = (byte) (elem | 0x80);
                elem = elem >> 7;
            }
        } else {
            encoded[offset + oidLen - 1] = (byte) elem;
        }

        offset += length;
    
public voidencodeOctetString()

        System.arraycopy(content, 0, encoded, offset, length);
        offset += length;
    
public voidencodeSequence(ASN1Sequence sequence)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidencodeSequenceOf(ASN1SequenceOf sequenceOf)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidencodeSet(ASN1Set set)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidencodeSetOf(ASN1SetOf setOf)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidencodeString()

        System.arraycopy(content, 0, encoded, offset, length);
        offset += length;
    
public final voidencodeTag(int tag)


        encoded[offset++] = (byte) tag; //FIXME long form?

        if (length > 127) { //long form
            int eLen = length >> 8;
            byte numOctets = 1;
            for (; eLen > 0; eLen = eLen >> 8) {
                numOctets++;
            }

            encoded[offset] = (byte) (numOctets | 0x80);
            offset++;

            eLen = length;
            int numOffset = offset + numOctets - 1;
            for (int i = 0; i < numOctets; i++, eLen = eLen >> 8) {
                encoded[numOffset - i] = (byte) eLen; //FIXME long value?
            }
            offset += numOctets;
        } else { //short form
            encoded[offset++] = (byte) length;
        }
    
public voidencodeUTCTime()

        System.arraycopy(content, 0, encoded, offset, length);
        offset += length;
    
public voidgetChoiceLength(ASN1Choice choice)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidgetExplicitLength(ASN1Explicit sequence)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidgetSequenceLength(ASN1Sequence sequence)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidgetSequenceOfLength(ASN1SequenceOf sequence)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidgetSetLength(ASN1Set set)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public voidgetSetOfLength(ASN1SetOf setOf)

        throw new RuntimeException("Is not implemented yet"); //FIXME
    
public intgetStringLength(java.lang.Object object)

        throw new RuntimeException("Is not implemented yet"); //FIXME