public class DerValue
extends java.lang.Object
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 |
|---|---|
DerInputStream |
data |
byte |
tag |
static byte |
TAG_APPLICATION |
static byte |
tag_BitString
Tag value indicating an ASN.1 "BIT STRING" value.
|
static byte |
tag_BMPString
Tag value indicating an ASN.1 "BMPString" value.
|
static byte |
tag_Boolean
Tag value indicating an ASN.1 "BOOLEAN" value.
|
static byte |
TAG_CONTEXT |
static byte |
tag_Enumerated
Tag value including an ASN.1 "ENUMERATED" value
|
static byte |
tag_GeneralizedTime
Tag value indicating an ASN.1 "GeneralizedTime" value.
|
static byte |
tag_GeneralString
Tag value indicating an ASN.1 "GeneralString" value.
|
static byte |
tag_IA5String
Tag value including an ASCII string
|
static byte |
tag_Integer
Tag value indicating an ASN.1 "INTEGER" value.
|
static byte |
tag_Null
Tag value indicating an ASN.1 "NULL" value.
|
static byte |
tag_ObjectId
Tag value indicating an ASN.1 "OBJECT IDENTIFIER" value.
|
static byte |
tag_OctetString
Tag value indicating an ASN.1 "OCTET STRING" value.
|
static byte |
tag_PrintableString
Tag value including a "printable" string
|
static byte |
TAG_PRIVATE |
static byte |
tag_Sequence
Tag value indicating an ASN.1
"SEQUENCE" (zero to N elements, order is significant).
|
static byte |
tag_SequenceOf
Tag value indicating an ASN.1
"SEQUENCE OF" (one to N elements, order is significant).
|
static byte |
tag_Set
Tag value indicating an ASN.1
"SET" (zero to N members, order does not matter).
|
static byte |
tag_SetOf
Tag value indicating an ASN.1
"SET OF" (one to N members, order does not matter).
|
static byte |
tag_T61String
Tag value including a "teletype" string
|
static byte |
TAG_UNIVERSAL
The tag class types
|
static byte |
tag_UniversalString
Tag value indicating an ASN.1 "UniversalString" value.
|
static byte |
tag_UtcTime
Tag value indicating an ASN.1 "UTCTime" value.
|
static byte |
tag_UTF8String
Tag value indicating an ASN.1 "UTF8String" value.
|
| Constructor and Description |
|---|
DerValue(byte[] encoding)
Parse an ASN.1/BER encoded datum.
|
DerValue(byte tag,
byte[] buffer)
Creates a DerValue from a tag and some DER-encoded data.
|
DerValue(byte stringTag,
java.lang.String value)
Creates a string type DER value from a String object
|
DerValue(java.io.InputStream in)
Get an ASN1/DER encoded datum from an input stream.
|
DerValue(java.lang.String value)
Creates a PrintableString or UTF8string DER value from a string.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
static byte |
createTag(byte tagClass,
boolean form,
byte val)
Create the tag of the attribute.
|
DerInputStream |
data()
Returns a new DerInputStream pointing at the start of this
DerValue's content.
|
void |
encode(DerOutputStream out)
Encode an ASN1/DER encoded datum onto a DER output stream.
|
boolean |
equals(java.lang.Object o)
Bitwise equality comparison.
|
java.lang.String |
getAsString()
Returns the name component as a Java string, regardless of its
encoding restrictions (ASCII, T61, Printable, IA5, BMP, UTF8).
|
java.math.BigInteger |
getBigInteger()
Returns an ASN.1 INTEGER value as a BigInteger.
|
byte[] |
getBitString()
Returns an ASN.1 BIT STRING value.
|
byte[] |
getBitString(boolean tagImplicit)
Returns an ASN.1 BIT STRING value, with the tag assumed implicit
based on the parameter.
|
java.lang.String |
getBMPString()
Returns the ASN.1 BMP (Unicode) STRING value as a Java string.
|
boolean |
getBoolean()
Returns an ASN.1 BOOLEAN
|
DerInputStream |
getData()
Returns the data field inside this class directly.
|
byte[] |
getDataBytes()
Helper routine to return all the bytes contained in the
DerInputStream associated with this object.
|
int |
getEnumerated()
Returns an ASN.1 ENUMERATED value.
|
java.util.Date |
getGeneralizedTime()
Returns a Date if the DerValue is GeneralizedTime.
|
java.lang.String |
getGeneralString()
Returns the ASN.1 GENERAL STRING value as a Java String.
|
java.lang.String |
getIA5String()
Returns an ASN.1 IA5 (ASCII) STRING value
|
int |
getInteger()
Returns an ASN.1 INTEGER value as an integer.
|
void |
getNull()
Reads the ASN.1 NULL value
|
byte[] |
getOctetString()
Returns an ASN.1 OCTET STRING
|
ObjectIdentifier |
getOID()
Returns an ASN.1 OBJECT IDENTIFIER.
|
java.math.BigInteger |
getPositiveBigInteger()
Returns an ASN.1 INTEGER value as a positive BigInteger.
|
java.lang.String |
getPrintableString()
Returns an ASN.1 STRING value
|
java.lang.String |
getT61String()
Returns an ASN.1 T61 (Teletype) STRING value
|
byte |
getTag() |
BitArray |
getUnalignedBitString()
Returns an ASN.1 BIT STRING value that need not be byte-aligned.
|
BitArray |
getUnalignedBitString(boolean tagImplicit)
Returns an ASN.1 BIT STRING value, with the tag assumed implicit
based on the parameter.
|
java.lang.String |
getUniversalString()
Returns the ASN.1 UNIVERSAL (UTF-32) STRING value as a Java String.
|
java.util.Date |
getUTCTime()
Returns a Date if the DerValue is UtcTime.
|
java.lang.String |
getUTF8String()
Returns the ASN.1 UTF-8 STRING value as a Java String.
|
int |
hashCode()
Returns a hashcode for this DerValue.
|
boolean |
isApplication()
Returns true if the tag class is APPLICATION.
|
boolean |
isConstructed()
Returns true iff the CONSTRUCTED bit is set in the type tag.
|
boolean |
isConstructed(byte constructedTag)
Returns true iff the CONSTRUCTED TAG matches the passed tag.
|
boolean |
isContextSpecific()
Returns true iff the CONTEXT SPECIFIC bit is set in the type tag.
|
boolean |
isContextSpecific(byte cntxtTag)
Returns true iff the CONTEXT SPECIFIC TAG matches the passed tag.
|
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.
|
boolean |
isUniversal()
Returns true if the tag class is UNIVERSAL.
|
int |
length()
Get the length of the encoded value.
|
void |
resetTag(byte tag)
Set the tag of the attribute.
|
DerValue[] |
subs(byte expectedTag,
int startLen)
Reads the sub-values in a constructed DerValue.
|
byte[] |
toByteArray()
Returns a DER-encoded value, such that if it's passed to the
DerValue constructor, a value equivalent to "this" is returned.
|
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.
|
java.lang.String |
toString()
Returns a printable representation of the value.
|
DerValue |
withTag(byte newTag)
Returns a new DerValue with a different tag.
|
static DerValue |
wrap(byte[] buf)
Wraps a byte array as a single DerValue.
|
static DerValue |
wrap(byte[] buf,
int offset,
int len)
Wraps a byte array as a single DerValue.
|
static DerValue |
wrap(byte tag,
DerOutputStream out)
Wraps a DerOutputStream.
|
public static final byte TAG_UNIVERSAL
public static final byte TAG_APPLICATION
public static final byte TAG_CONTEXT
public static final byte TAG_PRIVATE
public static final byte tag_Boolean
public static final byte tag_Integer
public static final byte tag_BitString
public static final byte tag_OctetString
public static final byte tag_Null
public static final byte tag_ObjectId
public static final byte tag_Enumerated
public static final byte tag_UTF8String
public static final byte tag_PrintableString
public static final byte tag_T61String
public static final byte tag_IA5String
public static final byte tag_UtcTime
public static final byte tag_GeneralizedTime
public static final byte tag_GeneralString
public static final byte tag_UniversalString
public static final byte tag_BMPString
public static final byte tag_Sequence
public static final byte tag_SequenceOf
public static final byte tag_Set
public static final byte tag_SetOf
public byte tag
public final DerInputStream data
public DerValue(java.lang.String value)
public DerValue(byte stringTag,
java.lang.String value)
stringTag - the tag for the DER value to createvalue - the String object to use for the DER valuepublic DerValue(byte tag,
byte[] buffer)
tag - the DER type tagbuffer - the DER-encoded datapublic DerValue(byte[] encoding)
throws java.io.IOException
java.io.IOExceptionpublic DerValue(java.io.InputStream in)
throws java.io.IOException
in - the input stream holding a single DER datum,
which may be followed by additional datajava.io.IOExceptionpublic boolean isUniversal()
public boolean isApplication()
public boolean isContextSpecific()
public boolean isContextSpecific(byte cntxtTag)
public boolean isConstructed()
public boolean isConstructed(byte constructedTag)
public static DerValue wrap(byte tag, DerOutputStream out)
tag - the tagout - the DerOutputStreampublic static DerValue wrap(byte[] buf) throws java.io.IOException
buf - the byte array containing the DER-encoded datumjava.io.IOExceptionpublic static DerValue wrap(byte[] buf, int offset, int len) throws java.io.IOException
buf - the byte array containing the DER-encoded datumoffset - where the encoded datum starts inside buflen - length of bytes to parse inside bufjava.io.IOExceptionpublic void encode(DerOutputStream out) throws java.io.IOException
java.io.IOExceptionpublic final DerInputStream data()
public final DerInputStream getData()
public final byte getTag()
public boolean getBoolean()
throws java.io.IOException
java.io.IOExceptionpublic ObjectIdentifier getOID() throws java.io.IOException
java.io.IOExceptionpublic byte[] getOctetString()
throws java.io.IOException
java.io.IOExceptionpublic int getInteger()
throws java.io.IOException
java.io.IOExceptionpublic java.math.BigInteger getBigInteger()
throws java.io.IOException
java.io.IOExceptionpublic java.math.BigInteger getPositiveBigInteger()
throws java.io.IOException
java.io.IOExceptionpublic int getEnumerated()
throws java.io.IOException
java.io.IOExceptionpublic byte[] getBitString()
throws java.io.IOException
java.io.IOExceptionpublic BitArray getUnalignedBitString() throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getAsString()
throws java.io.IOException
java.io.IOExceptionpublic byte[] getBitString(boolean tagImplicit)
throws java.io.IOException
tagImplicit - if true, the tag is assumed implicit.java.io.IOExceptionpublic BitArray getUnalignedBitString(boolean tagImplicit) throws java.io.IOException
tagImplicit - if true, the tag is assumed implicit.java.io.IOExceptionpublic byte[] getDataBytes()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getPrintableString()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getT61String()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getIA5String()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getBMPString()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getUTF8String()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getGeneralString()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getUniversalString()
throws java.io.IOException
java.io.IOExceptionpublic void getNull()
throws java.io.IOException
java.io.IOExceptionpublic java.util.Date getUTCTime()
throws java.io.IOException
java.io.IOExceptionpublic java.util.Date getGeneralizedTime()
throws java.io.IOException
java.io.IOExceptionpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - the object being compared with this onepublic java.lang.String toString()
toString in class java.lang.Objectpublic byte[] toByteArray()
throws java.io.IOException
java.io.IOExceptionpublic DerInputStream toDerInputStream() throws java.io.IOException
java.io.IOExceptionpublic int length()
public static boolean isPrintableStringChar(char ch)
public static byte createTag(byte tagClass,
boolean form,
byte val)
tagClass - the tag class type, one of UNIVERSAL, CONTEXT,
APPLICATION or PRIVATEform - if true, the value is constructed, otherwise it
is primitive.val - the tag valuepublic void resetTag(byte tag)
tag - the tag valuepublic DerValue withTag(byte newTag)
newTag - the new tagpublic int hashCode()
hashCode in class java.lang.Objectpublic DerValue[] subs(byte expectedTag, int startLen) throws java.io.IOException
expectedTag - the expected tag, or zero if we don't check.
This is useful when this DerValue is IMPLICIT.startLen - estimated number of sub-valuesjava.io.IOExceptionpublic void clear()