Search in sources :

Example 6 with BerInteger

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());
}
Also used : ExplicitlyTaggedSet(com.beanit.asn1bean.compiler.tagging_test.ExplicitlyTaggedSet) BerBoolean(com.beanit.asn1bean.ber.types.BerBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 7 with BerInteger

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);
}
Also used : ExplicitlyTaggedSequence(com.beanit.asn1bean.compiler.tagging_test.ExplicitlyTaggedSequence) BerBoolean(com.beanit.asn1bean.ber.types.BerBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 8 with BerInteger

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());
}
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 9 with BerInteger

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);
}
Also used : PersonnelRecord(com.beanit.asn1bean.compiler.modules.module1.PersonnelRecord) EmployeeNumberZ(com.beanit.asn1bean.compiler.modules.module2.EmployeeNumberZ) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Name(com.beanit.asn1bean.compiler.modules.module1.Name) BerEmbeddedPdv(com.beanit.asn1bean.ber.types.BerEmbeddedPdv) BerVisibleString(com.beanit.asn1bean.ber.types.string.BerVisibleString) MyBitString(com.beanit.asn1bean.compiler.modules.module1.MyBitString) ChildInformation(com.beanit.asn1bean.compiler.modules.module1.ChildInformation) TestSequenceOf(com.beanit.asn1bean.compiler.modules.module1.TestSequenceOf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestChoice(com.beanit.asn1bean.compiler.modules.module1.TestChoice) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) Date(com.beanit.asn1bean.compiler.modules.module1.Date) MyDate1(com.beanit.asn1bean.compiler.modules.module1.MyDate1) ByteArrayInputStream(java.io.ByteArrayInputStream) MyInt(com.beanit.asn1bean.compiler.modules.module1.MyInt) MyInt2(com.beanit.asn1bean.compiler.modules.module1.MyInt2) Test(org.junit.jupiter.api.Test)

Example 10 with BerInteger

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());
}
Also used : UserData(com.beanit.asn1bean.compiler.iso8823_presentation.UserData) ArrayList(java.util.ArrayList) ContextList(com.beanit.asn1bean.compiler.iso8823_presentation.ContextList) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) BerAny(com.beanit.asn1bean.ber.types.BerAny) FullyEncodedData(com.beanit.asn1bean.compiler.iso8823_presentation.FullyEncodedData) CPType(com.beanit.asn1bean.compiler.iso8823_presentation.CPType) ModeSelector(com.beanit.asn1bean.compiler.iso8823_presentation.ModeSelector) PresentationContextIdentifier(com.beanit.asn1bean.compiler.iso8823_presentation.PresentationContextIdentifier) CalledPresentationSelector(com.beanit.asn1bean.compiler.iso8823_presentation.CalledPresentationSelector) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) TransferSyntaxName(com.beanit.asn1bean.compiler.iso8823_presentation.TransferSyntaxName) AbstractSyntaxName(com.beanit.asn1bean.compiler.iso8823_presentation.AbstractSyntaxName) ByteArrayInputStream(java.io.ByteArrayInputStream) PresentationContextDefinitionList(com.beanit.asn1bean.compiler.iso8823_presentation.PresentationContextDefinitionList) CallingPresentationSelector(com.beanit.asn1bean.compiler.iso8823_presentation.CallingPresentationSelector) PDVList(com.beanit.asn1bean.compiler.iso8823_presentation.PDVList) 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