public Object decode(BerInputStream in) throws IOException { // only read content, doesn't check it in.readContent(); if (in.isVerify) { return null; } return getDecodedObject(in); }
/** * 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"); } } }
public Object decode(BerInputStream in) throws IOException { // FIXME what about constr??? String str = null; if (DirectoryString.ASN1.checkTag(in.tag)) { // has string representation str = (String) DirectoryString.ASN1.decode(in); } else { // gets octets only in.readContent(); } byte[] bytesEncoded = new byte[in.getOffset() - in.getTagOffset()]; System.arraycopy(in.getBuffer(), in.getTagOffset(), bytesEncoded, 0, bytesEncoded.length); return new AttributeValue(str, bytesEncoded, in.tag); }
/** * 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"); } }
if (tag == ASN1Constants.TAG_GENERALIZEDTIME) { readContent();
public Object decode(BerInputStream in) throws IOException { // only read content, doesn't check it in.readContent(); if (in.isVerify) { return null; } return getDecodedObject(in); }
public Object decode(BerInputStream in) throws IOException { // only read content, doesn't check it in.readContent(); if (in.isVerify) { return null; } return getDecodedObject(in); }
public Object decode(BerInputStream in) throws IOException { // only read content, doesn't check it in.readContent(); if (in.isVerify) { return null; } return getDecodedObject(in); }
/** * 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"); } }
/** * 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 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"); } }