@NotExtensible @NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public class ASN1Element extends java.lang.Object implements java.io.Serializable
Constructor and Description |
---|
ASN1Element(byte type)
Creates a new ASN.1 BER element with the specified type and no value.
|
ASN1Element(byte type,
byte[] value)
Creates a new ASN1 BER element with the specified type and value.
|
ASN1Element(byte type,
byte[] value,
int offset,
int length)
Creates a new ASN1 BER element with the specified type and value.
|
Modifier and Type | Method and Description |
---|---|
static ASN1Element |
decode(byte[] elementBytes)
Decodes the content in the provided byte array as an ASN.1 element.
|
ASN1BigInteger |
decodeAsBigInteger()
Decodes this ASN.1 element as a big integer element.
|
ASN1BitString |
decodeAsBitString()
Decodes this ASN.1 element as a bit string element.
|
ASN1Boolean |
decodeAsBoolean()
Decodes this ASN.1 element as a Boolean element.
|
ASN1Enumerated |
decodeAsEnumerated()
Decodes this ASN.1 element as an enumerated element.
|
ASN1GeneralizedTime |
decodeAsGeneralizedTime()
Decodes this ASN.1 element as a generalized time element.
|
ASN1IA5String |
decodeAsIA5String()
Decodes this ASN.1 element as an IA5 string element.
|
ASN1Integer |
decodeAsInteger()
Decodes this ASN.1 element as an integer element.
|
ASN1Long |
decodeAsLong()
Decodes this ASN.1 element as a long element.
|
ASN1Null |
decodeAsNull()
Decodes this ASN.1 element as a null element.
|
ASN1NumericString |
decodeAsNumericString()
Decodes this ASN.1 element as a numeric string element.
|
ASN1ObjectIdentifier |
decodeAsObjectIdentifier()
Decodes this ASN.1 element as an object identifier element.
|
ASN1OctetString |
decodeAsOctetString()
Decodes this ASN.1 element as an octet string element.
|
ASN1PrintableString |
decodeAsPrintableString()
Decodes this ASN.1 element as a printable string element.
|
ASN1Sequence |
decodeAsSequence()
Decodes this ASN.1 element as a sequence element.
|
ASN1Set |
decodeAsSet()
Decodes this ASN.1 element as a set element.
|
ASN1UTCTime |
decodeAsUTCTime()
Decodes this ASN.1 element as a UTC time element.
|
ASN1UTF8String |
decodeAsUTF8String()
Decodes this ASN.1 element as a UTF-8 string element.
|
byte[] |
encode()
Encodes this ASN.1 element to a byte array.
|
static byte[] |
encodeLength(int length)
Encodes the provided length to a byte array.
|
void |
encodeTo(ByteStringBuffer buffer)
Appends an encoded representation of this ASN.1 element to the provided
buffer.
|
boolean |
equals(java.lang.Object o)
Indicates whether the provided object is equal to this ASN.1 BER element.
|
boolean |
equalsIgnoreType(ASN1Element element)
Indicates whether the provided ASN.1 element is equal to this element,
ignoring any potential difference in the BER type.
|
byte |
getType()
Retrieves the BER type for this element.
|
byte |
getTypeClass()
Retrieves a value that corresponds to the type class for this element.
|
byte[] |
getValue()
Retrieves the encoded value for this element.
|
int |
getValueLength()
Retrieves the number of bytes contained in the value.
|
int |
hashCode()
Retrieves a hash code for this ASN.1 BER element.
|
boolean |
isConstructed()
Indicates whether the type indicates that this element is constructed.
|
static ASN1Element |
readFrom(java.io.InputStream inputStream)
Reads an ASN.1 element from the provided input stream.
|
static ASN1Element |
readFrom(java.io.InputStream inputStream,
int maxSize)
Reads an ASN.1 element from the provided input stream.
|
java.lang.String |
toString()
Retrieves a string representation of the value for ASN.1 element.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of the value for this ASN.1 element to the
provided buffer.
|
int |
writeTo(java.io.OutputStream outputStream)
Writes an encoded representation of this ASN.1 element to the provided
output stream.
|
public ASN1Element(byte type)
type
- The BER type for this element.public ASN1Element(byte type, @Nullable byte[] value)
type
- The BER type for this element.value
- The encoded value for this element.public ASN1Element(byte type, @NotNull byte[] value, int offset, int length)
type
- The BER type for this element.value
- The array containing the encoded value for this element.
It must not be null
.offset
- The offset within the array at which the value begins.length
- The number of bytes contained in the value.public final byte getType()
public byte getTypeClass()
ASN1Constants.TYPE_MASK_UNIVERSAL_CLASS
,
ASN1Constants.TYPE_MASK_APPLICATION_CLASS
,
ASN1Constants.TYPE_MASK_CONTEXT_SPECIFIC_CLASS
, or
ASN1Constants.TYPE_MASK_PRIVATE_CLASS
.public boolean isConstructed()
true
if the type indicates that the element is
constructed, or false
if the type indicates that the
element is primitive.public int getValueLength()
@NotNull public byte[] getValue()
@NotNull public final byte[] encode()
public void encodeTo(@NotNull ByteStringBuffer buffer)
buffer
- The buffer to which the encoded representation should be
appended.@NotNull public static byte[] encodeLength(int length)
length
- The length to be encoded.@NotNull public static ASN1Element decode(@NotNull byte[] elementBytes) throws ASN1Exception
elementBytes
- The byte array containing the data to decode.ASN1Exception
- If the provided byte array does not represent a
valid ASN.1 element.@NotNull public final ASN1BitString decodeAsBitString() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a bit string
element.@NotNull public final ASN1Boolean decodeAsBoolean() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a Boolean
element.@NotNull public final ASN1Enumerated decodeAsEnumerated() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as an enumerated
element.@NotNull public final ASN1GeneralizedTime decodeAsGeneralizedTime() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a generalized
time element.@NotNull public final ASN1IA5String decodeAsIA5String() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a IA5 string
element.@NotNull public final ASN1Integer decodeAsInteger() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as an integer
element.@NotNull public final ASN1Long decodeAsLong() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a long
element.@NotNull public final ASN1BigInteger decodeAsBigInteger() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a big integer
element.@NotNull public final ASN1Null decodeAsNull() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a null
element.@NotNull public final ASN1NumericString decodeAsNumericString() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a numeric
string element.@NotNull public final ASN1ObjectIdentifier decodeAsObjectIdentifier() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as an object
identifier element.@NotNull public final ASN1OctetString decodeAsOctetString()
@NotNull public final ASN1PrintableString decodeAsPrintableString() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a printable
string element.@NotNull public final ASN1Sequence decodeAsSequence() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a sequence
element.@NotNull public final ASN1Set decodeAsSet() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a set
element.@NotNull public final ASN1UTCTime decodeAsUTCTime() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a UTC time
element.@NotNull public final ASN1UTF8String decodeAsUTF8String() throws ASN1Exception
ASN1Exception
- If this element cannot be decoded as a UTF-8
string element.@Nullable public static ASN1Element readFrom(@NotNull java.io.InputStream inputStream) throws java.io.IOException, ASN1Exception
inputStream
- The input stream from which to read the element.null
if the end
of the input stream is reached without reading any data.java.io.IOException
- If a problem occurs while attempting to read from the
input stream.ASN1Exception
- If a problem occurs while attempting to decode the
element.@Nullable public static ASN1Element readFrom(@NotNull java.io.InputStream inputStream, int maxSize) throws java.io.IOException, ASN1Exception
inputStream
- The input stream from which to read the element.maxSize
- The maximum value size in bytes that will be allowed.
A value less than or equal to zero indicates that no
maximum size should be enforced. An attempt to read
an element with a value larger than this will cause an
ASN1Exception
to be thrown.null
if the end
of the input stream is reached without reading any data.java.io.IOException
- If a problem occurs while attempting to read from the
input stream.ASN1Exception
- If a problem occurs while attempting to decode the
element.public final int writeTo(@NotNull java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- The output stream to which the element should be
written.java.io.IOException
- If a problem occurs while attempting to write to the
provided output stream.ASN1Writer.writeElement(ASN1Element,OutputStream)
public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(@Nullable java.lang.Object o)
equals
in class java.lang.Object
o
- The object for which to make the determination.true
if the provided object is considered equal to this
ASN.1 element, or false
if not.public final boolean equalsIgnoreType(@Nullable ASN1Element element)
element
- The ASN.1 BER element for which to make the determination.true
if the provided ASN.1 element is considered equal to
this element (ignoring type differences), or false
if not.@NotNull public final java.lang.String toString()
toString
in class java.lang.Object