Search in sources :

Example 11 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.ber.ReverseByteArrayOutputStream 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 12 with ReverseByteArrayOutputStream

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

the class TaggingTest method implicitlyTaggedIntegerTest.

@Test
public void implicitlyTaggedIntegerTest() throws Exception {
    ImplicitlyTaggedInteger implicitlyTaggedInteger = new ImplicitlyTaggedInteger(1);
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    implicitlyTaggedInteger.encode(os);
    assertArrayEquals(toBytes("9F210101"), os.getArray());
}
Also used : ImplicitlyTaggedInteger(com.beanit.asn1bean.compiler.tagging_test.ImplicitlyTaggedInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 13 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.ber.ReverseByteArrayOutputStream 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 14 with ReverseByteArrayOutputStream

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

the class X690BerExampleTest method encodingDecoding.

@Test
public void encodingDecoding() throws IOException {
    ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
    // Name name = new Name(new BerVisibleString("John"), new
    // BerVisibleString("P"), new BerVisibleString("Smith"));
    Name name = new Name(HexString.toBytes("101A044a6f686e1A01501A05536d697468"));
    BerVisibleString title = new BerVisibleString("Director".getBytes(UTF_8));
    // EmployeeNumber number = new EmployeeNumber(51);
    EmployeeNumber number = new EmployeeNumber(new byte[] { 0x01, 0x33 });
    Date dateOfHire = new Date("19710917".getBytes(UTF_8));
    Name nameOfSpouse = new Name();
    nameOfSpouse.setGivenName(new BerVisibleString("Mary"));
    nameOfSpouse.setInitial(new BerVisibleString("T"));
    nameOfSpouse.setFamilyName(new BerVisibleString("Smith"));
    Name child1Name = new Name();
    child1Name.setGivenName(new BerVisibleString("Ralph"));
    child1Name.setInitial(new BerVisibleString("T"));
    child1Name.setFamilyName(new BerVisibleString("Smith"));
    ChildInformation child1 = new ChildInformation();
    child1.setName(child1Name);
    child1.setDateOfBirth(new Date("19571111".getBytes(UTF_8)));
    child1.encodeAndSave(80);
    Name child2Name = new Name();
    child2Name.setGivenName(new BerVisibleString("Susan"));
    child2Name.setInitial(new BerVisibleString("B"));
    child2Name.setFamilyName(new BerVisibleString("Jones"));
    ChildInformation child2 = new ChildInformation();
    child2.setName(child2Name);
    child2.setDateOfBirth(new Date("19590717".getBytes(UTF_8)));
    PersonnelRecord.Children childrenSeq = new PersonnelRecord.Children();
    List<ChildInformation> childList = childrenSeq.getChildInformation();
    childList.add(child1);
    childList.add(child2);
    PersonnelRecord personnelRecord = new PersonnelRecord();
    personnelRecord.setName(name);
    personnelRecord.setTitle(title);
    personnelRecord.setNumber(number);
    personnelRecord.setDateOfHire(dateOfHire);
    personnelRecord.setNameOfSpouse(nameOfSpouse);
    personnelRecord.setChildren(childrenSeq);
    personnelRecord.encode(berOS, true);
    byte[] expectedBytes = HexString.toBytes("60818561101A044a6f686e1A01501A05536d697468a00a1A084469726563746f72420133a10a43083139373130393137a21261101A044d6172791A01541A05536d697468a342311f61111A0552616c70681A01541A05536d697468a00a43083139353731313131311f61111A05537573616e1A01421A054a6f6e6573a00a43083139353930373137");
    assertArrayEquals(expectedBytes, berOS.getArray());
    ByteBuffer byteBuffer = berOS.getByteBuffer();
    assertEquals((byte) 0x60, byteBuffer.get());
    assertEquals((byte) 0x37, byteBuffer.get(byteBuffer.limit() - 1));
    ByteArrayInputStream bais = new ByteArrayInputStream(berOS.getArray());
    PersonnelRecord personnelRecord_decoded = new PersonnelRecord();
    personnelRecord_decoded.decode(bais, true);
    assertEquals("John", new String(personnelRecord_decoded.getName().getGivenName().value, UTF_8));
}
Also used : ChildInformation(com.beanit.asn1bean.compiler.x690_ber_example.ChildInformation) EmployeeNumber(com.beanit.asn1bean.compiler.x690_ber_example.EmployeeNumber) PersonnelRecord(com.beanit.asn1bean.compiler.x690_ber_example.PersonnelRecord) HexString(com.beanit.asn1bean.util.HexString) BerVisibleString(com.beanit.asn1bean.ber.types.string.BerVisibleString) ByteBuffer(java.nio.ByteBuffer) Date(com.beanit.asn1bean.compiler.x690_ber_example.Date) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Name(com.beanit.asn1bean.compiler.x690_ber_example.Name) ByteArrayInputStream(java.io.ByteArrayInputStream) BerVisibleString(com.beanit.asn1bean.ber.types.string.BerVisibleString) Test(org.junit.jupiter.api.Test)

Example 15 with ReverseByteArrayOutputStream

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

the class BerInteger method encodeAndSave.

public void encodeAndSave(int encodingSizeGuess) throws IOException {
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess);
    encode(os, false);
    code = os.getArray();
}
Also used : ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)

Aggregations

ReverseByteArrayOutputStream (com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)51 Test (org.junit.jupiter.api.Test)41 ByteArrayInputStream (java.io.ByteArrayInputStream)25 BerInteger (com.beanit.asn1bean.ber.types.BerInteger)14 BerVisibleString (com.beanit.asn1bean.ber.types.string.BerVisibleString)5 HexString (com.beanit.asn1bean.util.HexString)5 BerOctetString (com.beanit.asn1bean.ber.types.BerOctetString)4 BerUTF8String (com.beanit.asn1bean.ber.types.string.BerUTF8String)4 ProfileElement (com.beanit.asn1bean.compiler.pedefinitions.ProfileElement)4 BerAny (com.beanit.asn1bean.ber.types.BerAny)3 BerBoolean (com.beanit.asn1bean.ber.types.BerBoolean)3 BerNull (com.beanit.asn1bean.ber.types.BerNull)3 ImplicitlyRetaggedTaggedChoice (com.beanit.asn1bean.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 NonExtensibleSequence (com.beanit.asn1bean.compiler.extension_test.non_extensible.NonExtensibleSequence)2 PEHeader (com.beanit.asn1bean.compiler.pedefinitions.PEHeader)2 UInt15 (com.beanit.asn1bean.compiler.pedefinitions.UInt15)2 ArrayList (java.util.ArrayList)2 BerEmbeddedPdv (com.beanit.asn1bean.ber.types.BerEmbeddedPdv)1 BerObjectIdentifier (com.beanit.asn1bean.ber.types.BerObjectIdentifier)1 ExtensibleAccessSequence (com.beanit.asn1bean.compiler.extension_test.extensible_with_access.ExtensibleAccessSequence)1