All DER-encoded data are triples {type, length, data}. This class represents such tagged values as they have been read (or constructed), and provides structured access to the encoded data.
At this time, this class supports only a subset of the types of DER data encodings which are defined. That subset is sufficient for parsing most X.509 certificates, and working with selected additional formats (such as PKCS #10 certificate requests, and some kinds of PKCS #7 data). A note with respect to T61/Teletex strings: From RFC 1617, section 4.1.3 and RFC 5280, section 8, we assume that this kind of string will contain ISO-8859-1 characters only.
Modifier and Type | Field and Description |
---|---|
private final boolean | |
pack-priv final byte[] | |
public final DerInputStream | |
pack-priv final int | |
private final int | |
public byte | |
public static final byte | |
public static final byte | tag_BitString
Tag value indicating an ASN.1 "BIT STRING" value. |
public static final byte | tag_BMPString
Tag value indicating an ASN.1 "BMPString" value. |
public static final byte | tag_Boolean
Tag value indicating an ASN.1 "BOOLEAN" value. |
public static final byte | |
public static final byte | tag_Enumerated
Tag value including an ASN.1 "ENUMERATED" value |
public static final byte | tag_GeneralizedTime
Tag value indicating an ASN.1 "GeneralizedTime" value. |
public static final byte | tag_GeneralString
Tag value indicating an ASN.1 "GeneralString" value. |
public static final byte | tag_IA5String
Tag value including an ASCII string |
public static final byte | tag_Integer
Tag value indicating an ASN.1 "INTEGER" value. |
public static final byte | tag_Null
Tag value indicating an ASN.1 "NULL" value. |
public static final byte | tag_ObjectId
Tag value indicating an ASN.1 "OBJECT IDENTIFIER" value. |
public static final byte | tag_OctetString
Tag value indicating an ASN.1 "OCTET STRING" value. |
public static final byte | tag_PrintableString
Tag value including a "printable" string |
public static final byte | |
public static final byte | tag_Sequence
Tag value indicating an ASN.1 "SEQUENCE" (zero to N elements, order is significant). |
public static final byte | tag_SequenceOf
Tag value indicating an ASN.1 "SEQUENCE OF" (one to N elements, order is significant). |
public static final byte | tag_Set
Tag value indicating an ASN.1 "SET" (zero to N members, order does not matter). |
public static final byte | tag_SetOf
Tag value indicating an ASN.1 "SET OF" (one to N members, order does not matter). |
public static final byte | tag_T61String
Tag value including a "teletype" string |
public static final byte | TAG_UNIVERSAL
The tag class types |
public static final byte | tag_UniversalString
Tag value indicating an ASN.1 "UniversalString" value. |
public static final byte | tag_UtcTime
Tag value indicating an ASN.1 "UTCTime" value. |
public static final byte | tag_UTF8String
Tag value indicating an ASN.1 "UTF8String" value. |
Access | Constructor and Description |
---|---|
pack-priv | DerValue(byte tag, byte[] buffer, int start, int end, boolean allowBER)
Creates a new DerValue by specifying all its fields. |
public | |
public | |
pack-priv | |
public | DerValue(byte
the DER type tag tag, byte[] the DER-encoded data buffer)Creates a DerValue from a tag and some DER-encoded data. |
public | |
pack-priv | DerValue(byte[]
the byte array containing the DER-encoded datum buf, int where the encoded datum starts inside offset, int buf length of bytes to parse inside len, boolean buf whether BER is allowed allowBER, boolean whether extra bytes are allowed after the encoded datum.
If true, allowMore)len can be bigger than the length of
the encoded datum.Parse an ASN.1 encoded datum from a byte array. |
pack-priv | |
public | DerValue(InputStream
the input stream holding a single DER datum,
which may be followed by additional data in)Get an ASN1/DER encoded datum from an input stream. |
Modifier and Type | Method and Description |
---|---|
private static int | |
public void | |
public static byte | createTag(byte
the tag class type, one of UNIVERSAL, CONTEXT,
APPLICATION or PRIVATE tagClass, boolean if true, the value is constructed, otherwise it
is primitive. form, byte the tag value val)Create the tag of the attribute. |
public final DerInputStream | Returns: the new DerInputStream valueReturns a new DerInputStream pointing at the start of this DerValue's content. |
public void | |
public boolean | equals(Object
the object being compared with this one o)Overrides java. Bitwise equality comparison. |
public String | getAsString()
Returns the name component as a Java string, regardless of its encoding restrictions (ASCII, T61, Printable, IA5, BMP, UTF8). |
public BigInteger | Returns: the integer held in this DER value as a BigInteger.Returns an ASN.1 INTEGER value as a BigInteger. |
private BigInteger | Returns: the integer as a BigInteger.whether to always return a positive value,
irrespective of actual encoding makePositive)Returns a BigInteger value |
public byte[] | |
public byte[] | Returns: the bit string held in this valueif true, the tag is assumed implicit. tagImplicit)Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter. |
public String | Returns: a string corresponding to the encoded BMPString held in this valueReturns the ASN.1 BMP (Unicode) STRING value as a Java string. |
public boolean | |
public final DerInputStream | |
public byte[] | getDataBytes()
Helper routine to return all the bytes contained in the DerInputStream associated with this object. |
public int | |
public Date | Returns: the Date held in this DER valueReturns a Date if the DerValue is GeneralizedTime. |
public String | Returns: a string corresponding to the encoded GeneralString held in this valueReturns the ASN.1 GENERAL STRING value as a Java String. |
public String | |
public int | Returns: the integer held in this DER value.Returns an ASN.1 INTEGER value as an integer. |
private int | |
public void | |
public byte[] | |
public ObjectIdentifier | |
public BigInteger | Returns: the integer held in this DER value as a BigInteger.Returns an ASN.1 INTEGER value as a positive BigInteger. |
public String | |
public String | Returns: the teletype string held in this valueReturns an ASN.1 T61 (Teletype) STRING value |
public final byte | |
public Date | getTime()
Determines whether Date was encoded as UTC or Generalized time and calls getUTCTime or getGeneralizedTime accordingly |
private Date | getTimeInternal(boolean
true if Generalized Time is to be read, false
if UTC Time is to be read. generalized)Private helper routine to extract time from the der value. |
public BitArray | Returns: a BitArray representing the bit string held in this valueReturns an ASN.1 BIT STRING value that need not be byte-aligned. |
public BitArray | Returns: the bit string held in this valueif true, the tag is assumed implicit. tagImplicit)Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter. |
public String | Returns: a string corresponding to the encoded UniversalString held in this valueReturns the ASN.1 UNIVERSAL (UTF-32) STRING value as a Java String. |
public Date | |
public String | Returns: a string corresponding to the encoded UTF8String held in this valueReturns the ASN.1 UTF-8 STRING value as a Java String. |
public int | Returns: a hashcode for this DerValueOverrides java. Returns a hashcode for this DerValue. |
public boolean | |
public boolean | |
public boolean | |
public boolean | |
public boolean | |
private static boolean | |
public static boolean | isPrintableStringChar(char ch)
Determine if a character is one of the permissible characters for PrintableString: A-Z, a-z, 0-9, space, apostrophe (39), left and right parentheses, plus sign, comma, hyphen, period, slash, colon, equals sign, and question mark. |
pack-priv boolean | |
public boolean | |
public int | |
private String | |
public void | |
private static byte[] | |
public DerValue[] | Returns: the sub-values in an arraythe expected tag, or zero if we don't check.
This is useful when this DerValue is IMPLICIT. expectedTag, int estimated number of sub-values startLen)Reads the sub-values in a constructed DerValue. |
public byte[] | Returns: DER-encoded value, including tag and length.Returns a DER-encoded value, such that if it's passed to the DerValue constructor, a value equivalent to "this" is returned. |
public DerInputStream | toDerInputStream()
For "set" and "sequence" types, this function may be used to return a DER stream of the members of the set or sequence. |
private static int | |
public String | Returns: printable representation of the valueOverrides java. Returns a printable representation of the value. |
public DerValue | |
public static DerValue | Returns: a new DerValue using out as its contentthe tag tag, DerOutputStream the DerOutputStream out)Wraps a DerOutputStream. |
public static DerValue | Returns: a new DerValuethe byte array containing the DER-encoded datum buf)Wraps a byte array as a single DerValue. |
public static DerValue | Returns: a new DerValuethe byte array containing the DER-encoded datum buf, int where the encoded datum starts inside offset, int buf length of bytes to parse inside len)buf Wraps a byte array as a single DerValue. |
allowBER | back to summary |
---|---|
private final boolean allowBER |
buffer | back to summary |
---|---|
pack-priv final byte[] buffer |
data | back to summary |
---|---|
public final DerInputStream data |
end | back to summary |
---|---|
pack-priv final int end |
start | back to summary |
---|---|
private final int start |
tag | back to summary |
---|---|
public byte tag |
TAG_APPLICATION | back to summary |
---|---|
public static final byte TAG_APPLICATION |
tag_BitString | back to summary |
---|---|
public static final byte tag_BitString Tag value indicating an ASN.1 "BIT STRING" value. |
tag_BMPString | back to summary |
---|---|
public static final byte tag_BMPString Tag value indicating an ASN.1 "BMPString" value. |
tag_Boolean | back to summary |
---|---|
public static final byte tag_Boolean Tag value indicating an ASN.1 "BOOLEAN" value. |
TAG_CONTEXT | back to summary |
---|---|
public static final byte TAG_CONTEXT |
tag_Enumerated | back to summary |
---|---|
public static final byte tag_Enumerated Tag value including an ASN.1 "ENUMERATED" value |
tag_GeneralizedTime | back to summary |
---|---|
public static final byte tag_GeneralizedTime Tag value indicating an ASN.1 "GeneralizedTime" value. |
tag_GeneralString | back to summary |
---|---|
public static final byte tag_GeneralString Tag value indicating an ASN.1 "GeneralString" value. |
tag_IA5String | back to summary |
---|---|
public static final byte tag_IA5String Tag value including an ASCII string |
tag_Integer | back to summary |
---|---|
public static final byte tag_Integer Tag value indicating an ASN.1 "INTEGER" value. |
tag_Null | back to summary |
---|---|
public static final byte tag_Null Tag value indicating an ASN.1 "NULL" value. |
tag_ObjectId | back to summary |
---|---|
public static final byte tag_ObjectId Tag value indicating an ASN.1 "OBJECT IDENTIFIER" value. |
tag_OctetString | back to summary |
---|---|
public static final byte tag_OctetString Tag value indicating an ASN.1 "OCTET STRING" value. |
tag_PrintableString | back to summary |
---|---|
public static final byte tag_PrintableString Tag value including a "printable" string |
TAG_PRIVATE | back to summary |
---|---|
public static final byte TAG_PRIVATE |
tag_Sequence | back to summary |
---|---|
public static final byte tag_Sequence Tag value indicating an ASN.1 "SEQUENCE" (zero to N elements, order is significant). |
tag_SequenceOf | back to summary |
---|---|
public static final byte tag_SequenceOf Tag value indicating an ASN.1 "SEQUENCE OF" (one to N elements, order is significant). |
tag_Set | back to summary |
---|---|
public static final byte tag_Set Tag value indicating an ASN.1 "SET" (zero to N members, order does not matter). |
tag_SetOf | back to summary |
---|---|
public static final byte tag_SetOf Tag value indicating an ASN.1 "SET OF" (one to N members, order does not matter). |
tag_T61String | back to summary |
---|---|
public static final byte tag_T61String Tag value including a "teletype" string |
TAG_UNIVERSAL | back to summary |
---|---|
public static final byte TAG_UNIVERSAL The tag class types |
tag_UniversalString | back to summary |
---|---|
public static final byte tag_UniversalString Tag value indicating an ASN.1 "UniversalString" value. |
tag_UtcTime | back to summary |
---|---|
public static final byte tag_UtcTime Tag value indicating an ASN.1 "UTCTime" value. |
tag_UTF8String | back to summary |
---|---|
public static final byte tag_UTF8String Tag value indicating an ASN.1 "UTF8String" value. |
DerValue | back to summary |
---|---|
pack-priv DerValue(byte tag, byte[] buffer, int start, int end, boolean allowBER) Creates a new DerValue by specifying all its fields. |
DerValue | back to summary |
---|---|
public DerValue(String value) Creates a PrintableString or UTF8string DER value from a string. |
DerValue | back to summary |
---|---|
public DerValue(byte stringTag, String value) Creates a string type DER value from a String object
|
DerValue | back to summary |
---|---|
pack-priv DerValue(byte tag, byte[] buffer, boolean allowBER) |
DerValue | back to summary |
---|---|
public DerValue(byte tag, byte[] buffer) Creates a DerValue from a tag and some DER-encoded data. This is a public constructor.
|
DerValue | back to summary |
---|---|
public DerValue(byte[] encoding) throws IOException Parse an ASN.1/BER encoded datum. The entire encoding must hold exactly one datum, including its tag and length. This is a public constructor. |
DerValue | back to summary |
---|---|
pack-priv DerValue(byte[] buf, int offset, int len, boolean allowBER, boolean allowMore) throws IOException Parse an ASN.1 encoded datum from a byte array.
|
DerValue | back to summary |
---|---|
pack-priv DerValue(InputStream in, boolean allowBER) throws IOException |
DerValue | back to summary |
---|---|
public DerValue(InputStream in) throws IOException Get an ASN1/DER encoded datum from an input stream. The stream may have additional data following the encoded datum. In case of indefinite length encoded datum, the input stream must hold only one datum, i.e. all bytes in the stream might be consumed. Otherwise, only one DerValue will be consumed.
|
checkPaddedBits | back to summary |
---|---|
private static int checkPaddedBits(int numOfPadBits, byte[] data, int start, int end, boolean allowBER) throws IOException |
clear | back to summary |
---|---|
public void clear() |
createTag | back to summary |
---|---|
public static byte createTag(byte tagClass, boolean form, byte val) Create the tag of the attribute.
|
data | back to summary |
---|---|
public final DerInputStream data() Returns a new DerInputStream pointing at the start of this DerValue's content.
|
encode | back to summary |
---|---|
public void encode(DerOutputStream out) Encode an ASN1/DER encoded datum onto a DER output stream. |
equals | back to summary |
---|---|
public boolean equals(Object o) Overrides java. Bitwise equality comparison. DER encoded values have a single encoding, so that bitwise equality of the encoded values is an efficient way to establish equivalence of the unencoded values.
|
getAsString | back to summary |
---|---|
public String getAsString() throws IOException Returns the name component as a Java string, regardless of its encoding restrictions (ASCII, T61, Printable, IA5, BMP, UTF8). |
getBigInteger | back to summary |
---|---|
public BigInteger getBigInteger() throws IOException Returns an ASN.1 INTEGER value as a BigInteger.
|
getBigIntegerInternal | back to summary |
---|---|
private BigInteger getBigIntegerInternal(byte expectedTag, boolean makePositive) throws IOException Returns a BigInteger value
|
getBitString | back to summary |
---|---|
public byte[] getBitString() throws IOException Returns an ASN.1 BIT STRING value. The bit string must be byte-aligned.
|
getBitString | back to summary |
---|---|
public byte[] getBitString(boolean tagImplicit) throws IOException Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter. The bit string must be byte-aligned.
|
getBMPString | back to summary |
---|---|
public String getBMPString() throws IOException Returns the ASN.1 BMP (Unicode) STRING value as a Java string.
|
getBoolean | back to summary |
---|---|
public boolean getBoolean() throws IOException Returns an ASN.1 BOOLEAN
|
getData | back to summary |
---|---|
public final DerInputStream getData() Returns the data field inside this class directly.
Both this method and the |
getDataBytes | back to summary |
---|---|
public byte[] getDataBytes() Helper routine to return all the bytes contained in the DerInputStream associated with this object. |
getEnumerated | back to summary |
---|---|
public int getEnumerated() throws IOException Returns an ASN.1 ENUMERATED value.
|
getGeneralizedTime | back to summary |
---|---|
public Date getGeneralizedTime() throws IOException Returns a Date if the DerValue is GeneralizedTime.
|
getGeneralString | back to summary |
---|---|
public String getGeneralString() throws IOException Returns the ASN.1 GENERAL STRING value as a Java String.
|
getIA5String | back to summary |
---|---|
public String getIA5String() throws IOException Returns an ASN.1 IA5 (ASCII) STRING value
|
getInteger | back to summary |
---|---|
public int getInteger() throws IOException Returns an ASN.1 INTEGER value as an integer.
|
getIntegerInternal | back to summary |
---|---|
private int getIntegerInternal(byte expectedTag) throws IOException |
getNull | back to summary |
---|---|
public void getNull() throws IOException Reads the ASN.1 NULL value |
getOctetString | back to summary |
---|---|
public byte[] getOctetString() throws IOException Returns an ASN.1 OCTET STRING
|
getOID | back to summary |
---|---|
public ObjectIdentifier getOID() throws IOException Returns an ASN.1 OBJECT IDENTIFIER.
|
getPositiveBigInteger | back to summary |
---|---|
public BigInteger getPositiveBigInteger() throws IOException Returns an ASN.1 INTEGER value as a positive BigInteger. This is just to deal with implementations that incorrectly encode some values as negative.
|
getPrintableString | back to summary |
---|---|
public String getPrintableString() throws IOException Returns an ASN.1 STRING value
|
getT61String | back to summary |
---|---|
public String getT61String() throws IOException Returns an ASN.1 T61 (Teletype) STRING value
|
getTag | back to summary |
---|---|
public final byte getTag() |
getTime | back to summary |
---|---|
public Date getTime() throws IOException Determines whether Date was encoded as UTC or Generalized time and calls getUTCTime or getGeneralizedTime accordingly |
getTimeInternal | back to summary |
---|---|
private Date getTimeInternal(boolean generalized) throws IOException Private helper routine to extract time from the der value.
|
getUnalignedBitString | back to summary |
---|---|
public BitArray getUnalignedBitString() throws IOException Returns an ASN.1 BIT STRING value that need not be byte-aligned.
|
getUnalignedBitString | back to summary |
---|---|
public BitArray getUnalignedBitString(boolean tagImplicit) throws IOException Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter. The bit string need not be byte-aligned.
|
getUniversalString | back to summary |
---|---|
public String getUniversalString() throws IOException Returns the ASN.1 UNIVERSAL (UTF-32) STRING value as a Java String.
|
getUTCTime | back to summary |
---|---|
public Date getUTCTime() throws IOException Returns a Date if the DerValue is UtcTime.
|
getUTF8String | back to summary |
---|---|
public String getUTF8String() throws IOException Returns the ASN.1 UTF-8 STRING value as a Java String.
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Returns a hashcode for this DerValue.
|
isApplication | back to summary |
---|---|
public boolean isApplication() Returns true if the tag class is APPLICATION. |
isConstructed | back to summary |
---|---|
public boolean isConstructed() Returns true iff the CONSTRUCTED bit is set in the type tag. |
isConstructed | back to summary |
---|---|
public boolean isConstructed(byte constructedTag) Returns true iff the CONSTRUCTED TAG matches the passed tag. |
isContextSpecific | back to summary |
---|---|
public boolean isContextSpecific() Returns true iff the CONTEXT SPECIFIC bit is set in the type tag. This is associated with the ASN.1 "DEFINED BY" syntax. |
isContextSpecific | back to summary |
---|---|
public boolean isContextSpecific(byte cntxtTag) Returns true iff the CONTEXT SPECIFIC TAG matches the passed tag. |
isPrintableString | back to summary |
---|---|
private static boolean isPrintableString(String value) |
isPrintableStringChar | back to summary |
---|---|
public static boolean isPrintableStringChar(char ch) Determine if a character is one of the permissible characters for PrintableString: A-Z, a-z, 0-9, space, apostrophe (39), left and right parentheses, plus sign, comma, hyphen, period, slash, colon, equals sign, and question mark. Characters that are *not* allowed in PrintableString include exclamation point, quotation mark, number sign, dollar sign, percent sign, ampersand, asterisk, semicolon, less than sign, greater than sign, at sign, left and right square brackets, backslash, circumflex (94), underscore, back quote (96), left and right curly brackets, vertical line, tilde, and the control codes (0-31 and 127). This list is based on X.680 (the ASN.1 spec). |
isPrivate | back to summary |
---|---|
pack-priv boolean isPrivate() |
isUniversal | back to summary |
---|---|
public boolean isUniversal() Returns true if the tag class is UNIVERSAL. |
length | back to summary |
---|---|
public int length() Get the length of the encoded value. |
readStringInternal | back to summary |
---|---|
private String readStringInternal(byte expectedTag, Charset cs) throws IOException |
resetTag | back to summary |
---|---|
public void resetTag(byte tag) Set the tag of the attribute. Commonly used to reset the tag value used for IMPLICIT encodings. This method should be avoided, consider using withTag() instead.
|
string2bytes | back to summary |
---|---|
private static byte[] string2bytes(byte stringTag, String value) |
subs | back to summary |
---|---|
public DerValue[] subs(byte expectedTag, int startLen) throws IOException Reads the sub-values in a constructed DerValue.
|
toByteArray | back to summary |
---|---|
public byte[] toByteArray() Returns a DER-encoded value, such that if it's passed to the DerValue constructor, a value equivalent to "this" is returned.
|
toDerInputStream | back to summary |
---|---|
public DerInputStream toDerInputStream() throws IOException For "set" and "sequence" types, this function may be used to return a DER stream of the members of the set or sequence. This operation is not supported for primitive types such as integers or bit strings. |
toDigit | back to summary |
---|---|
private static int toDigit(byte b, String type) throws IOException Converts byte (represented as a char) to int.
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns a printable representation of the value. |
withTag | back to summary |
---|---|
public DerValue withTag(byte newTag) Returns a new DerValue with a different tag. This method is used to convert a DerValue decoded from an IMPLICIT encoding to its real tag. The content is not checked against the tag in this method.
|
wrap | back to summary |
---|---|
public static DerValue wrap(byte tag, DerOutputStream out) Wraps a DerOutputStream. All bytes currently written into the stream will become the content of the newly created DerValue. Attention: do not reset the DerOutputStream after this call. No array copying is made.
|
wrap | back to summary |
---|---|
public static DerValue wrap(byte[] buf) throws IOException Wraps a byte array as a single DerValue. Attention: no cloning is made.
|
wrap | back to summary |
---|---|
public static DerValue wrap(byte[] buf, int offset, int len) throws IOException Wraps a byte array as a single DerValue. Attention: no cloning is made.
|