/** * Decodes an ASN.1 header for an object with the ID and * length specified. * On entry, datalength is input as the number of valid bytes following * "data". On exit, it is returned as the number of valid bytes * in this object following the id and length. * * This only works on data types < 30, i.e. no extension octets. * The maximum length is 0xFFFF; * * @param is * the BERInputStream to decode. * @param type * returns the type of the object at the current position in the input * stream. * @return * the decoded length of the object. * @throws IOException */ public static final int decodeHeader(BERInputStream is, MutableByte type) throws IOException { return decodeHeader(is, type, true); }
public MessageLength getMessageLength(ByteBuffer buf) throws IOException { MutableByte type = new MutableByte(); BERInputStream is = new BERInputStream(buf); int ml = BER.decodeHeader(is, type, false); int hl = (int)is.getPosition(); MessageLength messageLength = new MessageLength(hl, ml); return messageLength; } }
public MessageLength getMessageLength(ByteBuffer buf) throws IOException { MutableByte type = new MutableByte(); BERInputStream is = new BERInputStream(buf); int ml = BER.decodeHeader(is, type); int hl = (int)is.getPosition(); MessageLength messageLength = new MessageLength(hl, ml); return messageLength; } }
public MessageLength getMessageLength(ByteBuffer buf) throws IOException { MutableByte type = new MutableByte(); BERInputStream is = new BERInputStream(buf); int ml = BER.decodeHeader(is, type, false); int hl = (int) is.getPosition(); MessageLength messageLength = new MessageLength(hl, ml); return messageLength; } }
public static ArrayList<VariableBinding> decodeVariableBindings(BERInputStream inputStream) throws IOException { BER.MutableByte pduType; pduType = new BER.MutableByte(); int vbLength = BER.decodeHeader(inputStream, pduType); if (pduType.getValue() != BER.SEQUENCE) { throw new IOException("Encountered invalid tag, SEQUENCE expected: " + pduType.getValue()); } // rest read count int startPos = (int) inputStream.getPosition(); ArrayList<VariableBinding> variableBindings = new ArrayList<>(); while (inputStream.getPosition() - startPos < vbLength) { VariableBinding vb = new VariableBinding(); vb.decodeBER(inputStream); variableBindings.add(vb); } if (inputStream.getPosition() - startPos != vbLength) { throw new IOException("Length of VB sequence (" + vbLength + ") does not match real length: " + ((int) inputStream.getPosition() - startPos)); } return variableBindings; }
public final void decodeBER(BERInputStream inputStream) throws IOException { BER.MutableByte type = new BER.MutableByte(); int length = BER.decodeHeader(inputStream, type); long startPos = inputStream.getPosition(); if (type.getValue() != BER.SEQUENCE) { throw new IOException("Invalid sequence encoding: " + type.getValue()); } oid.decodeBER(inputStream); variable = AbstractVariable.createFromBER(inputStream); if (BER.isCheckSequenceLength()) { BER.checkSequenceLength(length, (int) (inputStream.getPosition() - startPos), this); } }
public final void decodeBER(BERInputStream inputStream) throws IOException { BER.MutableByte type = new BER.MutableByte(); int length = BER.decodeHeader(inputStream, type); long startPos = inputStream.getPosition(); if (type.getValue() != BER.SEQUENCE) { throw new IOException("Invalid sequence encoding: " + type.getValue()); } oid.decodeBER(inputStream); variable = AbstractVariable.createFromBER(inputStream); if (BER.isCheckSequenceLength()) { BER.checkSequenceLength(length, (int) (inputStream.getPosition() - startPos), this); } }
public final void decodeBER(BERInputStream inputStream) throws IOException { BER.MutableByte type = new BER.MutableByte(); int length = BER.decodeHeader(inputStream, type); long startPos = inputStream.getPosition(); if (type.getValue() != BER.SEQUENCE) { throw new IOException("Invalid sequence encoding: " + type.getValue()); } oid.decodeBER(inputStream); variable = AbstractVariable.createFromBER(inputStream); if (BER.isCheckSequenceLength()) { BER.checkSequenceLength(length, (int) (inputStream.getPosition() - startPos), this); } }
public static DHParameters getDHParametersFromBER(OctetString berValue) throws IOException { BERInputStream inputStream = new BERInputStream(ByteBuffer.wrap(berValue.getValue())); BER.MutableByte sequenceType = new BER.MutableByte(); int sequenceLength = BER.decodeHeader(inputStream, sequenceType); long headerOffset = inputStream.getPosition(); BER.MutableByte integerType = new BER.MutableByte(); BigInteger prime = BER.decodeBigInteger(inputStream, integerType); BigInteger generator = BER.decodeBigInteger(inputStream, integerType); int privateValueLength = 0; if (inputStream.available() > 0 && inputStream.getPosition() < sequenceLength + headerOffset) { privateValueLength = BER.decodeInteger(inputStream, integerType); } return new DHParameters(prime, generator, privateValueLength); }
public static DHParameters getDHParametersFromBER(OctetString berValue) throws IOException { BERInputStream inputStream = new BERInputStream(ByteBuffer.wrap(berValue.getValue())); BER.MutableByte sequenceType = new BER.MutableByte(); int sequenceLength = BER.decodeHeader(inputStream, sequenceType); long headerOffset = inputStream.getPosition(); BER.MutableByte integerType = new BER.MutableByte(); BigInteger prime = BER.decodeBigInteger(inputStream, integerType); BigInteger generator = BER.decodeBigInteger(inputStream, integerType); int privateValueLength = 0; if (inputStream.available() > 0 && inputStream.getPosition() < sequenceLength + headerOffset) { privateValueLength = BER.decodeInteger(inputStream, integerType); } return new DHParameters(prime, generator, privateValueLength); }
public void decodeBER(BERInputStream message) throws IOException { BER.MutableByte type = new BER.MutableByte(); int length = BER.decodeHeader(message, type); if (type.getValue() != BER.SEQUENCE) { throw new IOException("Unexpected sequence header type: " + type.getValue()); } msgID.decodeBER(message); msgMaxSize.decodeBER(message); if (msgMaxSize.getValue() < 484) { throw new IOException("Invalid msgMaxSize: " + msgMaxSize); } msgFlags.decodeBER(message); if (msgFlags.length() != 1) { throw new IOException("Message flags length != 1: " + msgFlags.length()); } securityModel.decodeBER(message); if (logger.isDebugEnabled()) { logger.debug("SNMPv3 header decoded: msgId=" + msgID + ", msgMaxSize=" + msgMaxSize + ", msgFlags=" + msgFlags.toHexString() + ", secModel=" + securityModel); } BER.checkSequenceLength(length, this); }
public void decodeBER(BERInputStream message) throws IOException { BER.MutableByte type = new BER.MutableByte(); int length = BER.decodeHeader(message, type); if (type.getValue() != BER.SEQUENCE) { throw new IOException("Unexpected sequence header type: " + type.getValue()); } msgID.decodeBER(message); msgMaxSize.decodeBER(message); if (msgMaxSize.getValue() < 484) { throw new IOException("Invalid msgMaxSize: " + msgMaxSize); } msgFlags.decodeBER(message); if (msgFlags.length() != 1) { throw new IOException("Message flags length != 1: " + msgFlags.length()); } securityModel.decodeBER(message); if (logger.isDebugEnabled()) { logger.debug("SNMPv3 header decoded: msgId=" + msgID + ", msgMaxSize=" + msgMaxSize + ", msgFlags=" + msgFlags.toHexString() + ", secModel=" + securityModel); } BER.checkSequenceLength(length, this); }
public void decodeBER(BERInputStream message) throws IOException { BER.MutableByte type = new BER.MutableByte(); int length = BER.decodeHeader(message, type); if (type.getValue() != BER.SEQUENCE) { throw new IOException("Unexpected sequence header type: " + type.getValue()); } msgID.decodeBER(message); msgMaxSize.decodeBER(message); if (msgMaxSize.getValue() < 484) { throw new IOException("Invalid msgMaxSize: " + msgMaxSize); } msgFlags.decodeBER(message); if (msgFlags.length() != 1) { throw new IOException("Message flags length != 1: " + msgFlags.length()); } securityModel.decodeBER(message); if (logger.isDebugEnabled()) { logger.debug("SNMPv3 header decoded: msgId=" + msgID + ", msgMaxSize=" + msgMaxSize + ", msgFlags=" + msgFlags.toHexString() + ", secModel=" + securityModel); } BER.checkSequenceLength(length, this); }
protected static byte[] buildMessageBuffer(BERInputStream scopedPDU) throws IOException { scopedPDU.mark(16); int readLengthBytes = (int)scopedPDU.getPosition(); BER.MutableByte mutableByte = new BER.MutableByte(); int length = BER.decodeHeader(scopedPDU, mutableByte); readLengthBytes = (int)scopedPDU.getPosition() - readLengthBytes; byte[] buf = new byte[length + readLengthBytes]; scopedPDU.reset(); int offset = 0; int avail = scopedPDU.available(); while ((offset < buf.length) && (avail > 0)) { int read = scopedPDU.read(buf, offset, buf.length - offset); if (read < 0) { break; } offset += read; } return buf; }
protected static byte[] buildMessageBuffer(BERInputStream scopedPDU) throws IOException { scopedPDU.mark(16); int readLengthBytes = (int)scopedPDU.getPosition(); BER.MutableByte mutableByte = new BER.MutableByte(); int length = BER.decodeHeader(scopedPDU, mutableByte); readLengthBytes = (int)scopedPDU.getPosition() - readLengthBytes; byte[] buf = new byte[length + readLengthBytes]; scopedPDU.reset(); int offset = 0; int avail = scopedPDU.available(); while ((offset < buf.length) && (avail > 0)) { int read = scopedPDU.read(buf, offset, buf.length - offset); if (read < 0) { break; } offset += read; } return buf; }
private static byte[] buildMessageBuffer(BERInputStream scopedPDU) throws IOException { // return scopedPDU.getBuffer().array(); scopedPDU.mark(16); int readLengthBytes = (int)scopedPDU.getPosition(); MutableByte mutableByte = new MutableByte(); int length = BER.decodeHeader(scopedPDU, mutableByte); readLengthBytes = (int)scopedPDU.getPosition() - readLengthBytes; byte[] buf = new byte[length + readLengthBytes]; scopedPDU.reset(); int offset = 0; int avail = scopedPDU.available(); while ((offset < buf.length) && (avail > 0)) { int read = scopedPDU.read(buf, offset, buf.length - offset); if (read < 0) { break; } offset += read; } return buf; }
/** * Decodes a <code>ScopedPDU</code> from an <code>InputStream</code>. * * @param inputStream an <code>InputStream</code> containing a BER encoded * byte stream. * @throws IOException */ public void decodeBER(BERInputStream inputStream) throws IOException { MutableByte mutableByte = new MutableByte(); int length = BER.decodeHeader(inputStream, mutableByte); long startPos = inputStream.getPosition(); contextEngineID.decodeBER(inputStream); contextName.decodeBER(inputStream); super.decodeBER(inputStream); if (BER.isCheckSequenceLength()) { BER.checkSequenceLength(length, (int) (inputStream.getPosition() - startPos), this); } }
/** * Decodes a <code>ScopedPDU</code> from an <code>InputStream</code>. * * @param inputStream an <code>InputStream</code> containing a BER encoded * byte stream. * @throws IOException * if there is a BER encoding error or other IO exception in the input stream. */ public void decodeBER(BERInputStream inputStream) throws IOException { MutableByte mutableByte = new MutableByte(); int length = BER.decodeHeader(inputStream, mutableByte); long startPos = inputStream.getPosition(); contextEngineID.decodeBER(inputStream); contextName.decodeBER(inputStream); super.decodeBER(inputStream); if (BER.isCheckSequenceLength()) { BER.checkSequenceLength(length, (int) (inputStream.getPosition() - startPos), this); } }
/** * Decodes a <code>ScopedPDU</code> from an <code>InputStream</code>. * * @param inputStream an <code>InputStream</code> containing a BER encoded * byte stream. * @throws IOException * if there is a BER encoding error or other IO exception in the input stream. */ public void decodeBER(BERInputStream inputStream) throws IOException { MutableByte mutableByte = new MutableByte(); int length = BER.decodeHeader(inputStream, mutableByte); long startPos = inputStream.getPosition(); contextEngineID.decodeBER(inputStream); contextName.decodeBER(inputStream); super.decodeBER(inputStream); if (BER.isCheckSequenceLength()) { BER.checkSequenceLength(length, (int) (inputStream.getPosition() - startPos), this); } }
int length = BER.decodeHeader(wholeMsg, mutableByte); int startPos = (int)wholeMsg.getPosition();