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; } }
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; }
/** * Checks whether the length of that was encoded is also available from the * stream. * * @param is InputStream * @param length int * @throws IOException * if the bytes that are given in length cannot be read from the input * stream (without blocking). */ private static void checkLength(BERInputStream is, int length) throws IOException { if (!checkValueLength) { return; } if ((length < 0) || (length > is.getAvailableBytes())) { throw new IOException("The encoded length "+ length+ " exceeds the number of bytes left in input"+ getPositionMessage(is)+ " which actually is "+is.getAvailableBytes()); } }
wholeMsg.mark(16); return SnmpConstants.SNMP_MP_PARSE_ERROR; long lengthOfLength = wholeMsg.getPosition(); wholeMsg.reset(); wholeMsg.mark(length); if (wholeMsg.skip(lengthOfLength) != lengthOfLength) { return SnmpConstants.SNMP_MP_PARSE_ERROR; int secParametersPosition = (int)wholeMsg.getPosition(); wholeMsg.reset(); secStateReference, statusInformation); wholeMsg.close(); if (status == SnmpConstants.SNMPv3_USM_OK) { try { BERInputStream scopedPduStream = new BERInputStream(scopedPDU.rewind()); scopedPdu.decodeBER(scopedPduStream); sendPduHandle.setTransactionID(scopedPdu.getRequestID().getValue()); if (scopedPDU.getBuffer() != null) { BERInputStream scopedPduStream = new BERInputStream(scopedPDU.rewind()); scopedPdu.decodeBER(scopedPduStream);
private static String getPositionMessage(BERInputStream is) { return " at position "+is.getPosition(); }
ByteBuffer bis = ByteBuffer.wrap(message, scopedPDUPosition, scopedPDUHeaderLength); BERInputStream scopedPDUHeader = new BERInputStream(bis); long headerStartingPosition = scopedPDUHeader.getPosition(); int scopedPDULength = BER.decodeHeader(scopedPDUHeader, new MutableByte()); int scopedPDUPayloadPosition = scopedPDUPosition + (int)(scopedPDUHeader.getPosition() - headerStartingPosition); scopedPDUHeader.close(); scopedPDUHeader = null; byte[] scopedPduBytes =
if (!inputStream.markSupported()) { throw new IOException( "InputStream for decoding a Variable must support marks"); registerSyntaxes(); inputStream.mark(2); int type = inputStream.read(); Variable variable; if (SNMP4JSettings.isExtensibilityEnabled()) { variable = createVariable(type); inputStream.reset(); variable.decodeBER(inputStream); return variable;
public void processMessage(TransportMapping sourceTransport, Address incomingAddress, ByteBuffer wholeMessage) { processMessage(sourceTransport, incomingAddress, new BERInputStream(wholeMessage.duplicate())); }
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); }
TransportStateReference tmStateReference) { fireIncrementCounter(new CounterEvent(this, SnmpConstants.snmpInPkts)); if (!wholeMessage.markSupported()) { String txt = "Message stream must support marks"; logger.error(txt); wholeMessage.mark(16); BER.MutableByte type = new BER.MutableByte(); } else { wholeMessage.reset();
BigInteger value = BigInteger.ZERO; type.setValue((byte)inputStream.read()); (" at position "+inputStream.getPosition())); int b = inputStream.read() & 0xFF; if ((b & 0x80) > 0) { value = BigInteger.ONE.negate(); value = value.shiftLeft(8).or(BigInteger.valueOf(b)); if (length > 0) { b = inputStream.read();
wholeMsg.mark(16); return SnmpConstants.SNMP_MP_PARSE_ERROR; long lengthOfLength = wholeMsg.getPosition(); wholeMsg.reset(); wholeMsg.mark(length); if (wholeMsg.skip(lengthOfLength) != lengthOfLength) { return SnmpConstants.SNMP_MP_PARSE_ERROR; int secParametersPosition = (int)wholeMsg.getPosition(); wholeMsg.reset(); secStateReference, statusInformation); wholeMsg.close(); if (status == SnmpConstants.SNMPv3_USM_OK) { try { BERInputStream scopedPduStream = new BERInputStream(scopedPDU.rewind()); scopedPdu.decodeBER(scopedPduStream); sendPduHandle.setTransactionID(scopedPdu.getRequestID().getValue()); if (scopedPDU.getBuffer() != null) { BERInputStream scopedPduStream = new BERInputStream(scopedPDU.rewind()); scopedPdu.decodeBER(scopedPduStream);
public static String getPositionMessage(BERInputStream is) { return " at position "+is.getPosition(); }
ByteBuffer bis = ByteBuffer.wrap(message, scopedPDUPosition, scopedPDUHeaderLength); BERInputStream scopedPDUHeader = new BERInputStream(bis); long headerStartingPosition = scopedPDUHeader.getPosition(); int scopedPDULength = BER.decodeHeader(scopedPDUHeader, new MutableByte()); int scopedPDUPayloadPosition = scopedPDUPosition + (int) (scopedPDUHeader.getPosition() - headerStartingPosition); scopedPDUHeader.close();
if (!inputStream.markSupported()) { throw new IOException( "InputStream for decoding a Variable must support marks"); registerSyntaxes(); inputStream.mark(2); int type = inputStream.read(); Variable variable; if (SNMP4JSettings.isExtensibilityEnabled()) { variable = createVariable(type); inputStream.reset(); variable.decodeBER(inputStream); return variable;
public void processMessage(TransportMapping<?> sourceTransport, Address incomingAddress, ByteBuffer wholeMessage, TransportStateReference tmStateReference) { processMessage(sourceTransport, incomingAddress, new BERInputStream(wholeMessage), tmStateReference); }
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); }