public class

DerValue

extends Object
java.lang.Object
   ↳ sun.security.util.DerValue

Class Overview

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). A note with respect to T61/Teletex strings: From RFC 1617, section 4.1.3 and RFC 3280, section 4.1.2.4., we assume that this kind of string will contain ISO-8859-1 characters only.

Summary

Constants
byte TAG_APPLICATION
byte TAG_CONTEXT
byte TAG_PRIVATE
byte TAG_UNIVERSAL The tag class types
byte tag_BMPString Tag value indicating an ASN.1 "BMPString" value.
byte tag_BitString Tag value indicating an ASN.1 "BIT STRING" value.
byte tag_Boolean Tag value indicating an ASN.1 "BOOLEAN" value.
byte tag_Enumerated Tag value including an ASN.1 "ENUMERATED" value
byte tag_GeneralString Tag value indicating an ASN.1 "GenerallString" value.
byte tag_GeneralizedTime Tag value indicating an ASN.1 "GeneralizedTime" value.
byte tag_IA5String Tag value including an ASCII string
byte tag_Integer Tag value indicating an ASN.1 "INTEGER" value.
byte tag_Null Tag value indicating an ASN.1 "NULL" value.
byte tag_ObjectId Tag value indicating an ASN.1 "OBJECT IDENTIFIER" value.
byte tag_OctetString Tag value indicating an ASN.1 "OCTET STRING" value.
byte tag_PrintableString Tag value including a "printable" string
byte tag_Sequence Tag value indicating an ASN.1 "SEQUENCE" (zero to N elements, order is significant).
byte tag_SequenceOf Tag value indicating an ASN.1 "SEQUENCE OF" (one to N elements, order is significant).
byte tag_Set Tag value indicating an ASN.1 "SET" (zero to N members, order does not matter).
byte tag_SetOf Tag value indicating an ASN.1 "SET OF" (one to N members, order does not matter).
byte tag_T61String Tag value including a "teletype" string
byte tag_UTF8String Tag value indicating an ASN.1 "UTF8String" value.
byte tag_UniversalString Tag value indicating an ASN.1 "UniversalString" value.
byte tag_UtcTime Tag value indicating an ASN.1 "UTCTime" value.
Fields
protected DerInputBuffer buffer
public final DerInputStream data The DER-encoded data of the value.
public byte tag The DER tag of the value; one of the tag_ constants.
Public Constructors
DerValue(String value)
Creates a PrintableString or UTF8string DER value from a string
DerValue(byte stringTag, String value)
Creates a string type DER value from a String object
DerValue(byte tag, byte[] data)
Creates a DerValue from a tag and some DER-encoded data.
DerValue(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(InputStream in)
Get an ASN1/DER encoded datum from an input stream.
Public Methods
static 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 equals(Object other)
Returns true iff the other object is a DER value which is bitwise equal to this one.
boolean equals(DerValue other)
Bitwise equality comparison.
String getAsString()
Returns the name component as a Java string, regardless of its encoding restrictions (ASCII, T61, Printable, IA5, BMP, UTF8).
String getBMPString()
Returns the ASN.1 BMP (Unicode) STRING value as a Java string.
BigInteger getBigInteger()
Returns an ASN.1 INTEGER value as a BigInteger.
byte[] getBitString(boolean tagImplicit)
Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter.
byte[] getBitString()
Returns an ASN.1 BIT STRING value.
boolean getBoolean()
Returns an ASN.1 BOOLEAN
final DerInputStream getData()
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.
String getGeneralString()
Returns the ASN.1 GENERAL STRING value as a Java String.
Date getGeneralizedTime()
Returns a Date if the DerValue is GeneralizedTime.
String getIA5String()
Returns an ASN.1 IA5 (ASCII) STRING value
int getInteger()
Returns an ASN.1 INTEGER value as an integer.
ObjectIdentifier getOID()
Returns an ASN.1 OBJECT IDENTIFIER.
byte[] getOctetString()
Returns an ASN.1 OCTET STRING
BigInteger getPositiveBigInteger()
Returns an ASN.1 INTEGER value as a positive BigInteger.
String getPrintableString()
Returns an ASN.1 STRING value
String getT61String()
Returns an ASN.1 T61 (Teletype) STRING value
final byte getTag()
Date getUTCTime()
Returns a Date if the DerValue is UtcTime.
String getUTF8String()
Returns the ASN.1 UTF-8 STRING value as a Java String.
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.
int hashCode()
Returns a hashcode for this DerValue.
boolean isApplication()
Returns true if the tag class is APPLICATION.
boolean isConstructed(byte constructedTag)
Returns true iff the CONSTRUCTED TAG matches the passed tag.
boolean isConstructed()
Returns true iff the CONSTRUCTED bit is set in the type tag.
boolean isContextSpecific(byte cntxtTag)
Returns true iff the CONTEXT SPECIFIC TAG matches the passed tag.
boolean isContextSpecific()
Returns true iff the CONTEXT SPECIFIC bit is set in the type 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.
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.
String toString()
Returns a printable representation of the value.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final byte TAG_APPLICATION

Constant Value: 64 (0x00000040)

public static final byte TAG_CONTEXT

Constant Value: -128 (0xffffff80)

public static final byte TAG_PRIVATE

Constant Value: -64 (0xffffffc0)

public static final byte TAG_UNIVERSAL

The tag class types

Constant Value: 0 (0x00000000)

public static final byte tag_BMPString

Tag value indicating an ASN.1 "BMPString" value.

Constant Value: 30 (0x0000001e)

public static final byte tag_BitString

Tag value indicating an ASN.1 "BIT STRING" value.

Constant Value: 3 (0x00000003)

public static final byte tag_Boolean

Tag value indicating an ASN.1 "BOOLEAN" value.

Constant Value: 1 (0x00000001)

public static final byte tag_Enumerated

Tag value including an ASN.1 "ENUMERATED" value

Constant Value: 10 (0x0000000a)

public static final byte tag_GeneralString

Tag value indicating an ASN.1 "GenerallString" value.

Constant Value: 27 (0x0000001b)

public static final byte tag_GeneralizedTime

Tag value indicating an ASN.1 "GeneralizedTime" value.

Constant Value: 24 (0x00000018)

public static final byte tag_IA5String

Tag value including an ASCII string

Constant Value: 22 (0x00000016)

public static final byte tag_Integer

Tag value indicating an ASN.1 "INTEGER" value.

Constant Value: 2 (0x00000002)

public static final byte tag_Null

Tag value indicating an ASN.1 "NULL" value.

Constant Value: 5 (0x00000005)

public static final byte tag_ObjectId

Tag value indicating an ASN.1 "OBJECT IDENTIFIER" value.

Constant Value: 6 (0x00000006)

public static final byte tag_OctetString

Tag value indicating an ASN.1 "OCTET STRING" value.

Constant Value: 4 (0x00000004)

public static final byte tag_PrintableString

Tag value including a "printable" string

Constant Value: 19 (0x00000013)

public static final byte tag_Sequence

Tag value indicating an ASN.1 "SEQUENCE" (zero to N elements, order is significant).

Constant Value: 48 (0x00000030)

public static final byte tag_SequenceOf

Tag value indicating an ASN.1 "SEQUENCE OF" (one to N elements, order is significant).

Constant Value: 48 (0x00000030)

public static final byte tag_Set

Tag value indicating an ASN.1 "SET" (zero to N members, order does not matter).

Constant Value: 49 (0x00000031)

public static final byte tag_SetOf

Tag value indicating an ASN.1 "SET OF" (one to N members, order does not matter).

Constant Value: 49 (0x00000031)

public static final byte tag_T61String

Tag value including a "teletype" string

Constant Value: 20 (0x00000014)

public static final byte tag_UTF8String

Tag value indicating an ASN.1 "UTF8String" value.

Constant Value: 12 (0x0000000c)

public static final byte tag_UniversalString

Tag value indicating an ASN.1 "UniversalString" value.

Constant Value: 28 (0x0000001c)

public static final byte tag_UtcTime

Tag value indicating an ASN.1 "UTCTime" value.

Constant Value: 23 (0x00000017)

Fields

protected DerInputBuffer buffer

public final DerInputStream data

The DER-encoded data of the value.

public byte tag

The DER tag of the value; one of the tag_ constants.

Public Constructors

public DerValue (String value)

Creates a PrintableString or UTF8string DER value from a string

Throws
IOException

public DerValue (byte stringTag, String value)

Creates a string type DER value from a String object

Parameters
stringTag the tag for the DER value to create
value the String object to use for the DER value
Throws
IOException

public DerValue (byte tag, byte[] data)

Creates a DerValue from a tag and some DER-encoded data.

Parameters
tag the DER type tag
data the DER-encoded data

public DerValue (byte[] buf)

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

public DerValue (byte[] buf, int offset, int len)

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 buffer
offset start point of the single DER-encoded dataum
Throws
IOException

public DerValue (InputStream in)

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.

Parameters
in the input stream holding a single DER datum, which may be followed by additional data
Throws
IOException

Public Methods

public static byte createTag (byte tagClass, boolean form, byte val)

Create the tag of the attribute.

public void encode (DerOutputStream out)

Encode an ASN1/DER encoded datum onto a DER output stream.

Throws
IOException

public boolean equals (Object other)

Returns true iff the other object is a DER value which is bitwise equal to this one.

Parameters
other the object being compared with this one
Returns
  • true if this object is the same as the obj argument; false otherwise.

public boolean equals (DerValue other)

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

public String getAsString ()

Returns the name component as a Java string, regardless of its encoding restrictions (ASCII, T61, Printable, IA5, BMP, UTF8).

Throws
IOException

public String getBMPString ()

Returns the ASN.1 BMP (Unicode) STRING value as a Java string.

Returns
  • a string corresponding to the encoded BMPString held in this value
Throws
IOException

public BigInteger getBigInteger ()

Returns an ASN.1 INTEGER value as a BigInteger.

Returns
  • the integer held in this DER value as a BigInteger.
Throws
IOException

public byte[] getBitString (boolean tagImplicit)

Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter. The bit string must be byte-aligned.

Returns
  • the bit string held in this value
Throws
IOException

public byte[] 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

public boolean getBoolean ()

Returns an ASN.1 BOOLEAN

Returns
  • the boolean held in this DER value
Throws
IOException

public final DerInputStream getData ()

public byte[] getDataBytes ()

Helper routine to return all the bytes contained in the DerInputStream associated with this object.

Throws
IOException

public int getEnumerated ()

Returns an ASN.1 ENUMERATED value.

Returns
  • the integer held in this DER value.
Throws
IOException

public String getGeneralString ()

Returns the ASN.1 GENERAL STRING value as a Java String.

Returns
  • a string corresponding to the encoded GeneralString held in this value
Throws
IOException

public Date getGeneralizedTime ()

Returns a Date if the DerValue is GeneralizedTime.

Returns
  • the Date held in this DER value
Throws
IOException

public String getIA5String ()

Returns an ASN.1 IA5 (ASCII) STRING value

Returns
  • the ASCII string held in this value
Throws
IOException

public int getInteger ()

Returns an ASN.1 INTEGER value as an integer.

Returns
  • the integer held in this DER value.
Throws
IOException

public ObjectIdentifier getOID ()

Returns an ASN.1 OBJECT IDENTIFIER.

Returns
  • the OID held in this DER value
Throws
IOException

public byte[] getOctetString ()

Returns an ASN.1 OCTET STRING

Returns
  • the octet string held in this DER value
Throws
IOException

public BigInteger getPositiveBigInteger ()

Returns an ASN.1 INTEGER value as a positive BigInteger. This is just to deal with implementations that incorrectly encode some values as negative.

Returns
  • the integer held in this DER value as a BigInteger.
Throws
IOException

public String getPrintableString ()

Returns an ASN.1 STRING value

Returns
  • the printable string held in this value
Throws
IOException

public String getT61String ()

Returns an ASN.1 T61 (Teletype) STRING value

Returns
  • the teletype string held in this value
Throws
IOException

public final byte getTag ()

public Date getUTCTime ()

Returns a Date if the DerValue is UtcTime.

Returns
  • the Date held in this DER value
Throws
IOException

public String getUTF8String ()

Returns the ASN.1 UTF-8 STRING value as a Java String.

Returns
  • a string corresponding to the encoded UTF8String held in this value
Throws
IOException

public BitArray 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

public BitArray getUnalignedBitString (boolean tagImplicit)

Returns an ASN.1 BIT STRING value, with the tag assumed implicit based on the parameter. The bit string need not be byte-aligned.

Returns
  • the bit string held in this value
Throws
IOException

public int hashCode ()

Returns a hashcode for this DerValue.

Returns
  • a hashcode for this DerValue.

public boolean isApplication ()

Returns true if the tag class is APPLICATION.

public boolean isConstructed (byte constructedTag)

Returns true iff the CONSTRUCTED TAG matches the passed tag.

public boolean isConstructed ()

Returns true iff the CONSTRUCTED bit is set in the type tag.

public boolean isContextSpecific (byte cntxtTag)

Returns true iff the CONTEXT SPECIFIC TAG matches the passed tag.

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.

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).

public boolean isUniversal ()

Returns true if the tag class is UNIVERSAL.

public int length ()

Get the length of the encoded value.

public void resetTag (byte tag)

Set the tag of the attribute. Commonly used to reset the tag value used for IMPLICIT encodings.

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.

Returns
  • DER-encoded value, including tag and length.
Throws
IOException

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. This operation is not supported for primitive types such as integers or bit strings.

Throws
IOException

public String toString ()

Returns a printable representation of the value.

Returns
  • printable representation of the value