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());
}
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()));
}
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());
}
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());
}
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();
}
Aggregations