private void encodePresentationLayer(ByteBuffer payload, List<byte[]> ssduList, List<Integer> ssduOffsets, List<Integer> ssduLengths) throws IOException { PDVList pdv_list = new PDVList(); pdv_list.setPresentationContextIdentifier(new PresentationContextIdentifier(3l)); PDVList.PresentationDataValues presentationDataValues = new PDVList.PresentationDataValues(); presentationDataValues.setSingleASN1Type( new BerAny(Arrays.copyOfRange(payload.array(), payload.position(), payload.limit()))); pdv_list.setPresentationDataValues(presentationDataValues); FullyEncodedData fully_encoded_data = new FullyEncodedData(); List<PDVList> pdv_list_list = fully_encoded_data.getPDVList(); pdv_list_list.add(pdv_list); UserData user_data = new UserData(); user_data.setFullyEncodedData(fully_encoded_data); ReverseByteArrayOutputStream reverseOStream = new ReverseByteArrayOutputStream(200, true); user_data.encode(reverseOStream); ssduList.add(reverseOStream.buffer); ssduOffsets.add(reverseOStream.index + 1); ssduLengths.add(reverseOStream.buffer.length - (reverseOStream.index + 1)); }
private void encodePresentationLayer(ByteBuffer payload, List<byte[]> ssduList, List<Integer> ssduOffsets, List<Integer> ssduLengths) throws IOException { PDVList pdv_list = new PDVList(); pdv_list.setPresentationContextIdentifier(new PresentationContextIdentifier(3l)); PDVList.PresentationDataValues presentationDataValues = new PDVList.PresentationDataValues(); presentationDataValues.setSingleASN1Type( new BerAny(Arrays.copyOfRange(payload.array(), payload.position(), payload.limit()))); pdv_list.setPresentationDataValues(presentationDataValues); FullyEncodedData fully_encoded_data = new FullyEncodedData(); List<PDVList> pdv_list_list = fully_encoded_data.getPDVList(); pdv_list_list.add(pdv_list); UserData user_data = new UserData(); user_data.setFullyEncodedData(fully_encoded_data); ReverseByteArrayOutputStream reverseOStream = new ReverseByteArrayOutputStream(200, true); user_data.encode(reverseOStream); ssduList.add(reverseOStream.buffer); ssduOffsets.add(reverseOStream.index + 1); ssduLengths.add(reverseOStream.buffer.length - (reverseOStream.index + 1)); }
private static UserData getPresentationUserDataField(byte[] userDataBytes) { PDVList.PresentationDataValues presDataValues = new PDVList.PresentationDataValues(); presDataValues.setSingleASN1Type(new BerAny(userDataBytes)); PDVList pdvList = new PDVList(); pdvList.setPresentationContextIdentifier(acsePresentationContextId); pdvList.setPresentationDataValues(presDataValues); FullyEncodedData fullyEncodedData = new FullyEncodedData(); List<PDVList> pdvListList = fullyEncodedData.getPDVList(); pdvListList.add(pdvList); UserData userData = new UserData(); userData.setFullyEncodedData(fullyEncodedData); return userData; }
private static UserData getPresentationUserDataField(byte[] userDataBytes) { PDVList.PresentationDataValues presDataValues = new PDVList.PresentationDataValues(); presDataValues.setSingleASN1Type(new BerAny(userDataBytes)); PDVList pdvList = new PDVList(); pdvList.setPresentationContextIdentifier(acsePresentationContextId); pdvList.setPresentationDataValues(presDataValues); FullyEncodedData fullyEncodedData = new FullyEncodedData(); List<PDVList> pdvListList = fullyEncodedData.getPDVList(); pdvListList.add(pdvList); UserData userData = new UserData(); userData.setFullyEncodedData(fullyEncodedData); return userData; }
BerAny anyPayload = new BerAny(Arrays.copyOfRange(payload.array(), payload.position(), payload.limit()));
BerAny anyPayload = new BerAny(Arrays.copyOfRange(payload.array(), payload.position(), payload.limit()));
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { BerLength length = new BerLength(); codeLength += length.decode(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, length.val); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding BerChoice: Tag matched to no item."); }
new BerAny(new byte[] { 2, 1, 1 }), null, null); PDVList pdvList = new PDVList(null, new PresentationContextIdentifier(1), presDataValues); List<PDVList> pdvListList = new ArrayList<>(1);
public int decode(InputStream is, BerTag berTag) throws IOException { int codeLength = 0; BerTag passedTag = berTag; if (berTag == null) { berTag = new BerTag(); codeLength += berTag.decode(is); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { codeLength += BerLength.skip(is); singleASN1Type = new BerAny(); codeLength += singleASN1Type.decode(is, null); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { octetAligned = new BerOctetString(); codeLength += octetAligned.decode(is, false); return codeLength; } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { arbitrary = new BerBitString(); codeLength += arbitrary.decode(is, false); return codeLength; } if (passedTag != null) { return 0; } throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item."); }
@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()); }
taggedAny = new BerAny(); subCodeLength += taggedAny.decode(is, null); if (subCodeLength == totalLength) {
taggedAny = new BerAny(); codeLength += taggedAny.decode(is, null); return codeLength;