public static void decodeNull(BERInputStream is, MutableByte type) throws IOException { // get the type type.setValue((byte)(is.read() & 0xFF)); if ((type.value != (byte)0x05) && (type.value != (byte)0x80) && (type.value != (byte)0x81) && (type.value != (byte)0x82)) { throw new IOException("Wrong ASN.1 type. Is not null: " + type.value+ getPositionMessage(is)); } int length = decodeLength(is); if (length != 0) { throw new IOException("Invalid Null encoding, length is not zero: "+ length+getPositionMessage(is)); } }
public void decodeBER(BERInputStream inputStream) throws java.io.IOException { BER.MutableByte type = new BER.MutableByte(); byte[] value = BER.decodeString(inputStream, type); if (type.getValue() != BER.IPADDRESS) { throw new IOException("Wrong type encountered when decoding Counter: "+ type.getValue()); } if (value.length != 4) { throw new IOException("IpAddress encoding error, wrong length: " + value.length); } inetAddress = InetAddress.getByAddress(value); }
/** * Get the BER encoded length of a BigInteger value. * @param value * a BigInteger value with a length that is less 2^31. * @return * the length of the BER encoding of the supplied BigInteger as INTEGER value. */ public static int getBigIntegerBERLength(BigInteger value) { int length = value.toByteArray().length; return length + getBERLengthOfLength(length) + 1; }
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 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 static void encodeVariableBindings(OutputStream outputStream, List<VariableBinding> variableBindings) throws IOException { int vbLength = 0; for (VariableBinding vb : variableBindings) { vbLength += vb.getBERLength(); } BER.encodeHeader(outputStream, BER.SEQUENCE, vbLength); for (VariableBinding vb : variableBindings) { vb.encodeBER(outputStream); } }
/** * Decodes a ASN.1 length. * @param is * an <code>InputStream</code> * @return * the decoded length. * @throws IOException */ public static final int decodeLength(BERInputStream is) throws IOException { return decodeLength(is, true); }
public void encodeBER(OutputStream outputStream) throws java.io.IOException { BER.encodeString(outputStream, BER.OCTETSTRING, getValue()); }
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 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 void decodeBER(BERInputStream inputStream) throws java.io.IOException { BER.MutableByte type = new BER.MutableByte(); int newValue = BER.decodeInteger(inputStream, type); if (type.getValue() != BER.INTEGER) { throw new IOException("Wrong type encountered when decoding Counter: "+type.getValue()); } setValue(newValue); }
public void decodeBER(BERInputStream inputStream) throws java.io.IOException { MutableByte type = new BER.MutableByte(); BER.decodeNull(inputStream, type); this.syntax = type.getValue() & 0xFF; }
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 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 final void encodeBER(OutputStream outputStream) throws IOException { int length = getBERPayloadLength(); BER.encodeHeader(outputStream, BER.SEQUENCE, length); oid.encodeBER(outputStream); variable.encodeBER(outputStream); }
/** * Decodes a ASN.1 length. * @param is * an {@code InputStream} * @return * the decoded length. * @throws IOException * if the input stream contains an invalid BER encoding or an IO * exception occurred while reading from the stream. */ public static int decodeLength(BERInputStream is) throws IOException { return decodeLength(is, true); }
public void encodeBER(OutputStream outputStream) throws IOException { BER.encodeString(outputStream, BER.OPAQUE, getValue()); }
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 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; } }