Class DerValue
java.lang.Object
org.mozilla.jss.netscape.security.util.DerValue
Represents a single DER-encoded value. DER encoding rules are a subset
of the "Basic" Encoding Rules (BER), but they only support a single way
("Definite" encoding) to encode any given value.
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).
- Version:
- 1.43
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DerInputBuffer
The DER-encoded data of the value.private int
byte
The DER tag of the value; one of the tag_ constants.static final byte
static final byte
Tag value indicating an ASN.1 "BIT STRING" value.static final byte
Tag value indicating an ASN.1 "BMPString" value.static final byte
Tag value indicating an ASN.1 "BOOLEAN" value.static final byte
static final byte
Tag value including an ASN.1 "ENUMERATED" valuestatic final byte
Tag value indicating an ASN.1 "GeneralizedTime" value.static final byte
Tag value indicating an ASN.1 "GeneralString" value.static final byte
Tag value including an ASCII stringstatic final byte
Tag value indicating an ASN.1 "INTEGER" value.static final byte
Tag value indicating an ASN.1 "NULL" value.static final byte
Tag value indicating an ASN.1 "OBJECT IDENTIFIER" value.static final byte
Tag value indicating an ASN.1 "OCTET STRING" value.static final byte
Tag value including a "printable" stringstatic final byte
static final byte
Tag value indicating an ASN.1 "SEQUENCE" (zero to N elements, order is significant).static final byte
Tag value indicating an ASN.1 "SEQUENCE OF" (one to N elements, order is significant).static final byte
Tag value indicating an ASN.1 "SET" (zero to N members, order does not matter).static final byte
Tag value indicating an ASN.1 "SET OF" (one to N members, order does not matter).static final byte
Tag value including a "teletype" stringstatic final byte
The tag class typesstatic final byte
Tag value indicating an ASN.1 "UniversalString" value.static final byte
Tag value indicating an ASN.1 "UTCTime" value.static final byte
Tag value indicating an ASN.1 "UTF8String" value.static final byte
static final byte[]
-
Constructor Summary
ConstructorsConstructorDescriptionDerValue
(byte[] buf) Get an ASN.1/DER encoded datum from a buffer.DerValue
(byte[] buf, int offset, int len) Get an ASN.1/DER encoded datum from part of a buffer.DerValue
(byte tag, byte[] data) Creates a DerValue from a tag and some DER-encoded data.DerValue
(byte tag, byte[] data, int offset, int length) Creates a DerValue from a tag and some DER-encoded data.DerValue
(InputStream in) Get an ASN1/DER encoded datum from an input stream.Creates a DER value from a string using a generic way of determining the proper tag for the string. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte
createTag
(byte tagClass, boolean form, byte val) Create the tag of the attribute.void
encode
(DerOutputStream out) Encode an ASN1/DER encoded datum onto a DER output stream.boolean
Returns true iff the other object is a DER value which is bitwise equal to this one.boolean
Bitwise equality comparison.Returns the name component as a Java string, regardless of its encoding restrictions (ASCII, T61, Printable, etc).byte[]
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.boolean
Returns an ASN.1 BOOLEANint
Returns an ASN.1 unsigned integer value of enumerated value.Returns an ASN.1 IA5 (ASCII) STRING valueReturns an ASN.1 unsigned INTEGER value.getInteger
(boolean tagImplicit) Returns an ASN.1 unsigned INTEGER value, the parameter determining if the tag is implicit.byte[]
Returns an ASN.1 OCTET STRINGgetOID()
Returns an ASN.1 OBJECT IDENTIFIER.Returns an ASN.1 STRING valueReturns an ASN.1 T61 (Teletype) STRING valueReturns an ASN.1 BIT STRING value that need not be byte-aligned.getUnalignedBitString
(boolean tagImplicit) Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter.int
hashCode()
private void
init
(boolean fullyBuffered, InputStream in) (package private) boolean
boolean
Returns true iff the CONSTRUCTED bit is set in the type tag.boolean
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.(package private) boolean
(package private) boolean
int
length()
Get the length of the encoded value.void
resetTag
(byte tag) Set the tag of the attribute.byte[]
Returns a DER-encoded value, such that if it's passed to the DerValue constructor, a value equivalent to "this" is returned.For "set" and "sequence" types, this function may be used to return a DER stream of the members of the set or sequence.toString()
Returns a printable representation of the value.
-
Field Details
-
TAG_UNIVERSAL
public static final byte TAG_UNIVERSALThe tag class types- See Also:
-
TAG_APPLICATION
public static final byte TAG_APPLICATION- See Also:
-
TAG_CONTEXT
public static final byte TAG_CONTEXT- See Also:
-
TAG_PRIVATE
public static final byte TAG_PRIVATE- See Also:
-
tag
public byte tagThe DER tag of the value; one of the tag_ constants. -
buffer
-
data
The DER-encoded data of the value. -
length
private int length -
tag_Boolean
public static final byte tag_BooleanTag value indicating an ASN.1 "BOOLEAN" value.- See Also:
-
tag_Integer
public static final byte tag_IntegerTag value indicating an ASN.1 "INTEGER" value.- See Also:
-
tag_BitString
public static final byte tag_BitStringTag value indicating an ASN.1 "BIT STRING" value.- See Also:
-
tag_OctetString
public static final byte tag_OctetStringTag value indicating an ASN.1 "OCTET STRING" value.- See Also:
-
tag_Null
public static final byte tag_NullTag value indicating an ASN.1 "NULL" value.- See Also:
-
tag_ObjectId
public static final byte tag_ObjectIdTag value indicating an ASN.1 "OBJECT IDENTIFIER" value.- See Also:
-
tag_Enumerated
public static final byte tag_EnumeratedTag value including an ASN.1 "ENUMERATED" value- See Also:
-
tag_PrintableString
public static final byte tag_PrintableStringTag value including a "printable" string- See Also:
-
tag_VisibleString
public static final byte tag_VisibleString- See Also:
-
tag_T61String
public static final byte tag_T61StringTag value including a "teletype" string- See Also:
-
tag_IA5String
public static final byte tag_IA5StringTag value including an ASCII string- See Also:
-
tag_UtcTime
public static final byte tag_UtcTimeTag value indicating an ASN.1 "UTCTime" value.- See Also:
-
tag_GeneralizedTime
public static final byte tag_GeneralizedTimeTag value indicating an ASN.1 "GeneralizedTime" value.- See Also:
-
tag_GeneralString
public static final byte tag_GeneralStringTag value indicating an ASN.1 "GeneralString" value.- See Also:
-
tag_BMPString
public static final byte tag_BMPStringTag value indicating an ASN.1 "BMPString" value.- See Also:
-
tag_UniversalString
public static final byte tag_UniversalStringTag value indicating an ASN.1 "UniversalString" value.- See Also:
-
tag_UTF8String
public static final byte tag_UTF8StringTag value indicating an ASN.1 "UTF8String" value. (since 1998)- See Also:
-
tags_DirectoryString
public static final byte[] tags_DirectoryString -
tag_Sequence
public static final byte tag_SequenceTag value indicating an ASN.1 "SEQUENCE" (zero to N elements, order is significant).- See Also:
-
tag_SequenceOf
public static final byte tag_SequenceOfTag value indicating an ASN.1 "SEQUENCE OF" (one to N elements, order is significant).- See Also:
-
tag_Set
public static final byte tag_SetTag value indicating an ASN.1 "SET" (zero to N members, order does not matter).- See Also:
-
tag_SetOf
public static final byte tag_SetOfTag value indicating an ASN.1 "SET OF" (one to N members, order does not matter).- See Also:
-
-
Constructor Details
-
DerValue
Creates a DER value from a string using a generic way of determining the proper tag for the string. Assumes the string is a Generic attribute value and uses the converter for generic string values to convert to the Der Value.- Throws:
IOException
-
DerValue
public DerValue(byte tag, byte[] data) Creates a DerValue from a tag and some DER-encoded data.- Parameters:
tag
- the DER type tagdata
- the DER-encoded data
-
DerValue
public DerValue(byte tag, byte[] data, int offset, int length) Creates a DerValue from a tag and some DER-encoded data.- Parameters:
tag
- the DER type tagdata
- the DER-encoded dataoffset
- offset of the datalength
- length of the data
-
DerValue
DerValue(DerInputBuffer in) throws IOException - Throws:
IOException
-
DerValue
Get an ASN.1/DER encoded datum from a buffer. The entire buffer must hold exactly one datum, including its tag and length.- Parameters:
buf
- buffer holding a single DER-encoded datum.- Throws:
IOException
-
DerValue
Get an ASN.1/DER encoded datum from part of a buffer. That part of the buffer must hold exactly one datum, including its tag and length.- Parameters:
buf
- the bufferoffset
- start point of the single DER-encoded dataumlen
- how many bytes are in the encoded datum- Throws:
IOException
-
DerValue
Get an ASN1/DER encoded datum from an input stream. The stream may have additional data following the encoded datum.- Parameters:
in
- the input stream holding a single DER datum, which may be followed by additional data- Throws:
IOException
-
-
Method Details
-
isUniversal
boolean isUniversal() -
isApplication
boolean isApplication() -
isContextSpecific
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
public boolean isContextSpecific(byte cntxtTag) Returns true iff the CONTEXT SPECIFIC TAG matches the passed tag. -
isPrivate
boolean isPrivate() -
isConstructed
public boolean isConstructed()Returns true iff the CONSTRUCTED bit is set in the type tag. -
init
- Throws:
IOException
-
encode
Encode an ASN1/DER encoded datum onto a DER output stream.- Throws:
IOException
-
getBoolean
Returns an ASN.1 BOOLEAN- Returns:
- the boolean held in this DER value
- Throws:
IOException
-
getOID
Returns an ASN.1 OBJECT IDENTIFIER.- Returns:
- the OID held in this DER value
- Throws:
IOException
-
getOctetString
Returns an ASN.1 OCTET STRING- Returns:
- the octet string held in this DER value
- Throws:
IOException
-
getEnumerated
Returns an ASN.1 unsigned integer value of enumerated value.- Returns:
- the (unsigned) integer held in this DER value
- Throws:
IOException
-
getInteger
Returns an ASN.1 unsigned INTEGER value.- Returns:
- the (unsigned) integer held in this DER value
- Throws:
IOException
-
getInteger
Returns an ASN.1 unsigned INTEGER value, the parameter determining if the tag is implicit.- Parameters:
tagImplicit
- if true, ignores the tag value as it is assumed implicit.- Returns:
- the (unsigned) integer held in this DER value
- Throws:
IOException
-
getBitString
Returns an ASN.1 BIT STRING value. The bit string must be byte-aligned.- Returns:
- the bit string held in this value
- Throws:
IOException
-
getUnalignedBitString
Returns an ASN.1 BIT STRING value that need not be byte-aligned.- Returns:
- a BitArray representing the bit string held in this value
- Throws:
IOException
-
getAsString
Returns the name component as a Java string, regardless of its encoding restrictions (ASCII, T61, Printable, etc).- Throws:
IOException
-
getBitString
Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter. The bit string must be byte-aligned.- Parameters:
tagImplicit
- if true, the tag is assumed implicit.- Returns:
- the bit string held in this value
- Throws:
IOException
-
getUnalignedBitString
Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter. The bit string need not be byte-aligned.- Parameters:
tagImplicit
- if true, the tag is assumed implicit.- Returns:
- the bit string held in this value
- Throws:
IOException
-
getPrintableString
Returns an ASN.1 STRING value- Returns:
- the printable string held in this value
- Throws:
IOException
-
getDirectoryString
- Throws:
IOException
-
getASN1CharString
- Throws:
IOException
-
getT61String
Returns an ASN.1 T61 (Teletype) STRING value- Returns:
- the teletype string held in this value
- Throws:
IOException
-
getIA5String
Returns an ASN.1 IA5 (ASCII) STRING value- Returns:
- the ASCII string held in this value
- Throws:
IOException
-
getBMPString
- Throws:
IOException
-
getUniversalString
- Throws:
IOException
-
getUTF8String
- Throws:
IOException
-
equals
Returns true iff the other object is a DER value which is bitwise equal to this one. -
hashCode
public int hashCode() -
equals
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.- Parameters:
other
- the object being compared with this one
-
toString
Returns a printable representation of the value. -
toByteArray
Returns a DER-encoded value, such that if it's passed to the DerValue constructor, a value equivalent to "this" is returned.- Returns:
- DER-encoded value, including tag and length.
- Throws:
IOException
-
toDerInputStream
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.- Throws:
IOException
-
length
public int length()Get the length of the encoded value. -
createTag
public static byte createTag(byte tagClass, boolean form, byte val) Create the tag of the attribute.- Parameters:
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 value
-
resetTag
public void resetTag(byte tag) Set the tag of the attribute. Commonly used to reset the tag value used for IMPLICIT encodings.- Parameters:
tag
- the tag value
-