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 BerAnyNoDecode(); 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."); }
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 BerAnyNoDecode(payload.limit() - payload.position())); 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); BerByteArrayOutputStream berOStream = new BerByteArrayOutputStream(200, true); user_data.encode(berOStream); ssduList.add(berOStream.buffer); ssduOffsets.add(berOStream.index + 1); ssduLengths.add(berOStream.buffer.length - (berOStream.index + 1)); ssduList.add(payload.array()); ssduOffsets.add(payload.arrayOffset() + payload.position()); ssduLengths.add(payload.limit() - payload.position()); }
sublength = singleASN1Type.encode(os); codeLength += sublength; codeLength += BerLength.encodeLength(os, sublength);
private static UserData getPresentationUserDataField(int userDataLength) { PDVList.PresentationDataValues presDataValues = new PDVList.PresentationDataValues(); presDataValues.setSingleASN1Type(new BerAnyNoDecode(userDataLength)); 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; }
sublength = singleASN1Type.encode(os); codeLength += sublength; codeLength += BerLength.encodeLength(os, sublength);
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 BerAnyNoDecode(); 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."); }
BerAnyNoDecode anyPayload = new BerAnyNoDecode(payloadLength);
encoding.setSingleASN1Type(new BerAnyNoDecode(payloadLength));