Search in sources :

Example 1 with BerObjectDescriptor

use of com.beanit.asn1bean.ber.types.string.BerObjectDescriptor in project jasn1 by openmuc.

the class BerEmbeddedPdv method decode.

public int decode(InputStream is, boolean withTag) throws IOException {
    int tlByteCount = 0;
    int vByteCount = 0;
    BerTag berTag = new BerTag();
    if (withTag) {
        tlByteCount += tag.decodeAndCheck(is);
    }
    BerLength length = new BerLength();
    tlByteCount += length.decode(is);
    int lengthVal = length.val;
    vByteCount += berTag.decode(is);
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
        vByteCount += length.decode(is);
        identification = new Identification();
        vByteCount += identification.decode(is, null);
        vByteCount += length.readEocIfIndefinite(is);
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
        dataValueDescriptor = new BerObjectDescriptor();
        vByteCount += dataValueDescriptor.decode(is, false);
        vByteCount += berTag.decode(is);
    }
    if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
        dataValue = new BerOctetString();
        vByteCount += dataValue.decode(is, false);
        if (lengthVal >= 0 && vByteCount == lengthVal) {
            return tlByteCount + vByteCount;
        }
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (lengthVal < 0) {
        if (!berTag.equals(0, 0, 0)) {
            throw new IOException("Decoded sequence has wrong end of contents octets");
        }
        vByteCount += BerLength.readEocByte(is);
        return tlByteCount + vByteCount;
    }
    throw new IOException("Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount);
}
Also used : BerLength(com.beanit.asn1bean.ber.BerLength) BerObjectDescriptor(com.beanit.asn1bean.ber.types.string.BerObjectDescriptor) IOException(java.io.IOException) BerTag(com.beanit.asn1bean.ber.BerTag)

Aggregations

BerLength (com.beanit.asn1bean.ber.BerLength)1 BerTag (com.beanit.asn1bean.ber.BerTag)1 BerObjectDescriptor (com.beanit.asn1bean.ber.types.string.BerObjectDescriptor)1 IOException (java.io.IOException)1