/** * Decodes ASN.1 SequenceOf type */ public void readSequenceOf(ASN1SequenceOf sequenceOf) throws IOException { if (tag != ASN1Constants.TAG_C_SEQUENCEOF) { throw expected("sequenceOf"); } decodeValueCollection(sequenceOf); }
/** * Decodes ASN.1 SetOf type */ public void readSetOf(ASN1SetOf setOf) throws IOException { if (tag != ASN1Constants.TAG_C_SETOF) { throw expected("setOf"); } decodeValueCollection(setOf); }
/** * Decodes ASN.1 Set type */ public void readSet(ASN1Set set) throws IOException { if (tag != ASN1Constants.TAG_C_SET) { throw expected("set"); } throw new ASN1Exception("Decoding ASN.1 Set type is not supported"); }
/** * Decodes ASN.1 Octetstring type */ public void readOctetString() throws IOException { if (tag == ASN1Constants.TAG_OCTETSTRING) { readContent(); } else if (tag == ASN1Constants.TAG_C_OCTETSTRING) { throw new ASN1Exception("Decoding constructed ASN.1 octet string type is not supported"); } else { throw expected("octetstring"); } }
/** * Decodes ASN.1 boolean type */ public void readBoolean() throws IOException { if (tag != ASN1Constants.TAG_BOOLEAN) { throw expected("boolean"); } // check encoded length if (length != 1) { throw new ASN1Exception("Wrong length for ASN.1 boolean at [" + tagOffset + "]"); } readContent(); }
/** * Decodes ASN.1 String type * * @throws IOException if an I/O error occurs or the end of the stream is reached */ public void readString(ASN1StringType type) throws IOException { if (tag == type.id) { readContent(); } else if (tag == type.constrId) { throw new ASN1Exception("Decoding constructed ASN.1 string type is not provided"); } else { throw expected("string"); } }
/** * Decodes ASN.1 Integer type */ public void readInteger() throws IOException { if (tag != ASN1Constants.TAG_INTEGER) { throw expected("integer"); } // check encoded length if (length < 1) { throw new ASN1Exception("Wrong length for ASN.1 integer at [" + tagOffset + "]"); } readContent(); // check encoded content if (length > 1) { byte firstByte = buffer[offset - length]; byte secondByte = (byte) (buffer[offset - length + 1] & 0x80); if (firstByte == 0 && secondByte == 0 || firstByte == (byte) 0xFF && secondByte == (byte) 0x80) { throw new ASN1Exception("Wrong content for ASN.1 integer at [" + (offset - length) + "]. An integer MUST be encoded in minimum number of octets"); } } }
/** * Decodes ASN.1 ObjectIdentifier type */ public void readOID() throws IOException { if (tag != ASN1Constants.TAG_OID) { throw expected("OID"); } // check encoded length if (length < 1) { throw new ASN1Exception("Wrong length for ASN.1 object identifier at [" + tagOffset + "]"); } readContent(); // check content: last encoded byte (8th bit MUST be zero) if ((buffer[offset - 1] & 0x80) != 0) { throw new ASN1Exception("Wrong encoding at [" + (offset - 1) + "]"); } oidElement = 1; for (int i = 0; i < length; i++, ++oidElement) { while ((buffer[contentOffset + i] & 0x80) == 0x80) { i++; } } }
/** * Decodes ASN.1 Enumerated type */ public void readEnumerated() throws IOException { if (tag != ASN1Constants.TAG_ENUM) { throw expected("enumerated"); } // check encoded length if (length == 0) { throw new ASN1Exception("ASN.1 enumerated: wrong length for identifier at [" + tagOffset + "]"); } readContent(); // check encoded content if (length > 1) { int bits = buffer[contentOffset] & 0xFF; if (buffer[contentOffset + 1] < 0) { bits += 0x100; } if (bits == 0 || bits == 0x1FF) { throw new ASN1Exception("ASN.1 enumerated: wrong content at [" + contentOffset + "]. An integer MUST be encoded in minimum number of octets"); } } }
/** * Decodes ASN.1 bitstring type */ public void readBitString() throws IOException { if (tag == ASN1Constants.TAG_BITSTRING) { if (length == 0) { throw new ASN1Exception("ASN.1 Bitstring: wrong length. Tag at [" + tagOffset + "]"); } readContent(); // content: check unused bits if (buffer[contentOffset] > 7) { throw new ASN1Exception("ASN.1 Bitstring: wrong content at [" + contentOffset + "]. A number of unused bits MUST be in range 0 to 7"); } if (length == 1 && buffer[contentOffset] != 0) { throw new ASN1Exception("ASN.1 Bitstring: wrong content at [" + contentOffset + "]. For empty string unused bits MUST be 0"); } } else if (tag == ASN1Constants.TAG_C_BITSTRING) { throw new ASN1Exception("Decoding constructed ASN.1 bitstring type is not provided"); } else { throw expected("bitstring"); } }
throw new ASN1Exception("Decoding constructed ASN.1 UTCTime type is not supported"); } else { throw expected("UTCTime");
throw expected("sequence");
throw new ASN1Exception("Decoding constructed ASN.1 GeneralizedTime type is not supported"); } else { throw expected("GeneralizedTime");
/** * Decodes ASN.1 SequenceOf type */ public void readSequenceOf(ASN1SequenceOf sequenceOf) throws IOException { if (tag != ASN1Constants.TAG_C_SEQUENCEOF) { throw expected("sequenceOf"); } decodeValueCollection(sequenceOf); }
/** * Decodes ASN.1 Set type */ public void readSet(ASN1Set set) throws IOException { if (tag != ASN1Constants.TAG_C_SET) { throw expected("set"); } throw new ASN1Exception("Decoding ASN.1 Set type is not supported"); }
/** * Decodes ASN.1 SetOf type */ public void readSetOf(ASN1SetOf setOf) throws IOException { if (tag != ASN1Constants.TAG_C_SETOF) { throw expected("setOf"); } decodeValueCollection(setOf); }
/** * Decodes ASN.1 SetOf type */ public void readSetOf(ASN1SetOf setOf) throws IOException { if (tag != ASN1Constants.TAG_C_SETOF) { throw expected("setOf"); } decodeValueCollection(setOf); }
/** * Decodes ASN.1 Set type */ public void readSet(ASN1Set set) throws IOException { if (tag != ASN1Constants.TAG_C_SET) { throw expected("set"); } throw new ASN1Exception("Decoding ASN.1 Set type is not supported"); }
/** * Decodes ASN.1 Octetstring type */ public void readOctetString() throws IOException { if (tag == ASN1Constants.TAG_OCTETSTRING) { readContent(); } else if (tag == ASN1Constants.TAG_C_OCTETSTRING) { throw new ASN1Exception("Decoding constructed ASN.1 octet string type is not supported"); } else { throw expected("octetstring"); } }
/** * Decodes ASN.1 Octetstring type */ public void readOctetString() throws IOException { if (tag == ASN1Constants.TAG_OCTETSTRING) { readContent(); } else if (tag == ASN1Constants.TAG_C_OCTETSTRING) { throw new ASN1Exception("Decoding constructed ASN.1 octet string type is not supported"); } else { throw expected("octetstring"); } }