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)); } }
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); }
/** * 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()); } }
/** * 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()); } }
/** * 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()); } }
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; }
if ((type.value != 0x02) && (type.value != 0x46)) { throw new IOException("Wrong type. Not an integer 64: "+type.value+ getPositionMessage(is)); if (length > 9) { throw new IOException("Invalid 64bit unsigned integer length: "+length+ getPositionMessage(is));
if ((t & ASN_EXTENSION_ID) == ASN_EXTENSION_ID) { throw new IOException("Cannot process extension IDs"+ getPositionMessage(is));
if ((t & ASN_EXTENSION_ID) == ASN_EXTENSION_ID) { throw new IOException("Cannot process extension IDs"+ getPositionMessage(is));
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; }
if ((type.value != 0x02) && (type.value != 0x46)) { throw new IOException("Wrong type. Not an integer 64: "+type.value+ getPositionMessage(is)); if (length > 9) { throw new IOException("Invalid 64bit unsigned integer length: "+length+ getPositionMessage(is));
if ((type.value != 0x02) && (type.value != 0x46)) { throw new IOException("Wrong type. Not an integer 64: "+type.value+ getPositionMessage(is)); if (length > 9) { throw new IOException("Invalid 64bit unsigned integer length: "+length+ getPositionMessage(is));
if ((t & ASN_EXTENSION_ID) == ASN_EXTENSION_ID) { throw new IOException("Cannot process extension IDs"+ getPositionMessage(is));
(type.value != 0x45)) { throw new IOException("Wrong ASN.1 type. Not a string: "+type.value+ getPositionMessage(is));