Search in sources :

Example 1 with BerTag

use of com.beanit.asn1bean.ber.BerTag in project sandbox-java by stIncMale.

the class InAppAttribute 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(BerInteger.tag)) {
        type = new BerInteger();
        vByteCount += type.decode(is, false);
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (berTag.equals(BerInteger.tag)) {
        version = new BerInteger();
        vByteCount += version.decode(is, false);
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (berTag.equals(BerOctetString.tag)) {
        value = new BerOctetString();
        vByteCount += value.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) BerOctetString(com.beanit.asn1bean.ber.types.BerOctetString) IOException(java.io.IOException) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) BerTag(com.beanit.asn1bean.ber.BerTag)

Example 2 with BerTag

use of com.beanit.asn1bean.ber.BerTag in project sandbox-java by stIncMale.

the class InAppReceipt 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;
    while (vByteCount < lengthVal || lengthVal < 0) {
        vByteCount += berTag.decode(is);
        if (lengthVal < 0 && berTag.equals(0, 0, 0)) {
            vByteCount += BerLength.readEocByte(is);
            break;
        }
        if (!berTag.equals(InAppAttribute.tag)) {
            throw new IOException("Tag does not match mandatory sequence of/set of component.");
        }
        InAppAttribute element = new InAppAttribute();
        vByteCount += element.decode(is, false);
        seqOf.add(element);
    }
    if (lengthVal >= 0 && vByteCount != lengthVal) {
        throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + lengthVal + " but has " + vByteCount);
    }
    return tlByteCount + vByteCount;
}
Also used : BerLength(com.beanit.asn1bean.ber.BerLength) IOException(java.io.IOException) BerTag(com.beanit.asn1bean.ber.BerTag)

Example 3 with BerTag

use of com.beanit.asn1bean.ber.BerTag in project sandbox-java by stIncMale.

the class Payload 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;
    while (vByteCount < lengthVal || lengthVal < 0) {
        vByteCount += berTag.decode(is);
        if (lengthVal < 0 && berTag.equals(0, 0, 0)) {
            vByteCount += BerLength.readEocByte(is);
            break;
        }
        if (!berTag.equals(ReceiptAttribute.tag)) {
            throw new IOException("Tag does not match mandatory sequence of/set of component.");
        }
        ReceiptAttribute element = new ReceiptAttribute();
        vByteCount += element.decode(is, false);
        seqOf.add(element);
    }
    if (lengthVal >= 0 && vByteCount != lengthVal) {
        throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + lengthVal + " but has " + vByteCount);
    }
    return tlByteCount + vByteCount;
}
Also used : BerLength(com.beanit.asn1bean.ber.BerLength) IOException(java.io.IOException) BerTag(com.beanit.asn1bean.ber.BerTag)

Example 4 with BerTag

use of com.beanit.asn1bean.ber.BerTag in project jasn1 by openmuc.

the class BerAny method decode.

public int decode(InputStream is, BerTag tag) throws IOException {
    int byteCount = 0;
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    if (tag == null) {
        tag = new BerTag();
        byteCount = tag.decode(is, os);
    } else {
        tag.encode(os);
    }
    byteCount += DecodeUtil.decodeUnknownComponent(is, os);
    value = os.toByteArray();
    return byteCount;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BerTag(com.beanit.asn1bean.ber.BerTag)

Example 5 with BerTag

use of com.beanit.asn1bean.ber.BerTag 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

BerTag (com.beanit.asn1bean.ber.BerTag)10 BerLength (com.beanit.asn1bean.ber.BerLength)6 IOException (java.io.IOException)5 BerInteger (com.beanit.asn1bean.ber.types.BerInteger)2 BerOctetString (com.beanit.asn1bean.ber.types.BerOctetString)2 AsnBitString (com.beanit.asn1bean.compiler.model.AsnBitString)2 AsnCharacterString (com.beanit.asn1bean.compiler.model.AsnCharacterString)2 AsnElementType (com.beanit.asn1bean.compiler.model.AsnElementType)2 AsnOctetString (com.beanit.asn1bean.compiler.model.AsnOctetString)2 AsnTag (com.beanit.asn1bean.compiler.model.AsnTag)2 HexString (com.beanit.asn1bean.util.HexString)2 BerObjectDescriptor (com.beanit.asn1bean.ber.types.string.BerObjectDescriptor)1 AsnConstructedType (com.beanit.asn1bean.compiler.model.AsnConstructedType)1 AsnParameter (com.beanit.asn1bean.compiler.model.AsnParameter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1