Search in sources :

Example 1 with BerAny

use of com.beanit.asn1bean.ber.types.BerAny 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)

Example 2 with BerAny

use of com.beanit.asn1bean.ber.types.BerAny 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));
    SequenceOfDirectTypes.UntaggedChoice untaggedChoice = new SequenceOfDirectTypes.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);
    assertArrayEquals(toBytes("BF2B18020101A1030201028201038401FFA503830104A603020101"), os.getArray());
    sequence = new SequenceOfDirectTypes();
    sequence.decode(new ByteArrayInputStream(os.getArray()));
    assertEquals(1, sequence.getUntaggedInt().value.intValue());
    assertEquals(2, sequence.getExplicitlyTaggedInt().value.intValue());
    assertEquals(3, sequence.getImplicitlyTaggedInt().value.intValue());
    assertTrue(untaggedChoice.getMyBoolean().value);
    assertEquals(4, sequence.getTaggedChoice().getMyInteger().value.intValue());
    assertArrayEquals(toBytes("020101"), sequence.getTaggedAny().value);
    assertNull(sequence.getUntaggedChoice2());
}
Also used : SequenceOfDirectTypes(com.beanit.asn1bean.compiler.tagging_test.SequenceOfDirectTypes) BerBoolean(com.beanit.asn1bean.ber.types.BerBoolean) RetaggedUntaggedChoice(com.beanit.asn1bean.compiler.tagging_test.RetaggedUntaggedChoice) 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) BerAny(com.beanit.asn1bean.ber.types.BerAny) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 3 with BerAny

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

the class AnyTypeTest method encodingAny.

@Test
public void encodingAny() throws Exception {
    SimpleSeq simpleSeq = new SimpleSeq(new BerInteger(2));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    simpleSeq.encode(os);
    System.out.println(HexString.fromBytes(os.getArray()));
    assertArrayEquals(toBytes("3003800102"), os.getArray());
    SeqContainingAnyDefinedBy seqContainingAnyDefinedBy = new SeqContainingAnyDefinedBy(new BerAny(os.getArray()));
    os.reset();
    seqContainingAnyDefinedBy.encode(os);
    System.out.println(HexString.fromBytes(os.getArray()));
    assertArrayEquals(toBytes("3007A0053003800102"), os.getArray());
}
Also used : BerInteger(com.beanit.asn1bean.ber.types.BerInteger) SeqContainingAnyDefinedBy(com.beanit.asn1bean.compiler.various_tests.SeqContainingAnyDefinedBy) BerAny(com.beanit.asn1bean.ber.types.BerAny) SimpleSeq(com.beanit.asn1bean.compiler.various_tests.SimpleSeq) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ReverseByteArrayOutputStream (com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)3 BerAny (com.beanit.asn1bean.ber.types.BerAny)3 BerInteger (com.beanit.asn1bean.ber.types.BerInteger)3 Test (org.junit.jupiter.api.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BerBoolean (com.beanit.asn1bean.ber.types.BerBoolean)1 AbstractSyntaxName (com.beanit.asn1bean.compiler.iso8823_presentation.AbstractSyntaxName)1 CPType (com.beanit.asn1bean.compiler.iso8823_presentation.CPType)1 CalledPresentationSelector (com.beanit.asn1bean.compiler.iso8823_presentation.CalledPresentationSelector)1 CallingPresentationSelector (com.beanit.asn1bean.compiler.iso8823_presentation.CallingPresentationSelector)1 ContextList (com.beanit.asn1bean.compiler.iso8823_presentation.ContextList)1 FullyEncodedData (com.beanit.asn1bean.compiler.iso8823_presentation.FullyEncodedData)1 ModeSelector (com.beanit.asn1bean.compiler.iso8823_presentation.ModeSelector)1 PDVList (com.beanit.asn1bean.compiler.iso8823_presentation.PDVList)1 PresentationContextDefinitionList (com.beanit.asn1bean.compiler.iso8823_presentation.PresentationContextDefinitionList)1 PresentationContextIdentifier (com.beanit.asn1bean.compiler.iso8823_presentation.PresentationContextIdentifier)1 TransferSyntaxName (com.beanit.asn1bean.compiler.iso8823_presentation.TransferSyntaxName)1 UserData (com.beanit.asn1bean.compiler.iso8823_presentation.UserData)1 ImplicitlyRetaggedTaggedChoice (com.beanit.asn1bean.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)1 RetaggedUntaggedChoice (com.beanit.asn1bean.compiler.tagging_test.RetaggedUntaggedChoice)1