Search in sources :

Example 1 with TaggedChoice

use of com.beanit.asn1bean.compiler.tagging_test.TaggedChoice in project jasn1 by openmuc.

the class TaggingTest method taggedChoiceTest.

@Test
public void taggedChoiceTest() throws Exception {
    TaggedChoice choice = new TaggedChoice();
    choice.setMyInteger(new BerInteger(1));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    choice.encode(os);
    assertArrayEquals(toBytes("BF2205A403020101"), os.getArray());
    choice = new TaggedChoice();
    choice.decode(new ByteArrayInputStream(os.getArray()));
    assertNotNull(choice.getMyInteger());
    assertNull(choice.getMyBoolean());
}
Also used : 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) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 2 with TaggedChoice

use of com.beanit.asn1bean.compiler.tagging_test.TaggedChoice 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 3 with TaggedChoice

use of com.beanit.asn1bean.compiler.tagging_test.TaggedChoice in project jasn1 by openmuc.

the class TaggingTest method taggedChoiceIndefiniteTest.

@Test
public void taggedChoiceIndefiniteTest() throws Exception {
    byte[] code = toBytes("BF2280A48002010100000000");
    TaggedChoice taggedChoice = new TaggedChoice();
    InputStream is = new ByteArrayInputStream(code);
    int numDecodedBytes = taggedChoice.decode(is);
    assertNotNull(taggedChoice.getMyInteger());
    assertEquals(-1, is.read());
    assertEquals(code.length, numDecodedBytes);
}
Also used : TaggedChoice(com.beanit.asn1bean.compiler.tagging_test.TaggedChoice) ImplicitlyRetaggedTaggedChoice(com.beanit.asn1bean.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ImplicitlyRetaggedTaggedChoice (com.beanit.asn1bean.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 TaggedChoice (com.beanit.asn1bean.compiler.tagging_test.TaggedChoice)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Test (org.junit.jupiter.api.Test)3 ReverseByteArrayOutputStream (com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)2 BerInteger (com.beanit.asn1bean.ber.types.BerInteger)2 BerAny (com.beanit.asn1bean.ber.types.BerAny)1 BerBoolean (com.beanit.asn1bean.ber.types.BerBoolean)1 RetaggedUntaggedChoice (com.beanit.asn1bean.compiler.tagging_test.RetaggedUntaggedChoice)1 SequenceOfDirectTypes (com.beanit.asn1bean.compiler.tagging_test.SequenceOfDirectTypes)1 InputStream (java.io.InputStream)1