Search in sources :

Example 11 with BerInteger

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

the class TaggingTest method sequenceOfDirectTypesTest.

@Test
public void sequenceOfDirectTypesTest() throws Exception {
    SequenceOfDirectTypes sequence = new SequenceOfDirectTypes();
    sequence.setUntaggedInt(new BerInteger(1));
    sequence.setExplicitlyTaggedInt(new BerInteger(2));
    sequence.setImplicitlyTaggedInt(new BerInteger(3));
    SequenceOfDirectTypes.UntaggedChoice untaggedChoice = new SequenceOfDirectTypes.UntaggedChoice();
    untaggedChoice.setMyBoolean(new BerBoolean(true));
    sequence.setUntaggedChoice(untaggedChoice);
    SequenceOfDirectTypes.TaggedChoice taggedChoice = new SequenceOfDirectTypes.TaggedChoice();
    taggedChoice.setMyInteger(new BerInteger(4));
    sequence.setTaggedChoice(taggedChoice);
    sequence.setTaggedAny(new BerAny(new byte[] { 2, 1, 1 }));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    sequence.encode(os);
    assertArrayEquals(toBytes("BF2B18020101A1030201028201038401FFA503830104A603020101"), os.getArray());
    sequence = new SequenceOfDirectTypes();
    sequence.decode(new ByteArrayInputStream(os.getArray()));
    assertEquals(1, sequence.getUntaggedInt().value.intValue());
    assertEquals(2, sequence.getExplicitlyTaggedInt().value.intValue());
    assertEquals(3, sequence.getImplicitlyTaggedInt().value.intValue());
    assertTrue(untaggedChoice.getMyBoolean().value);
    assertEquals(4, sequence.getTaggedChoice().getMyInteger().value.intValue());
    assertArrayEquals(toBytes("020101"), sequence.getTaggedAny().value);
    assertNull(sequence.getUntaggedChoice2());
}
Also used : SequenceOfDirectTypes(com.beanit.asn1bean.compiler.tagging_test.SequenceOfDirectTypes) BerBoolean(com.beanit.asn1bean.ber.types.BerBoolean) RetaggedUntaggedChoice(com.beanit.asn1bean.compiler.tagging_test.RetaggedUntaggedChoice) TaggedChoice(com.beanit.asn1bean.compiler.tagging_test.TaggedChoice) ImplicitlyRetaggedTaggedChoice(com.beanit.asn1bean.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) BerAny(com.beanit.asn1bean.ber.types.BerAny) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 12 with BerInteger

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

the class TaggingTest method explicitlyTaggedSetOfTest.

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

Example 13 with BerInteger

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

the class AnyTypeTest method encodingAny.

@Test
public void encodingAny() throws Exception {
    SimpleSeq simpleSeq = new SimpleSeq(new BerInteger(2));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    simpleSeq.encode(os);
    System.out.println(HexString.fromBytes(os.getArray()));
    assertArrayEquals(toBytes("3003800102"), os.getArray());
    SeqContainingAnyDefinedBy seqContainingAnyDefinedBy = new SeqContainingAnyDefinedBy(new BerAny(os.getArray()));
    os.reset();
    seqContainingAnyDefinedBy.encode(os);
    System.out.println(HexString.fromBytes(os.getArray()));
    assertArrayEquals(toBytes("3007A0053003800102"), os.getArray());
}
Also used : BerInteger(com.beanit.asn1bean.ber.types.BerInteger) SeqContainingAnyDefinedBy(com.beanit.asn1bean.compiler.various_tests.SeqContainingAnyDefinedBy) BerAny(com.beanit.asn1bean.ber.types.BerAny) SimpleSeq(com.beanit.asn1bean.compiler.various_tests.SimpleSeq) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 14 with BerInteger

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

the class ExtensibilityImpliedTest method setExtensionBytes.

@Test
void setExtensionBytes() throws IOException {
    NonExtensibleSequence nonExtensibleSequence = new NonExtensibleSequence();
    nonExtensibleSequence.setAge(new BerInteger(5));
    ExtensibleAccessSequence extensibleSequence = new ExtensibleAccessSequence();
    extensibleSequence.setAge(new BerInteger(5));
    extensibleSequence.setExtensionBytes(extensionCode);
    ExtensibleAccessSequenceAndMore extensibleSequenceAndMore = new ExtensibleAccessSequenceAndMore();
    extensibleSequenceAndMore.setExtensibleSequence(extensibleSequence);
    extensibleSequenceAndMore.setMore(new BerVisibleString("more"));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(100, true);
    extensibleSequenceAndMore.encode(os);
    Assertions.assertArrayEquals(extendedSequenceAndMoreCode, os.getArray());
}
Also used : ExtensibleAccessSequence(com.beanit.asn1bean.compiler.extension_test.extensible_with_access.ExtensibleAccessSequence) ExtensibleAccessSequenceAndMore(com.beanit.asn1bean.compiler.extension_test.extensible_with_access.ExtensibleAccessSequenceAndMore) NonExtensibleSequence(com.beanit.asn1bean.compiler.extension_test.non_extensible.NonExtensibleSequence) BerVisibleString(com.beanit.asn1bean.ber.types.string.BerVisibleString) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 15 with BerInteger

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

the class ExtensibilityImpliedTest method computeCode.

@BeforeAll
static void computeCode() throws IOException {
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(100, true);
    NonExtensibleSequence nonExtensibleSequence = new NonExtensibleSequence();
    nonExtensibleSequence.setAge(new BerInteger(5));
    os.reset();
    nonExtensibleSequence.encode(os);
    byte[] nonExtensibleSequenceCode = os.getArray();
    ExtendedSequence extendedSequence = new ExtendedSequence();
    extendedSequence.setAge(new BerInteger(5));
    extendedSequence.setName(new BerVisibleString("name"));
    extendedSequence.setSubAge(nonExtensibleSequence);
    os.reset();
    extendedSequence.encode(os);
    byte[] extendedSequenceCode = os.getArray();
    extensionCode = Arrays.copyOfRange(extendedSequenceCode, nonExtensibleSequenceCode.length, extendedSequenceCode.length);
    ExtendedSequenceAndMore extendedSequenceAndMore = new ExtendedSequenceAndMore();
    extendedSequenceAndMore.setExtendedSequence(extendedSequence);
    extendedSequenceAndMore.setMore(new BerVisibleString("more"));
    os.reset();
    extendedSequenceAndMore.encode(os);
    extendedSequenceAndMoreCode = os.getArray();
}
Also used : NonExtensibleSequence(com.beanit.asn1bean.compiler.extension_test.non_extensible.NonExtensibleSequence) BerVisibleString(com.beanit.asn1bean.ber.types.string.BerVisibleString) ExtendedSequenceAndMore(com.beanit.asn1bean.compiler.extension_test.non_extensible.ExtendedSequenceAndMore) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ExtendedSequence(com.beanit.asn1bean.compiler.extension_test.non_extensible.ExtendedSequence) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) BeforeAll(org.junit.jupiter.api.BeforeAll)

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