Search in sources :

Example 1 with BerLength

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

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

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

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

Example 5 with BerLength

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

the class BerInteger method decode.

public int decode(InputStream is, boolean withTag) throws IOException {
    int codeLength = 0;
    if (withTag) {
        codeLength += tag.decodeAndCheck(is);
    }
    BerLength length = new BerLength();
    codeLength += length.decode(is);
    if (length.val < 1) {
        throw new IOException("Decoded length of BerInteger is not correct");
    }
    byte[] byteCode = new byte[length.val];
    Util.readFully(is, byteCode);
    codeLength += length.val;
    value = new BigInteger(byteCode);
    return codeLength;
}
Also used : BerLength(com.beanit.asn1bean.ber.BerLength) BigInteger(java.math.BigInteger) IOException(java.io.IOException)

Aggregations

BerLength (com.beanit.asn1bean.ber.BerLength)14 IOException (java.io.IOException)11 BerTag (com.beanit.asn1bean.ber.BerTag)6 EOFException (java.io.EOFException)3 BerInteger (com.beanit.asn1bean.ber.types.BerInteger)2 BerOctetString (com.beanit.asn1bean.ber.types.BerOctetString)2 BerObjectDescriptor (com.beanit.asn1bean.ber.types.string.BerObjectDescriptor)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1