Top Description Fields Constructors Methods
sun.security.util

public Class DerValue

extends Object
Class Inheritance
Imports
jdk.internal.util.ArraysSupport, sun.nio.cs.UTF_32BE, sun.util.calendar.CalendarDate, .CalendarSystem, java.io.*, java.math.BigInteger, java.nio.charset.Charset, java.util.*

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 5280, section 8, we assume that this kind of string will contain ISO-8859-1 characters only.

Authors
David Brownell, Amit Kapoor, Hemma Prafullchandra

Field Summary

Modifier and TypeField 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.

Constructor Summary

AccessConstructor 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
DerValue(String value)

Creates a PrintableString or UTF8string DER value from a string.

public
DerValue(byte
the tag for the DER value to create
stringTag
,
String
the String object to use for the DER value
value
)

Creates a string type DER value from a String object

pack-priv
DerValue(byte tag, byte[] buffer, boolean allowBER)

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
DerValue(byte[] encoding)

Parse an ASN.1/BER encoded datum.

pack-priv
DerValue(byte[]
the byte array containing the DER-encoded datum
buf
,
int
where the encoded datum starts inside buf
offset
,
int
length of bytes to parse inside buf
len
,
boolean
whether BER is allowed
allowBER
,
boolean
whether extra bytes are allowed after the encoded datum. If true, len can be bigger than the length of the encoded datum.
allowMore
)

Parse an ASN.1 encoded datum from a byte array.

pack-priv
DerValue(InputStream in, boolean allowBER)

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.

Method Summary

Modifier and TypeMethod and Description
private static int
checkPaddedBits(int numOfPadBits, byte[] data, int start, int end, boolean allowBER)

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 value
data
()

Returns a new DerInputStream pointing at the start of this DerValue's content.

public void
encode(DerOutputStream out)

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

public boolean
equals(Object
the object being compared with this one
o
)

Overrides java.lang.Object.equals.

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

Returns an ASN.1 INTEGER value as a BigInteger.

private BigInteger

Returns:

the integer as a BigInteger.
getBigIntegerInternal
(byte expectedTag, boolean
whether to always return a positive value, irrespective of actual encoding
makePositive
)

Returns a BigInteger value

public byte[]

Returns:

the bit string held in this value
getBitString
()

Returns an ASN.1 BIT STRING value.

public byte[]

Returns:

the bit string held in this value
getBitString
(boolean
if 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 value
getBMPString
()

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

public boolean

Returns:

the boolean held in this DER value
getBoolean
()

Returns an ASN.1 BOOLEAN

public final DerInputStream
getData()

Returns the data field inside this class directly.

public byte[]
getDataBytes()

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

public int

Returns:

the integer held in this DER value.
getEnumerated
()

Returns an ASN.1 ENUMERATED value.

public Date

Returns:

the Date held in this DER value
getGeneralizedTime
()

Returns a Date if the DerValue is GeneralizedTime.

public String

Returns:

a string corresponding to the encoded GeneralString held in this value
getGeneralString
()

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

public String

Returns:

the ASCII string held in this value
getIA5String
()

Returns an ASN.1 IA5 (ASCII) STRING value

public int

Returns:

the integer held in this DER value.
getInteger
()

Returns an ASN.1 INTEGER value as an integer.

private int
getIntegerInternal(byte expectedTag)

public void
getNull()

Reads the ASN.1 NULL value

public byte[]

Returns:

the octet string held in this DER value
getOctetString
()

Returns an ASN.1 OCTET STRING

public ObjectIdentifier

Returns:

the OID held in this DER value
getOID
()

Returns an ASN.1 OBJECT IDENTIFIER.

public BigInteger

Returns:

the integer held in this DER value as a BigInteger.
getPositiveBigInteger
()

Returns an ASN.1 INTEGER value as a positive BigInteger.

public String

Returns:

the printable string held in this value
getPrintableString
()

Returns an ASN.1 STRING value

public String

Returns:

the teletype string held in this value
getT61String
()

Returns 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 value
getUnalignedBitString
()

Returns an ASN.1 BIT STRING value that need not be byte-aligned.

public BitArray

Returns:

the bit string held in this value
getUnalignedBitString
(boolean
if 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 value
getUniversalString
()

Returns the ASN.1 UNIVERSAL (UTF-32) STRING value as a Java String.

public Date

Returns:

the Date held in this DER value
getUTCTime
()

Returns a Date if the DerValue is UtcTime.

public String

Returns:

a string corresponding to the encoded UTF8String held in this value
getUTF8String
()

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

public int

Returns:

a hashcode for this DerValue
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hashcode for this DerValue.

public boolean
isApplication()

Returns true if the tag class is APPLICATION.

public boolean
isConstructed()

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

public boolean
isConstructed(byte constructedTag)

Returns true iff the CONSTRUCTED TAG matches the passed tag.

public boolean
isContextSpecific()

Returns true iff the CONTEXT SPECIFIC bit is set in the type tag.

public boolean
isContextSpecific(byte cntxtTag)

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

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
isUniversal()

Returns true if the tag class is UNIVERSAL.

public int
length()

Get the length of the encoded value.

private String
readStringInternal(byte expectedTag, Charset cs)

public void
resetTag(byte
the tag value
tag
)

Set the tag of the attribute.

private static byte[]
string2bytes(byte stringTag, String value)

public DerValue[]

Returns:

the sub-values in an array
subs
(byte
the 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.
toByteArray
()

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
toDigit(byte b, String type)

Converts byte (represented as a char) to int.

public String

Returns:

printable representation of the value
toString
()

Overrides java.lang.Object.toString.

Returns a printable representation of the value.

public DerValue

Returns:

a new DerValue
withTag
(byte
the new tag
newTag
)

Returns a new DerValue with a different tag.

public static DerValue

Returns:

a new DerValue using out as its content
wrap
(byte
the tag
tag
,
DerOutputStream
the DerOutputStream
out
)

Wraps a DerOutputStream.

public static DerValue

Returns:

a new DerValue
wrap
(byte[]
the byte array containing the DER-encoded datum
buf
)

Wraps a byte array as a single DerValue.

public static DerValue

Returns:

a new DerValue
wrap
(byte[]
the byte array containing the DER-encoded datum
buf
,
int
where the encoded datum starts inside buf
offset
,
int
length of bytes to parse inside buf
len
)

Wraps a byte array as a single DerValue.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

allowBERback to summary
private final boolean allowBER
bufferback to summary
pack-priv final byte[] buffer
databack to summary
public final DerInputStream data
endback to summary
pack-priv final int end
startback to summary
private final int start
tagback to summary
public byte tag
TAG_APPLICATIONback to summary
public static final byte TAG_APPLICATION
tag_BitStringback to summary
public static final byte tag_BitString

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

tag_BMPStringback to summary
public static final byte tag_BMPString

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

tag_Booleanback to summary
public static final byte tag_Boolean

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

TAG_CONTEXTback to summary
public static final byte TAG_CONTEXT
tag_Enumeratedback to summary
public static final byte tag_Enumerated

Tag value including an ASN.1 "ENUMERATED" value

tag_GeneralizedTimeback to summary
public static final byte tag_GeneralizedTime

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

tag_GeneralStringback to summary
public static final byte tag_GeneralString

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

tag_IA5Stringback to summary
public static final byte tag_IA5String

Tag value including an ASCII string

tag_Integerback to summary
public static final byte tag_Integer

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

tag_Nullback to summary
public static final byte tag_Null

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

tag_ObjectIdback to summary
public static final byte tag_ObjectId

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

tag_OctetStringback to summary
public static final byte tag_OctetString

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

tag_PrintableStringback to summary
public static final byte tag_PrintableString

Tag value including a "printable" string

TAG_PRIVATEback to summary
public static final byte TAG_PRIVATE
tag_Sequenceback to summary
public static final byte tag_Sequence

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

tag_SequenceOfback to summary
public static final byte tag_SequenceOf

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

tag_Setback to summary
public static final byte tag_Set

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

tag_SetOfback 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_T61Stringback to summary
public static final byte tag_T61String

Tag value including a "teletype" string

TAG_UNIVERSALback to summary
public static final byte TAG_UNIVERSAL

The tag class types

tag_UniversalStringback to summary
public static final byte tag_UniversalString

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

tag_UtcTimeback to summary
public static final byte tag_UtcTime

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

tag_UTF8Stringback to summary
public static final byte tag_UTF8String

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

Constructor Detail

DerValueback to summary
pack-priv DerValue(byte tag, byte[] buffer, int start, int end, boolean allowBER)

Creates a new DerValue by specifying all its fields.

DerValueback to summary
public DerValue(String value)

Creates a PrintableString or UTF8string DER value from a string.

DerValueback to summary
public DerValue(byte stringTag, String value)

Creates a string type DER value from a String object

Parameters
stringTag:byte

the tag for the DER value to create

value:String

the String object to use for the DER value

DerValueback to summary
pack-priv DerValue(byte tag, byte[] buffer, boolean allowBER)
DerValueback to summary
public DerValue(byte tag, byte[] buffer)

Creates a DerValue from a tag and some DER-encoded data. This is a public constructor.

Parameters
tag:byte

the DER type tag

buffer:byte[]

the DER-encoded data

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

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

Parameters
buf:byte[]

the byte array containing the DER-encoded datum

offset:int

where the encoded datum starts inside buf

len:int

length of bytes to parse inside buf

allowBER:boolean

whether BER is allowed

allowMore:boolean

whether extra bytes are allowed after the encoded datum. If true, len can be bigger than the length of the encoded datum.

Exceptions
IOException:
if it's an invalid encoding or there are extra bytes after the encoded datum and allowMore is false.
DerValueback to summary
pack-priv DerValue(InputStream in, boolean allowBER) throws IOException
DerValueback 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.

Parameters
in:InputStream

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

Method Detail

checkPaddedBitsback to summary
private static int checkPaddedBits(int numOfPadBits, byte[] data, int start, int end, boolean allowBER) throws IOException
clearback to summary
public void clear()
createTagback to summary
public static byte createTag(byte tagClass, boolean form, byte val)

Create the tag of the attribute.

Parameters
tagClass:byte

the tag class type, one of UNIVERSAL, CONTEXT, APPLICATION or PRIVATE

form:boolean

if true, the value is constructed, otherwise it is primitive.

val:byte

the tag value

databack to summary
public final DerInputStream data()

Returns a new DerInputStream pointing at the start of this DerValue's content.

Returns:DerInputStream

the new DerInputStream value

encodeback to summary
public void encode(DerOutputStream out)

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

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.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
o:Object

the object being compared with this one

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAsStringback 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).

getBigIntegerback to summary
public BigInteger getBigInteger() throws IOException

Returns an ASN.1 INTEGER value as a BigInteger.

Returns:BigInteger

the integer held in this DER value as a BigInteger.

getBigIntegerInternalback to summary
private BigInteger getBigIntegerInternal(byte expectedTag, boolean makePositive) throws IOException

Returns a BigInteger value

Parameters
makePositive:boolean

whether to always return a positive value, irrespective of actual encoding

Returns:BigInteger

the integer as a BigInteger.

getBitStringback to summary
public byte[] getBitString() throws IOException

Returns an ASN.1 BIT STRING value. The bit string must be byte-aligned.

Returns:byte[]

the bit string held in this value

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

Parameters
tagImplicit:boolean

if true, the tag is assumed implicit.

Returns:byte[]

the bit string held in this value

getBMPStringback to summary
public String getBMPString() throws IOException

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

Returns:String

a string corresponding to the encoded BMPString held in this value

getBooleanback to summary
public boolean getBoolean() throws IOException

Returns an ASN.1 BOOLEAN

Returns:boolean

the boolean held in this DER value

getDataback to summary
public final DerInputStream getData()

Returns the data field inside this class directly. Both this method and the data field should be avoided. Consider using data() instead.

getDataBytesback to summary
public byte[] getDataBytes()

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

getEnumeratedback to summary
public int getEnumerated() throws IOException

Returns an ASN.1 ENUMERATED value.

Returns:int

the integer held in this DER value.

getGeneralizedTimeback to summary
public Date getGeneralizedTime() throws IOException

Returns a Date if the DerValue is GeneralizedTime.

Returns:Date

the Date held in this DER value

getGeneralStringback to summary
public String getGeneralString() throws IOException

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

Returns:String

a string corresponding to the encoded GeneralString held in this value

getIA5Stringback to summary
public String getIA5String() throws IOException

Returns an ASN.1 IA5 (ASCII) STRING value

Returns:String

the ASCII string held in this value

getIntegerback to summary
public int getInteger() throws IOException

Returns an ASN.1 INTEGER value as an integer.

Returns:int

the integer held in this DER value.

getIntegerInternalback to summary
private int getIntegerInternal(byte expectedTag) throws IOException
getNullback to summary
public void getNull() throws IOException

Reads the ASN.1 NULL value

getOctetStringback to summary
public byte[] getOctetString() throws IOException

Returns an ASN.1 OCTET STRING

Returns:byte[]

the octet string held in this DER value

getOIDback to summary
public ObjectIdentifier getOID() throws IOException

Returns an ASN.1 OBJECT IDENTIFIER.

Returns:ObjectIdentifier

the OID held in this DER value

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

Returns:BigInteger

the integer held in this DER value as a BigInteger.

getPrintableStringback to summary
public String getPrintableString() throws IOException

Returns an ASN.1 STRING value

Returns:String

the printable string held in this value

getT61Stringback to summary
public String getT61String() throws IOException

Returns an ASN.1 T61 (Teletype) STRING value

Returns:String

the teletype string held in this value

getTagback to summary
public final byte getTag()
getTimeback to summary
public Date getTime() throws IOException

Determines whether Date was encoded as UTC or Generalized time and calls getUTCTime or getGeneralizedTime accordingly

getTimeInternalback to summary
private Date getTimeInternal(boolean generalized) throws IOException

Private helper routine to extract time from the der value.

Parameters
generalized:boolean

true if Generalized Time is to be read, false if UTC Time is to be read.

getUnalignedBitStringback to summary
public BitArray getUnalignedBitString() throws IOException

Returns an ASN.1 BIT STRING value that need not be byte-aligned.

Returns:BitArray

a BitArray representing the bit string held in this value

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

Parameters
tagImplicit:boolean

if true, the tag is assumed implicit.

Returns:BitArray

the bit string held in this value

getUniversalStringback to summary
public String getUniversalString() throws IOException

Returns the ASN.1 UNIVERSAL (UTF-32) STRING value as a Java String.

Returns:String

a string corresponding to the encoded UniversalString held in this value

getUTCTimeback to summary
public Date getUTCTime() throws IOException

Returns a Date if the DerValue is UtcTime.

Returns:Date

the Date held in this DER value

getUTF8Stringback to summary
public String getUTF8String() throws IOException

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

Returns:String

a string corresponding to the encoded UTF8String held in this value

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hashcode for this DerValue.

Returns:int

a hashcode for this DerValue

Annotations
@Override
isApplicationback to summary
public boolean isApplication()

Returns true if the tag class is APPLICATION.

isConstructedback to summary
public boolean isConstructed()

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

isConstructedback to summary
public boolean isConstructed(byte constructedTag)

Returns true iff the CONSTRUCTED TAG matches the passed tag.

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

isContextSpecificback to summary
public boolean isContextSpecific(byte cntxtTag)

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

isPrintableStringback to summary
private static boolean isPrintableString(String value)
isPrintableStringCharback 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).

isPrivateback to summary
pack-priv boolean isPrivate()
isUniversalback to summary
public boolean isUniversal()

Returns true if the tag class is UNIVERSAL.

lengthback to summary
public int length()

Get the length of the encoded value.

readStringInternalback to summary
private String readStringInternal(byte expectedTag, Charset cs) throws IOException
resetTagback 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.

Parameters
tag:byte

the tag value

string2bytesback to summary
private static byte[] string2bytes(byte stringTag, String value)
subsback to summary
public DerValue[] subs(byte expectedTag, int startLen) throws IOException

Reads the sub-values in a constructed DerValue.

Parameters
expectedTag:byte

the expected tag, or zero if we don't check. This is useful when this DerValue is IMPLICIT.

startLen:int

estimated number of sub-values

Returns:DerValue[]

the sub-values in an array

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

Returns:byte[]

DER-encoded value, including tag and length.

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

toDigitback to summary
private static int toDigit(byte b, String type) throws IOException

Converts byte (represented as a char) to int.

Exceptions
IOException:
if integer is not a valid digit in the specified radix (10)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a printable representation of the value.

Returns:String

printable representation of the value

Annotations
@Override
withTagback 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.

Parameters
newTag:byte

the new tag

Returns:DerValue

a new DerValue

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

Parameters
tag:byte

the tag

out:DerOutputStream

the DerOutputStream

Returns:DerValue

a new DerValue using out as its content

wrapback to summary
public static DerValue wrap(byte[] buf) throws IOException

Wraps a byte array as a single DerValue. Attention: no cloning is made.

Parameters
buf:byte[]

the byte array containing the DER-encoded datum

Returns:DerValue

a new DerValue

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

Parameters
buf:byte[]

the byte array containing the DER-encoded datum

offset:int

where the encoded datum starts inside buf

len:int

length of bytes to parse inside buf

Returns:DerValue

a new DerValue