@Mutable @ThreadSafety(level=NOT_THREADSAFE) public final class ASN1Buffer extends java.lang.Object implements java.io.Serializable
OutputStream
or ByteBuffer
,
or copied to a byte array. ASN1Buffer
instances are not threadsafe
and should not be accessed concurrently by multiple threads.Constructor and Description |
---|
ASN1Buffer()
Creates a new instance of this ASN.1 buffer.
|
ASN1Buffer(int maxBufferSize)
Creates a new instance of this ASN.1 buffer with an optional maximum
retained size.
|
Modifier and Type | Method and Description |
---|---|
void |
addBoolean(boolean booleanValue)
Adds a Boolean element to this ASN.1 buffer using the default BER type.
|
void |
addBoolean(byte type,
boolean booleanValue)
Adds a Boolean element to this ASN.1 buffer using the provided BER type.
|
void |
addElement(ASN1Element element)
Adds the provided ASN.1 element to this ASN.1 buffer.
|
void |
addEnumerated(byte type,
int intValue)
Adds an enumerated element to this ASN.1 buffer using the provided BER
type.
|
void |
addEnumerated(int intValue)
Adds an enumerated element to this ASN.1 buffer using the default BER type.
|
void |
addGeneralizedTime(byte type,
java.util.Date date)
Adds a generalized time element to this ASN.1 buffer using the provided BER
type.
|
void |
addGeneralizedTime(byte type,
long time)
Adds a generalized time element to this ASN.1 buffer using the provided BER
type.
|
void |
addGeneralizedTime(java.util.Date date)
Adds a generalized time element to this ASN.1 buffer using the default BER
type.
|
void |
addGeneralizedTime(long time)
Adds a generalized time element to this ASN.1 buffer using the default BER
type.
|
void |
addInteger(java.math.BigInteger value)
Adds an integer element to this ASN.1 buffer using the default BER type.
|
void |
addInteger(byte type,
java.math.BigInteger value)
Adds an integer element to this ASN.1 buffer using the provided BER type.
|
void |
addInteger(byte type,
int intValue)
Adds an integer element to this ASN.1 buffer using the provided BER type.
|
void |
addInteger(byte type,
long longValue)
Adds an integer element to this ASN.1 buffer using the provided BER type.
|
void |
addInteger(int intValue)
Adds an integer element to this ASN.1 buffer using the default BER type.
|
void |
addInteger(long longValue)
Adds an integer element to this ASN.1 buffer using the default BER type.
|
void |
addNull()
Adds a null element to this ASN.1 buffer using the default BER type.
|
void |
addNull(byte type)
Adds a null element to this ASN.1 buffer using the provided BER type.
|
void |
addOctetString()
Adds an octet string element to this ASN.1 buffer using the default BER
type and no value.
|
void |
addOctetString(byte type)
Adds an octet string element to this ASN.1 buffer using the provided BER
type and no value.
|
void |
addOctetString(byte[] value)
Adds an octet string element to this ASN.1 buffer using the default BER
type.
|
void |
addOctetString(byte type,
byte[] value)
Adds an octet string element to this ASN.1 buffer using the provided BER
type.
|
void |
addOctetString(byte type,
java.lang.CharSequence value)
Adds an octet string element to this ASN.1 buffer using the provided BER
type.
|
void |
addOctetString(byte type,
java.lang.String value)
Adds an octet string element to this ASN.1 buffer using the provided BER
type.
|
void |
addOctetString(java.lang.CharSequence value)
Adds an octet string element to this ASN.1 buffer using the default BER
type.
|
void |
addOctetString(java.lang.String value)
Adds an octet string element to this ASN.1 buffer using the default BER
type.
|
void |
addUTCTime(byte type,
java.util.Date date)
Adds a UTC time element to this ASN.1 buffer using the provided BER type.
|
void |
addUTCTime(byte type,
long time)
Adds a UTC time element to this ASN.1 buffer using the provided BER type.
|
void |
addUTCTime(java.util.Date date)
Adds a UTC time element to this ASN.1 buffer using the default BER type.
|
void |
addUTCTime(long time)
Adds a UTC time element to this ASN.1 buffer using the default BER type.
|
java.nio.ByteBuffer |
asByteBuffer()
Retrieves a byte buffer that wraps the data associated with this ASN.1
buffer.
|
ASN1BufferSequence |
beginSequence()
Begins adding elements to an ASN.1 sequence using the default BER type.
|
ASN1BufferSequence |
beginSequence(byte type)
Begins adding elements to an ASN.1 sequence using the provided BER type.
|
ASN1BufferSet |
beginSet()
Begins adding elements to an ASN.1 set using the default BER type.
|
ASN1BufferSet |
beginSet(byte type)
Begins adding elements to an ASN.1 set using the provided BER type.
|
void |
clear()
Clears the contents of this buffer.
|
int |
length()
Retrieves the current length of this buffer in bytes.
|
void |
setZeroBufferOnClear()
Specifies that the content of the buffer should be zeroed out the next time
it is cleared in order to wipe any sensitive information it may contain.
|
byte[] |
toByteArray()
Retrieves a byte array containing the contents of this ASN.1 buffer.
|
void |
writeTo(java.io.OutputStream outputStream)
Writes the contents of this buffer to the provided output stream.
|
boolean |
zeroBufferOnClear()
Indicates whether the content of the buffer should be zeroed out the next
time it is cleared in order to wipe any sensitive information it may
contain.
|
public ASN1Buffer()
public ASN1Buffer(int maxBufferSize)
maxBufferSize
- The maximum buffer size that will be retained by
this ASN.1 buffer. A value less than or equal to
zero indicates that no maximum size should be
enforced.public boolean zeroBufferOnClear()
true
if the content of the buffer should be zeroed out the
next time it is cleared, or false
if not.public void setZeroBufferOnClear()
public void clear()
public int length()
public void addElement(@NotNull ASN1Element element)
element
- The element to be added. It must not be null
.public void addBoolean(boolean booleanValue)
booleanValue
- The value to use for the Boolean element.public void addBoolean(byte type, boolean booleanValue)
type
- The BER type to use for the Boolean element.booleanValue
- The value to use for the Boolean element.public void addEnumerated(int intValue)
intValue
- The value to use for the enumerated element.public void addEnumerated(byte type, int intValue)
type
- The BER type to use for the enumerated element.intValue
- The value to use for the enumerated element.public void addGeneralizedTime(@NotNull java.util.Date date)
date
- The date value that specifies the time to represent. This
must not be null
.public void addGeneralizedTime(byte type, @NotNull java.util.Date date)
type
- The BER type to use for the generalized time element.date
- The date value that specifies the time to represent. This
must not be null
.public void addGeneralizedTime(long time)
time
- The time to represent. This must be expressed in
milliseconds since the epoch (the same format used by
System.currentTimeMillis()
and
Date.getTime()
).public void addGeneralizedTime(byte type, long time)
type
- The BER type to use for the generalized time element.time
- The time to represent. This must be expressed in
milliseconds since the epoch (the same format used by
System.currentTimeMillis()
and
Date.getTime()
).public void addInteger(int intValue)
intValue
- The value to use for the integer element.public void addInteger(byte type, int intValue)
type
- The BER type to use for the integer element.intValue
- The value to use for the integer element.public void addInteger(long longValue)
longValue
- The value to use for the integer element.public void addInteger(byte type, long longValue)
type
- The BER type to use for the integer element.longValue
- The value to use for the integer element.public void addInteger(@NotNull java.math.BigInteger value)
value
- The value to use for the integer element. It must not be
null
.public void addInteger(byte type, @NotNull java.math.BigInteger value)
type
- The BER type to use for the integer element.value
- The value to use for the integer element. It must not be
null
.public void addNull()
public void addNull(byte type)
type
- The BER type to use for the null element.public void addOctetString()
public void addOctetString(byte type)
type
- The BER type to use for the octet string element.public void addOctetString(@Nullable byte[] value)
value
- The value to use for the octet string element.public void addOctetString(@Nullable java.lang.CharSequence value)
value
- The value to use for the octet string element.public void addOctetString(@Nullable java.lang.String value)
value
- The value to use for the octet string element.public void addOctetString(byte type, @Nullable byte[] value)
type
- The BER type to use for the octet string element.value
- The value to use for the octet string element.public void addOctetString(byte type, @Nullable java.lang.CharSequence value)
type
- The BER type to use for the octet string element.value
- The value to use for the octet string element.public void addOctetString(byte type, @Nullable java.lang.String value)
type
- The BER type to use for the octet string element.value
- The value to use for the octet string element.public void addUTCTime(@NotNull java.util.Date date)
date
- The date value that specifies the time to represent. This
must not be null
.public void addUTCTime(byte type, @NotNull java.util.Date date)
type
- The BER type to use for the UTC time element.date
- The date value that specifies the time to represent. This
must not be null
.public void addUTCTime(long time)
time
- The time to represent. This must be expressed in
milliseconds since the epoch (the same format used by
System.currentTimeMillis()
and
Date.getTime()
).public void addUTCTime(byte type, long time)
type
- The BER type to use for the UTC time element.time
- The time to represent. This must be expressed in
milliseconds since the epoch (the same format used by
System.currentTimeMillis()
and
Date.getTime()
).@NotNull public ASN1BufferSequence beginSequence()
ASN1BufferSequence.end()
method
MUST be called to ensure that the sequence is properly encoded.@NotNull public ASN1BufferSequence beginSequence(byte type)
type
- The BER type to use for the sequence.ASN1BufferSequence.end()
method
MUST be called to ensure that the sequence is properly encoded.@NotNull public ASN1BufferSet beginSet()
ASN1BufferSet.end()
method MUST be called to ensure
that the set is properly encoded.@NotNull public ASN1BufferSet beginSet(byte type)
type
- The BER type to use for the set.ASN1BufferSet.end()
method MUST be called to ensure
that the set is properly encoded.public void writeTo(@NotNull java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- The output stream to which the data should be
written.java.io.IOException
- If a problem occurs while writing to the provided
output stream.@NotNull public byte[] toByteArray()
@NotNull public java.nio.ByteBuffer asByteBuffer()
ByteBuffer
is no longer needed.