Search in sources :

Example 1 with BerInteger

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

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

the class TaggingTest method implicitlyRetaggedTaggedChoiceTest.

@Test
public void implicitlyRetaggedTaggedChoiceTest() throws Exception {
    ImplicitlyRetaggedTaggedChoice choice = new ImplicitlyRetaggedTaggedChoice();
    choice.setMyInteger(new BerInteger(1));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    choice.encode(os);
    assertArrayEquals(toBytes("A305A403020101"), os.getArray());
}
Also used : ImplicitlyRetaggedTaggedChoice(com.beanit.asn1bean.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 3 with BerInteger

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

the class TaggingTest method seqOfExplicitlyTaggedTypeTest.

@Test
public void seqOfExplicitlyTaggedTypeTest() throws Exception {
    SeqOfExplicitlyTaggedType seqOf = new SeqOfExplicitlyTaggedType();
    List<BerInteger> integerList = seqOf.getBerInteger();
    integerList.add(new BerInteger(3));
    integerList.add(new BerInteger(4));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    seqOf.encode(os);
    assertArrayEquals(toBytes("300AA303020103A303020104"), os.getArray());
    seqOf = new SeqOfExplicitlyTaggedType();
    seqOf.decode(new ByteArrayInputStream(os.getArray()));
}
Also used : SeqOfExplicitlyTaggedType(com.beanit.asn1bean.compiler.tagging_test.SeqOfExplicitlyTaggedType) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 4 with BerInteger

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

the class TaggingTest method retaggedChoiceTest.

@Test
public void retaggedChoiceTest() throws Exception {
    RetaggedUntaggedChoice choice = new RetaggedUntaggedChoice();
    choice.setMyInteger(new BerInteger(1));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    choice.encode(os);
    assertArrayEquals(toBytes("BF2103830101"), os.getArray());
    choice = new RetaggedUntaggedChoice();
    choice.decode(new ByteArrayInputStream(os.getArray()));
    assertNotNull(choice.getMyInteger());
    assertNull(choice.getMyBoolean());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RetaggedUntaggedChoice(com.beanit.asn1bean.compiler.tagging_test.RetaggedUntaggedChoice) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 5 with BerInteger

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

the class TaggingTest method explicitlyTaggedSeqOfTest.

@Test
public void explicitlyTaggedSeqOfTest() throws Exception {
    ExplicitlyTaggedSeqOf seqOf = new ExplicitlyTaggedSeqOf();
    List<BerInteger> integerList = seqOf.getBerInteger();
    integerList.add(new BerInteger(3));
    integerList.add(new BerInteger(4));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    seqOf.encode(os);
    assertArrayEquals(toBytes("BF21083006020103020104"), os.getArray());
    seqOf = new ExplicitlyTaggedSeqOf();
    seqOf.decode(new ByteArrayInputStream(os.getArray()));
}
Also used : ExplicitlyTaggedSeqOf(com.beanit.asn1bean.compiler.tagging_test.ExplicitlyTaggedSeqOf) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

BerInteger (com.beanit.asn1bean.ber.types.BerInteger)16 ReverseByteArrayOutputStream (com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)14 Test (org.junit.jupiter.api.Test)13 ByteArrayInputStream (java.io.ByteArrayInputStream)10 BerAny (com.beanit.asn1bean.ber.types.BerAny)3 BerBoolean (com.beanit.asn1bean.ber.types.BerBoolean)3 BerVisibleString (com.beanit.asn1bean.ber.types.string.BerVisibleString)3 ImplicitlyRetaggedTaggedChoice (com.beanit.asn1bean.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 BerLength (com.beanit.asn1bean.ber.BerLength)2 BerTag (com.beanit.asn1bean.ber.BerTag)2 BerOctetString (com.beanit.asn1bean.ber.types.BerOctetString)2 NonExtensibleSequence (com.beanit.asn1bean.compiler.extension_test.non_extensible.NonExtensibleSequence)2 RetaggedUntaggedChoice (com.beanit.asn1bean.compiler.tagging_test.RetaggedUntaggedChoice)2 TaggedChoice (com.beanit.asn1bean.compiler.tagging_test.TaggedChoice)2 IOException (java.io.IOException)2 BerEmbeddedPdv (com.beanit.asn1bean.ber.types.BerEmbeddedPdv)1 ExtensibleAccessSequence (com.beanit.asn1bean.compiler.extension_test.extensible_with_access.ExtensibleAccessSequence)1 ExtensibleAccessSequenceAndMore (com.beanit.asn1bean.compiler.extension_test.extensible_with_access.ExtensibleAccessSequenceAndMore)1 ExtendedSequence (com.beanit.asn1bean.compiler.extension_test.non_extensible.ExtendedSequence)1 ExtendedSequenceAndMore (com.beanit.asn1bean.compiler.extension_test.non_extensible.ExtendedSequenceAndMore)1