use of com.beanit.asn1bean.ber.types.BerInteger in project jasn1 by openmuc.
the class TaggingTest method explicitlyTaggedSetTest.
@Test
public void explicitlyTaggedSetTest() throws Exception {
ExplicitlyTaggedSet set = new ExplicitlyTaggedSet();
set.setMyInteger(new BerInteger(1));
set.setMyBoolean(new BerBoolean(true));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
set.encode(os);
assertArrayEquals(toBytes("BF210a3108a1030201010101FF"), os.getArray());
set = new ExplicitlyTaggedSet();
set.decode(new ByteArrayInputStream(os.getArray()));
assertNotNull(set.getMyInteger());
assertNotNull(set.getMyBoolean());
}
use of com.beanit.asn1bean.ber.types.BerInteger in project jasn1 by openmuc.
the class TaggingTest method explicitlyTaggedSequenceTest.
@Test
public void explicitlyTaggedSequenceTest() throws Exception {
ExplicitlyTaggedSequence sequence = new ExplicitlyTaggedSequence();
sequence.setMyInteger(new BerInteger(1));
sequence.setMyBoolean(new BerBoolean(true));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
sequence.encode(os);
byte[] code = toBytes("BF210830060201010101FF");
assertArrayEquals(code, os.getArray());
sequence = new ExplicitlyTaggedSequence();
int numDecodedBytes = sequence.decode(new ByteArrayInputStream(os.getArray()));
assertNotNull(sequence.getMyInteger());
assertNotNull(sequence.getMyBoolean());
assertEquals(code.length, numDecodedBytes);
}
use of com.beanit.asn1bean.ber.types.BerInteger 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());
}
use of com.beanit.asn1bean.ber.types.BerInteger in project jasn1 by openmuc.
the class ModulesTest method encodingDecoding.
@Test
public void encodingDecoding() throws IOException {
ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
MyDate1 dateOfHire = new MyDate1();
dateOfHire.value = "19710917".getBytes(UTF_8);
dateOfHire.encode(berOS, true);
MyInt2 myInt2Encode = new MyInt2(2);
berOS.reset();
myInt2Encode.encode(berOS, true);
MyInt2 myInt2Decode = new MyInt2();
byte[] code = HexString.toBytes("a303020102");
InputStream is = new ByteArrayInputStream(code);
myInt2Decode.decode(is, true);
assertEquals(myInt2Decode.value.intValue(), 2);
PersonnelRecord pr = new PersonnelRecord();
Name name = new Name();
name.setGivenName(new BerVisibleString("givenName".getBytes(UTF_8)));
name.setFamilyName(new BerVisibleString("familyName".getBytes(UTF_8)));
name.setInitial(new BerVisibleString("initial".getBytes(UTF_8)));
pr.setName(name);
pr.setTitle(new BerVisibleString("title".getBytes(UTF_8)));
pr.setNumber(new EmployeeNumberZ(1));
pr.setDateOfHire(new Date("23121981".getBytes(UTF_8)));
pr.setNameOfSpouse(name);
ChildInformation child = new ChildInformation();
child.setName(new Name("child name".getBytes(UTF_8)));
child.setDateOfBirth(new Date("12121912".getBytes(UTF_8)));
PersonnelRecord.Children children = new PersonnelRecord.Children();
List<ChildInformation> childInformation = children.getChildInformation();
childInformation.add(child);
childInformation.add(child);
pr.setTestBitString(new MyBitString(new byte[] { (byte) 0x80, (byte) 0xff }, 10));
pr.setTest(new MyInt(3));
TestChoice testChoice = new TestChoice();
testChoice.setChoiceElement1(child);
pr.setTest2(testChoice);
pr.setTest3(testChoice);
pr.setTest4(testChoice);
pr.setTest5(testChoice);
pr.setTest6(testChoice);
TestSequenceOf testSequenceOf = new TestSequenceOf();
List<BerInteger> berIntegers = testSequenceOf.getBerInteger();
for (int i = 0; i < 10; i++) {
berIntegers.add(new BerInteger(i));
}
pr.setTestSequenceOf(testSequenceOf);
PersonnelRecord.TestSequenceOf2 testSequenceOf2 = new PersonnelRecord.TestSequenceOf2();
List<PersonnelRecord.TestSequenceOf2.SEQUENCE> sequences = testSequenceOf2.getSEQUENCE();
for (int i = 0; i < 10; i++) {
PersonnelRecord.TestSequenceOf2.SEQUENCE sequence = new PersonnelRecord.TestSequenceOf2.SEQUENCE();
sequence.setTest1(new BerInteger(i++));
sequence.setTest2(new BerInteger(i));
sequences.add(sequence);
}
pr.setTestSequenceOf2(testSequenceOf2);
BerEmbeddedPdv berEmbeddedPdv = new BerEmbeddedPdv();
pr.setEmbeddedPdv(berEmbeddedPdv);
}
use of com.beanit.asn1bean.ber.types.BerInteger in project jasn1 by openmuc.
the class PresentationLayerTest method encodingDecoding.
@Test
public void encodingDecoding() throws IOException {
ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
List<TransferSyntaxName> berObjectIdentifierList = new ArrayList<>(1);
berObjectIdentifierList.add(new TransferSyntaxName(new int[] { 2, 1, 1 }));
ContextList.SEQUENCE.TransferSyntaxNameList tsnl = new ContextList.SEQUENCE.TransferSyntaxNameList(berObjectIdentifierList);
ContextList.SEQUENCE context_listSubSeq = new ContextList.SEQUENCE(new PresentationContextIdentifier(1), new AbstractSyntaxName(new int[] { 2, 2, 1, 0, 1 }), tsnl);
ContextList.SEQUENCE context_listSubSeq2 = new ContextList.SEQUENCE(new PresentationContextIdentifier(3), new AbstractSyntaxName(new int[] { 1, 0, 9506, 2, 1 }), tsnl);
List<ContextList.SEQUENCE> context_listSubSeqList = new ArrayList<>(2);
context_listSubSeqList.add(context_listSubSeq);
context_listSubSeqList.add(context_listSubSeq2);
PresentationContextDefinitionList context_list = new PresentationContextDefinitionList(context_listSubSeqList);
PDVList.PresentationDataValues presDataValues = new PDVList.PresentationDataValues(new BerAny(new byte[] { 2, 1, 1 }), null, null);
PDVList pdvList = new PDVList(null, new PresentationContextIdentifier(1), presDataValues);
List<PDVList> pdvListList = new ArrayList<>(1);
pdvListList.add(pdvList);
FullyEncodedData fullyEncodedData = new FullyEncodedData(pdvListList);
UserData userData = new UserData(null, fullyEncodedData);
CPType.NormalModeParameters normalModeParameter = new CPType.NormalModeParameters(null, new CallingPresentationSelector(new byte[] { 0, 0, 0, 1 }), new CalledPresentationSelector(new byte[] { 0, 0, 0, 1 }), context_list, null, null, null, userData);
ModeSelector modeSelector = new ModeSelector(new BerInteger(1));
CPType cpType = new CPType(modeSelector, normalModeParameter);
cpType.encode(berOS, true);
ByteArrayInputStream bais = new ByteArrayInputStream(berOS.getArray());
CPType cpType_decoded = new CPType();
cpType_decoded.decode(bais, true);
assertEquals("2.2.1.0.1", cpType_decoded.normalModeParameters.presentationContextDefinitionList.seqOf.get(0).abstractSyntaxName.toString());
}
Aggregations