Search in sources :

Example 1 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream 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);
    Assert.assertEquals("2.2.1.0.1", cpType_decoded.normalModeParameters.presentationContextDefinitionList.seqOf.get(0).abstractSyntaxName.toString());
}
Also used : UserData(org.openmuc.jasn1.compiler.iso8823_presentation.UserData) ArrayList(java.util.ArrayList) ContextList(org.openmuc.jasn1.compiler.iso8823_presentation.ContextList) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) BerAny(org.openmuc.jasn1.ber.types.BerAny) FullyEncodedData(org.openmuc.jasn1.compiler.iso8823_presentation.FullyEncodedData) CPType(org.openmuc.jasn1.compiler.iso8823_presentation.CPType) ModeSelector(org.openmuc.jasn1.compiler.iso8823_presentation.ModeSelector) PresentationContextIdentifier(org.openmuc.jasn1.compiler.iso8823_presentation.PresentationContextIdentifier) CalledPresentationSelector(org.openmuc.jasn1.compiler.iso8823_presentation.CalledPresentationSelector) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) TransferSyntaxName(org.openmuc.jasn1.compiler.iso8823_presentation.TransferSyntaxName) AbstractSyntaxName(org.openmuc.jasn1.compiler.iso8823_presentation.AbstractSyntaxName) ByteArrayInputStream(java.io.ByteArrayInputStream) PresentationContextDefinitionList(org.openmuc.jasn1.compiler.iso8823_presentation.PresentationContextDefinitionList) CallingPresentationSelector(org.openmuc.jasn1.compiler.iso8823_presentation.CallingPresentationSelector) PDVList(org.openmuc.jasn1.compiler.iso8823_presentation.PDVList) Test(org.junit.Test)

Example 2 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream 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);
    System.out.println("setOf : " + DatatypeConverter.printHexBinary(os.getArray()));
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF21083106020103020104"), os.getArray());
    setOf = new ExplicitlyTaggedSetOf();
    setOf.decode(new ByteArrayInputStream(os.getArray()));
}
Also used : ExplicitlyTaggedSetOf(org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSetOf) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 3 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.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);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("9F210101"), os.getArray());
}
Also used : ImplicitlyTaggedInteger(org.openmuc.jasn1.compiler.tagging_test.ImplicitlyTaggedInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 4 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.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);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF2203020101"), os.getArray());
    choice = new TaggedChoice();
    choice.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertNotNull(choice.getMyInteger());
    Assert.assertNull(choice.getMyBoolean());
}
Also used : 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) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 5 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream 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);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF210830060201010101FF"), os.getArray());
    sequence = new ExplicitlyTaggedSequence();
    sequence.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertNotNull(sequence.getMyInteger());
    Assert.assertNotNull(sequence.getMyBoolean());
}
Also used : ExplicitlyTaggedSequence(org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSequence) 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)

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