Search in sources :

Example 26 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream 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);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF210831060201010101FF"), os.getArray());
    set = new ExplicitlyTaggedSet();
    set.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertNotNull(set.getMyInteger());
    Assert.assertNotNull(set.getMyBoolean());
}
Also used : ExplicitlyTaggedSet(org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSet) BerBoolean(org.openmuc.jasn1.ber.types.BerBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 27 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class TaggingTest method implicitlyRetaggedTaggedChoiceTest.

@Test
public void implicitlyRetaggedTaggedChoiceTest() throws Exception {
    ImplicitlyRetaggedTaggedChoice choice = new ImplicitlyRetaggedTaggedChoice();
    choice.setMyInteger(new BerInteger(1));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    choice.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("A303020101"), os.getArray());
}
Also used : ImplicitlyRetaggedTaggedChoice(org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 28 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream 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));
    UntaggedChoice untaggedChoice = new 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);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF2B18020101A1030201028201038401FFA503830104A603020101"), os.getArray());
    sequence = new SequenceOfDirectTypes();
    sequence.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertEquals(1, sequence.getUntaggedInt().value.intValue());
    Assert.assertEquals(2, sequence.getExplicitlyTaggedInt().value.intValue());
    Assert.assertEquals(3, sequence.getImplicitlyTaggedInt().value.intValue());
    Assert.assertEquals(true, untaggedChoice.getMyBoolean().value);
    Assert.assertEquals(4, sequence.getTaggedChoice().getMyInteger().value.intValue());
    System.out.println(DatatypeConverter.printHexBinary(sequence.getTaggedAny().value));
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("020101"), sequence.getTaggedAny().value);
    Assert.assertNull(sequence.getUntaggedChoice2());
}
Also used : SequenceOfDirectTypes(org.openmuc.jasn1.compiler.tagging_test.SequenceOfDirectTypes) BerBoolean(org.openmuc.jasn1.ber.types.BerBoolean) UntaggedChoice(org.openmuc.jasn1.compiler.tagging_test.SequenceOfDirectTypes.UntaggedChoice) RetaggedUntaggedChoice(org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice) TaggedChoice(org.openmuc.jasn1.compiler.tagging_test.TaggedChoice) ImplicitlyRetaggedTaggedChoice(org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) BerAny(org.openmuc.jasn1.ber.types.BerAny) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 29 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class TaggingTest method retaggedChoiceTest.

@Test
public void retaggedChoiceTest() throws Exception {
    RetaggedUntaggedChoice choice = new RetaggedUntaggedChoice();
    choice.setMyInteger(new BerInteger(1));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    choice.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF2103830101"), os.getArray());
    choice = new RetaggedUntaggedChoice();
    choice.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertNotNull(choice.getMyInteger());
    Assert.assertNull(choice.getMyBoolean());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RetaggedUntaggedChoice(org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 30 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.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();
    name.code = new byte[] { (byte) 0x10, (byte) 0x1A, (byte) 0x04, (byte) 0x4a, (byte) 0x6f, (byte) 0x68, (byte) 0x6e, (byte) 0x1A, (byte) 0x01, (byte) 0x50, (byte) 0x1A, (byte) 0x05, (byte) 0x53, (byte) 0x6d, (byte) 0x69, (byte) 0x74, (byte) 0x68 };
    BerVisibleString title = new BerVisibleString("Director".getBytes("US-ASCII"));
    // EmployeeNumber number = new EmployeeNumber(51);
    EmployeeNumber number = new EmployeeNumber();
    number.code = new byte[] { 0x01, 0x33 };
    Date dateOfHire = new Date("19710917".getBytes());
    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()));
    System.out.println("192: " + HexConverter.toShortHexString("19571111".getBytes()));
    child1.encodeAndSave(80);
    System.out.println("geneCode: " + HexConverter.toShortHexString(child1.code));
    System.out.println("realCode: " + HexConverter.toShortHexString(new byte[] { (byte) 0x1f, (byte) 0x61, (byte) 0x11, (byte) 0x1A, (byte) 0x05, (byte) 0x52, (byte) 0x61, (byte) 0x6c, (byte) 0x70, (byte) 0x68, (byte) 0x1A, (byte) 0x01, (byte) 0x54, (byte) 0x1A, (byte) 0x05, (byte) 0x53, (byte) 0x6d, (byte) 0x69, (byte) 0x74, (byte) 0x68, (byte) 0xa0, (byte) 0x0a, (byte) 0x43, (byte) 0x08, (byte) 0x31, (byte) 0x39, (byte) 0x35, (byte) 0x37, (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x31 }));
    Assert.assertArrayEquals(new byte[] { (byte) 0x1f, (byte) 0x61, (byte) 0x11, (byte) 0x1A, (byte) 0x05, (byte) 0x52, (byte) 0x61, (byte) 0x6c, (byte) 0x70, (byte) 0x68, (byte) 0x1A, (byte) 0x01, (byte) 0x54, (byte) 0x1A, (byte) 0x05, (byte) 0x53, (byte) 0x6d, (byte) 0x69, (byte) 0x74, (byte) 0x68, (byte) 0xa0, (byte) 0x0a, (byte) 0x43, (byte) 0x08, (byte) 0x31, (byte) 0x39, (byte) 0x35, (byte) 0x37, (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x31 }, child1.code);
    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()));
    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 = new byte[] { (byte) 0x60, (byte) 0x81, (byte) 0x85, (byte) 0x61, (byte) 0x10, (byte) 0x1A, (byte) 0x04, (byte) 0x4a, (byte) 0x6f, (byte) 0x68, (byte) 0x6e, (byte) 0x1A, (byte) 0x01, (byte) 0x50, (byte) 0x1A, (byte) 0x05, (byte) 0x53, (byte) 0x6d, (byte) 0x69, (byte) 0x74, (byte) 0x68, (byte) 0xa0, (byte) 0x0a, (byte) 0x1A, (byte) 0x08, (byte) 0x44, (byte) 0x69, (byte) 0x72, (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x6f, (byte) 0x72, (byte) 0x42, (byte) 0x01, (byte) 0x33, (byte) 0xa1, (byte) 0x0a, (byte) 0x43, (byte) 0x08, (byte) 0x31, (byte) 0x39, (byte) 0x37, (byte) 0x31, (byte) 0x30, (byte) 0x39, (byte) 0x31, (byte) 0x37, (byte) 0xa2, (byte) 0x12, (byte) 0x61, (byte) 0x10, (byte) 0x1A, (byte) 0x04, (byte) 0x4d, (byte) 0x61, (byte) 0x72, (byte) 0x79, (byte) 0x1A, (byte) 0x01, (byte) 0x54, (byte) 0x1A, (byte) 0x05, (byte) 0x53, (byte) 0x6d, (byte) 0x69, (byte) 0x74, (byte) 0x68, (byte) 0xa3, (byte) 0x42, (byte) 0x31, (byte) 0x1f, (byte) 0x61, (byte) 0x11, (byte) 0x1A, (byte) 0x05, (byte) 0x52, (byte) 0x61, (byte) 0x6c, (byte) 0x70, (byte) 0x68, (byte) 0x1A, (byte) 0x01, (byte) 0x54, (byte) 0x1A, (byte) 0x05, (byte) 0x53, (byte) 0x6d, (byte) 0x69, (byte) 0x74, (byte) 0x68, (byte) 0xa0, (byte) 0x0a, (byte) 0x43, (byte) 0x08, (byte) 0x31, (byte) 0x39, (byte) 0x35, (byte) 0x37, (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x1f, (byte) 0x61, (byte) 0x11, (byte) 0x1A, (byte) 0x05, (byte) 0x53, (byte) 0x75, (byte) 0x73, (byte) 0x61, (byte) 0x6e, (byte) 0x1A, (byte) 0x01, (byte) 0x42, (byte) 0x1A, (byte) 0x05, (byte) 0x4a, (byte) 0x6f, (byte) 0x6e, (byte) 0x65, (byte) 0x73, (byte) 0xa0, (byte) 0x0a, (byte) 0x43, (byte) 0x08, (byte) 0x31, (byte) 0x39, (byte) 0x35, (byte) 0x39, (byte) 0x30, (byte) 0x37, (byte) 0x31, (byte) 0x37 };
    System.out.println("encoded structure:");
    System.out.println(getByteArrayString(berOS.getArray()));
    Assert.assertArrayEquals(expectedBytes, berOS.getArray());
    ByteBuffer byteBuffer = berOS.getByteBuffer();
    Assert.assertEquals((byte) 0x60, byteBuffer.get());
    Assert.assertEquals((byte) 0x37, byteBuffer.get(byteBuffer.limit() - 1));
    ByteArrayInputStream bais = new ByteArrayInputStream(berOS.getArray());
    PersonnelRecord personnelRecord_decoded = new PersonnelRecord();
    personnelRecord_decoded.decode(bais, true);
    Assert.assertEquals("John", new String(personnelRecord_decoded.getName().getGivenName().value));
// System.out
// .println("presentation_context_identifier= "
// +
// cpType_decoded.normal_mode_parameters.presentation_context_definition_list.seqOf.get(0).abstract_syntax_name);
}
Also used : ChildInformation(org.openmuc.jasn1.compiler.x690_ber_example.ChildInformation) EmployeeNumber(org.openmuc.jasn1.compiler.x690_ber_example.EmployeeNumber) PersonnelRecord(org.openmuc.jasn1.compiler.x690_ber_example.PersonnelRecord) BerVisibleString(org.openmuc.jasn1.ber.types.string.BerVisibleString) ByteBuffer(java.nio.ByteBuffer) Date(org.openmuc.jasn1.compiler.x690_ber_example.Date) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Name(org.openmuc.jasn1.compiler.x690_ber_example.Name) ByteArrayInputStream(java.io.ByteArrayInputStream) BerVisibleString(org.openmuc.jasn1.ber.types.string.BerVisibleString) Test(org.junit.Test)

Aggregations

ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)44 Test (org.junit.Test)38 ByteArrayInputStream (java.io.ByteArrayInputStream)25 BerInteger (org.openmuc.jasn1.ber.types.BerInteger)11 BerOctetString (org.openmuc.jasn1.ber.types.BerOctetString)4 BerUTF8String (org.openmuc.jasn1.ber.types.string.BerUTF8String)4 ProfileElement (org.openmuc.jasn1.compiler.pedefinitions.ProfileElement)4 BerBoolean (org.openmuc.jasn1.ber.types.BerBoolean)3 BerNull (org.openmuc.jasn1.ber.types.BerNull)3 BerVisibleString (org.openmuc.jasn1.ber.types.string.BerVisibleString)3 ImplicitlyRetaggedTaggedChoice (org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 BerAny (org.openmuc.jasn1.ber.types.BerAny)2 PEHeader (org.openmuc.jasn1.compiler.pedefinitions.PEHeader)2 UInt15 (org.openmuc.jasn1.compiler.pedefinitions.UInt15)2 RetaggedUntaggedChoice (org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice)2 ChildInformation (org.openmuc.jasn1.compiler.x690_ber_example.ChildInformation)2 Date (org.openmuc.jasn1.compiler.x690_ber_example.Date)2 EmployeeNumber (org.openmuc.jasn1.compiler.x690_ber_example.EmployeeNumber)2