type.setValue((byte)is.read()); if ((type.value != 0x02) && (type.value != 0x46)) { throw new IOException("Wrong type. Not an integer 64: "+type.value+ int b = is.read() & 0xFF; if (length > 9) { throw new IOException("Invalid 64bit unsigned integer length: "+length+ b = is.read(); value = (value << 8) | (b & 0xFF); if (i+1<length) { b = is.read();
type.setValue((byte)is.read()); if ((type.value != 0x02) && (type.value != 0x46)) { throw new IOException("Wrong type. Not an integer 64: "+type.value+ int b = is.read() & 0xFF; if (length > 9) { throw new IOException("Invalid 64bit unsigned integer length: "+length+ b = is.read(); value = (value << 8) | (b & 0xFF); if (i+1<length) { b = is.read();
public static int decodeInteger(BERInputStream is, MutableByte type) throws IOException { int length; int value = 0; type.setValue((byte)is.read()); if ((type.value != 0x02) && (type.value != 0x43) && (type.value != 0x41)) { throw new IOException("Wrong ASN.1 type. Not an integer: "+type.value+ getPositionMessage(is)); } length = decodeLength(is); if (length > 4) { throw new IOException("Length greater than 32bit are not supported "+ " for integers: "+getPositionMessage(is)); } int b = is.read() & 0xFF; if ((b & 0x80) > 0) { value = -1; /* integer is negative */ } while (length-- > 0) { value = (value << 8) | b; if (length > 0) { b = is.read(); } } return value; }
public static final int decodeInteger(BERInputStream is, MutableByte type) throws IOException { int length; int value = 0; type.setValue((byte)is.read()); if ((type.value != 0x02) && (type.value != 0x43) && (type.value != 0x41)) { throw new IOException("Wrong ASN.1 type. Not an integer: "+type.value+ getPositionMessage(is)); } length = decodeLength(is); if (length > 4) { throw new IOException("Length greater than 32bit are not supported "+ " for integers: "+getPositionMessage(is)); } int b = is.read() & 0xFF; if ((b & 0x80) > 0) { value = -1; /* integer is negative */ } while (length-- > 0) { value = (value << 8) | b; if (length > 0) { b = is.read(); } } return value; }
public static int decodeInteger(BERInputStream is, MutableByte type) throws IOException { int length; int value = 0; type.setValue((byte)is.read()); if ((type.value != 0x02) && (type.value != 0x43) && (type.value != 0x41)) { throw new IOException("Wrong ASN.1 type. Not an integer: "+type.value+ getPositionMessage(is)); } length = decodeLength(is); if (length > 4) { throw new IOException("Length greater than 32bit are not supported "+ " for integers: "+getPositionMessage(is)); } int b = is.read() & 0xFF; if ((b & 0x80) > 0) { value = -1; /* integer is negative */ } while (length-- > 0) { value = (value << 8) | b; if (length > 0) { b = is.read(); } } return value; }
public static byte[] decodeString(BERInputStream is, MutableByte type) throws IOException { /* * ASN.1 octet string ::= primstring | cmpdstring * primstring ::= 0x04 asnlength byte {byte}* * cmpdstring ::= 0x24 asnlength string {string}* * ipaddress ::= 0x40 4 byte byte byte byte */ // get the type type.setValue((byte)is.read()); if ((type.value != BER.OCTETSTRING) && (type.value != 0x24) && (type.value != BER.IPADDRESS) && (type.value != BER.OPAQUE) && (type.value != BER.BITSTRING) && (type.value != 0x45)) { throw new IOException("Wrong ASN.1 type. Not a string: "+type.value+getPositionMessage(is)); } int length = decodeLength(is); byte[] value = new byte[length]; if (length > 0) { int read = is.read(value, 0, length); if ((read < 0) || (read < length)) { throw new IOException("Wrong string length " + read + " < " + length); } } return value; }
public static BigInteger decodeBigInteger(BERInputStream is, MutableByte type) throws IOException { int length; type.setValue((byte)is.read()); if (type.value != 0x02) { throw new IOException("Wrong ASN.1 type. Not an INTEGER: "+type.value+ getPositionMessage(is)); } length = decodeLength(is); if (length < 0) { throw new IOException("Length greater than "+Integer.MAX_VALUE+" are not supported "+ " for integers: "+getPositionMessage(is)); } byte[] bytes = new byte[length]; int actualRead = is.read(bytes); if (actualRead != length) { throw new IOException("Length of INTEGER ("+length+") is greater than number of bytes left in BER stream: "+ actualRead); } return new BigInteger(bytes); }
public static BigInteger decodeBigInteger(BERInputStream is, MutableByte type) throws IOException { int length; type.setValue((byte)is.read()); if (type.value != 0x02) { throw new IOException("Wrong ASN.1 type. Not an INTEGER: "+type.value+ getPositionMessage(is)); } length = decodeLength(is); if (length < 0) { throw new IOException("Length greater than "+Integer.MAX_VALUE+" are not supported "+ " for integers: "+getPositionMessage(is)); } byte[] bytes = new byte[length]; int actualRead = is.read(bytes); if (actualRead != length) { throw new IOException("Length of INTEGER ("+length+") is greater than number of bytes left in BER stream: "+ actualRead); } return new BigInteger(bytes); }
public static byte[] decodeString(BERInputStream is, MutableByte type) throws IOException { /* * ASN.1 octet string ::= primstring | cmpdstring * primstring ::= 0x04 asnlength byte {byte}* * cmpdstring ::= 0x24 asnlength string {string}* * ipaddress ::= 0x40 4 byte byte byte byte */ // get the type type.setValue((byte)is.read()); if ((type.value != BER.OCTETSTRING) && (type.value != 0x24) && (type.value != BER.IPADDRESS) && (type.value != BER.OPAQUE) && (type.value != BER.BITSTRING) && (type.value != 0x45)) { throw new IOException("Wrong ASN.1 type. Not a string: "+type.value+getPositionMessage(is)); } int length = decodeLength(is); byte[] value = new byte[length]; if (length > 0) { int read = is.read(value, 0, length); if ((read < 0) || (read < length)) { throw new IOException("Wrong string length " + read + " < " + length); } } return value; }
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 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 static final 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)); } }
byte t = (byte)is.read(); if ((t & ASN_EXTENSION_ID) == ASN_EXTENSION_ID) { throw new IOException("Cannot process extension IDs"+
byte t = (byte)is.read(); if ((t & ASN_EXTENSION_ID) == ASN_EXTENSION_ID) { throw new IOException("Cannot process extension IDs"+
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; }