Search in sources :

Example 26 with ReverseByteArrayOutputStream

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

the class MobileTest method genericFileManagement.

@Test
public void genericFileManagement() throws Exception {
    ProfileElement genericFileManagementProfileElement = new ProfileElement();
    List<FileManagement.CHOICE> choices = new ArrayList<>();
    choices.add(createDf((short) 0x3f00, "7821", (byte) 0x0e, "01020A"));
    choices.addAll(createEf((short) 0x2f05, "4121", (byte) 0x0F, (short) 3, (short) 0x28));
    choices.addAll(createEf((short) 0x2fe2, "4121", (byte) 0x0B, (short) 0x0A, null, "98109909002143658739", null));
    choices.addAll(createEf((short) 0x2f00, "42210026", (byte) 0x0A, (short) 0x98, (short) 0xF0, "61184F10A0000000871002FF33FF01890000010050045553494D", null));
    choices.addAll(createEf((short) 0x2f06, "42210025", (byte) 0x0A, (short) 0x01EF, null, Arrays.asList(new FileRecordContent(null, "8001019000800102A406830101950108800158A40683010A950108"), new FileRecordContent(10, "800101A40683010195010880015AA40683010A950108"), new FileRecordContent(15, "80015BA40683010A950108"), new FileRecordContent(26, "800101900080015A9700"), new FileRecordContent(27, "800103A406830101950108800158A40683010A950108"), new FileRecordContent(15, "800111A40683010195010880014AA40683010A950108"), new FileRecordContent(15, "800103A406830101950108800158A40683010A950108840132A406830101950108"), new FileRecordContent(4, "800101A406830101950108800102A406830181950108800158A40683010A950108"), new FileRecordContent(4, "800101900080011AA406830101950108800140A40683010A950108"), new FileRecordContent(10, "800101900080015AA40683010A950108"), new FileRecordContent(21, "8001019000800118A40683010A9501088001429700"), new FileRecordContent(14, "800101A40683010195010880015A9700"), new FileRecordContent(21, "800113A406830101950108800148A40683010A950108"), new FileRecordContent(13, "80015EA40683010A950108"), new FileRecordContent(26, "8001019000800102A010A406830101950108A406830102950108800158A40683010A950108"))));
    choices.addAll(createEf((short) 0x2f08, "4121", (byte) 0x0A, (short) 5));
    genericFileManagementProfileElement.genericFileManagement = new PEGenericFileManagement(new PEHeader(new BerNull(), new UInt15(1)), new PEGenericFileManagement.FileManagementCMD(Collections.singletonList(new FileManagement(choices))));
    ReverseByteArrayOutputStream reverseOutputStream = new ReverseByteArrayOutputStream(2048, true);
    genericFileManagementProfileElement.encode(reverseOutputStream);
    byte[] code = reverseOutputStream.getArray();
    ProfileElement rereadProfileElement = new ProfileElement();
    rereadProfileElement.decode(new ByteArrayInputStream(code), null);
    ReverseByteArrayOutputStream reverseOutputStream2 = new ReverseByteArrayOutputStream(2048, true);
    rereadProfileElement.encode(reverseOutputStream2);
    byte[] code2 = reverseOutputStream2.getArray();
    assertArrayEquals(code, code2);
    String expected = "A1 820237 A0 05 80 00 81 01 01 A1 82022C 30 820228 62 10 82 02 7821 83 02 3F00 8B 01 0E C6 03 01020A 62 11 82 02 4121 83 02 2F05 8B 01 0F 80 01 03 88 01 28 62 0E 82 02 4121 83 02 2FE2 8B 01 0B 80 01 0A 81 0A 98109909002143658739 62 14 82 04 4221002683 02 2F00 8B 01 0A 80 02 0098 88 01 F0 81 1A 61184F10A0000000871002FF33FF01890000010050045553494D 62 11 82 04 42210025 83 02 2F06 8B 01 0A 80 02 01EF 81 1B 8001019000800102A406830101950108800158A40683010A950108 02 01 0A 81 16 800101A40683010195010880015AA40683010A950108 02 01 0F 81 0B 80015BA40683010A950108 02 01 1A 81 0A 800101900080015A9700 02 01 1B 81 16 800103A406830101950108800158A40683010A950108 02 01 0F 81 16 800111A40683010195010880014AA40683010A950108 02 01 0F 81 21 800103A406830101950108800158A40683010A950108840132A406830101950108 02 01 04 81 21 800101A406830101950108800102A406830181950108800158A40683010A950108 02 01 04 81 1B 800101900080011AA406830101950108800140A40683010A950108 02 01 0A 81 10 800101900080015AA40683010A950108 02 01 15 81 15 8001019000800118A40683010A9501088001429700 02 01 0E 81 10 800101A40683010195010880015A9700 02 01 15 81 16 800113A406830101950108800148A40683010A950108 02 01 0D 81 0B 80015EA40683010A950108 02 01 1A81 25 8001019000800102A010A406830101950108A406830102950108800158A40683010A950108 62 0E 82 02 4121 83 02 2F08 8B 01 0A 80 01 05".replaceAll("\\s", "");
    assertEquals(expected, HexString.fromBytes(code));
}
Also used : PEHeader(com.beanit.asn1bean.compiler.pedefinitions.PEHeader) ArrayList(java.util.ArrayList) FileManagement(com.beanit.asn1bean.compiler.pedefinitions.FileManagement) PEGenericFileManagement(com.beanit.asn1bean.compiler.pedefinitions.PEGenericFileManagement) BerUTF8String(com.beanit.asn1bean.ber.types.string.BerUTF8String) BerOctetString(com.beanit.asn1bean.ber.types.BerOctetString) HexString(com.beanit.asn1bean.util.HexString) ProfileElement(com.beanit.asn1bean.compiler.pedefinitions.ProfileElement) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BerNull(com.beanit.asn1bean.ber.types.BerNull) UInt15(com.beanit.asn1bean.compiler.pedefinitions.UInt15) PEGenericFileManagement(com.beanit.asn1bean.compiler.pedefinitions.PEGenericFileManagement) Test(org.junit.jupiter.api.Test)

Example 27 with ReverseByteArrayOutputStream

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

the class MobileTest method header.

@Test
public void header() throws Exception {
    ProfileElement headerProfileElement = new ProfileElement();
    ServicesList servicesList = new ServicesList();
    ProfileHeader.EUICCMandatoryGFSTEList GFSTEList = new ProfileHeader.EUICCMandatoryGFSTEList();
    GFSTEList.seqOf = Arrays.asList(new BerObjectIdentifier(new int[] { 2, 23, 143, 1, 2, 1 }), new BerObjectIdentifier(new int[] { 2, 23, 143, 1, 2, 4 }));
    servicesList.usim = new BerNull();
    servicesList.milenage = new BerNull();
    servicesList.javacard = new BerNull();
    headerProfileElement.header = new ProfileHeader(new UInt8(2), new UInt8(0), new BerUTF8String("SIMalliance Sample Profile"), new BerOctetString(HexString.toBytes("89019990001234567893")), null, servicesList, GFSTEList, null, null);
    ReverseByteArrayOutputStream reverseByteArrayOutputStream = new ReverseByteArrayOutputStream(2048, true);
    headerProfileElement.encode(reverseByteArrayOutputStream);
    byte[] code = reverseByteArrayOutputStream.getArray();
    ProfileElement rereadProfileElement = new ProfileElement();
    rereadProfileElement.decode(new ByteArrayInputStream(code), null);
    ReverseByteArrayOutputStream reverseOutputStream2 = new ReverseByteArrayOutputStream(2048, true);
    rereadProfileElement.encode(reverseOutputStream2);
    byte[] code2 = reverseOutputStream2.getArray();
    assertArrayEquals(code, code2);
    String expected = "A0 48 80 01 02 81 01 00 82 1A 53494D616C6C69616E63652053616D706C652050726F66696C65 83 0A 89019990001234567893 A5 06 81 00 84 00 8B 00 A6 10 06 06 67810F010201 06 06 67810F010204".replaceAll("\\s", "");
    assertEquals(expected, HexString.fromBytes(code));
}
Also used : BerObjectIdentifier(com.beanit.asn1bean.ber.types.BerObjectIdentifier) BerUTF8String(com.beanit.asn1bean.ber.types.string.BerUTF8String) BerOctetString(com.beanit.asn1bean.ber.types.BerOctetString) BerUTF8String(com.beanit.asn1bean.ber.types.string.BerUTF8String) BerOctetString(com.beanit.asn1bean.ber.types.BerOctetString) HexString(com.beanit.asn1bean.util.HexString) ProfileElement(com.beanit.asn1bean.compiler.pedefinitions.ProfileElement) UInt8(com.beanit.asn1bean.compiler.pedefinitions.UInt8) ProfileHeader(com.beanit.asn1bean.compiler.pedefinitions.ProfileHeader) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) ServicesList(com.beanit.asn1bean.compiler.pedefinitions.ServicesList) ByteArrayInputStream(java.io.ByteArrayInputStream) BerNull(com.beanit.asn1bean.ber.types.BerNull) Test(org.junit.jupiter.api.Test)

Example 28 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.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);
    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 29 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.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));
    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 30 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.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);
    assertArrayEquals(toBytes("BF21083106020103020104"), os.getArray());
    setOf = new ExplicitlyTaggedSetOf();
    setOf.decode(new ByteArrayInputStream(os.getArray()));
}
Also used : ExplicitlyTaggedSetOf(com.beanit.asn1bean.compiler.tagging_test.ExplicitlyTaggedSetOf) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

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