Package com.unboundid.asn1
Class ASN1Buffer
java.lang.Object
com.unboundid.asn1.ASN1Buffer
- All Implemented Interfaces:
Serializable
@Mutable
@ThreadSafety(level=NOT_THREADSAFE)
public final class ASN1Buffer
extends Object
implements Serializable
This class provides a mechanism for writing one or more ASN.1 elements into a
byte string buffer. It may be cleared and re-used any number of times, and
the contents may be written to an
OutputStream or ByteBuffer,
or copied to a byte array. ASN1Buffer instances are not threadsafe
and should not be accessed concurrently by multiple threads.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBoolean(boolean booleanValue) Adds a Boolean element to this ASN.1 buffer using the default BER type.voidaddBoolean(byte type, boolean booleanValue) Adds a Boolean element to this ASN.1 buffer using the provided BER type.voidaddElement(ASN1Element element) Adds the provided ASN.1 element to this ASN.1 buffer.voidaddEnumerated(byte type, int intValue) Adds an enumerated element to this ASN.1 buffer using the provided BER type.voidaddEnumerated(int intValue) Adds an enumerated element to this ASN.1 buffer using the default BER type.voidaddGeneralizedTime(byte type, long time) Adds a generalized time element to this ASN.1 buffer using the provided BER type.voidaddGeneralizedTime(byte type, Date date) Adds a generalized time element to this ASN.1 buffer using the provided BER type.voidaddGeneralizedTime(long time) Adds a generalized time element to this ASN.1 buffer using the default BER type.voidaddGeneralizedTime(Date date) Adds a generalized time element to this ASN.1 buffer using the default BER type.voidaddInteger(byte type, int intValue) Adds an integer element to this ASN.1 buffer using the provided BER type.voidaddInteger(byte type, long longValue) Adds an integer element to this ASN.1 buffer using the provided BER type.voidaddInteger(byte type, BigInteger value) Adds an integer element to this ASN.1 buffer using the provided BER type.voidaddInteger(int intValue) Adds an integer element to this ASN.1 buffer using the default BER type.voidaddInteger(long longValue) Adds an integer element to this ASN.1 buffer using the default BER type.voidaddInteger(BigInteger value) Adds an integer element to this ASN.1 buffer using the default BER type.voidaddNull()Adds a null element to this ASN.1 buffer using the default BER type.voidaddNull(byte type) Adds a null element to this ASN.1 buffer using the provided BER type.voidAdds an octet string element to this ASN.1 buffer using the default BER type and no value.voidaddOctetString(byte type) Adds an octet string element to this ASN.1 buffer using the provided BER type and no value.voidaddOctetString(byte[] value) Adds an octet string element to this ASN.1 buffer using the default BER type.voidaddOctetString(byte type, byte[] value) Adds an octet string element to this ASN.1 buffer using the provided BER type.voidaddOctetString(byte type, CharSequence value) Adds an octet string element to this ASN.1 buffer using the provided BER type.voidaddOctetString(byte type, String value) Adds an octet string element to this ASN.1 buffer using the provided BER type.voidaddOctetString(CharSequence value) Adds an octet string element to this ASN.1 buffer using the default BER type.voidaddOctetString(String value) Adds an octet string element to this ASN.1 buffer using the default BER type.voidaddUTCTime(byte type, long time) Adds a UTC time element to this ASN.1 buffer using the provided BER type.voidaddUTCTime(byte type, Date date) Adds a UTC time element to this ASN.1 buffer using the provided BER type.voidaddUTCTime(long time) Adds a UTC time element to this ASN.1 buffer using the default BER type.voidaddUTCTime(Date date) Adds a UTC time element to this ASN.1 buffer using the default BER type.Retrieves a byte buffer that wraps the data associated with this ASN.1 buffer.Begins adding elements to an ASN.1 sequence using the default BER type.beginSequence(byte type) Begins adding elements to an ASN.1 sequence using the provided BER type.beginSet()Begins adding elements to an ASN.1 set using the default BER type.beginSet(byte type) Begins adding elements to an ASN.1 set using the provided BER type.voidclear()Clears the contents of this buffer.intlength()Retrieves the current length of this buffer in bytes.voidSpecifies 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[]Retrieves a byte array containing the contents of this ASN.1 buffer.voidwriteTo(OutputStream outputStream) Writes the contents of this buffer to the provided output stream.booleanIndicates 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.
-
Constructor Details
-
ASN1Buffer
public ASN1Buffer()Creates a new instance of this ASN.1 buffer. -
ASN1Buffer
Creates a new instance of this ASN.1 buffer with an optional maximum retained size. If a maximum size is defined, then this buffer may be used to hold elements larger than that, but when the buffer is cleared it will be shrunk to the maximum size.- Parameters:
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.
-
-
Method Details
-
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.- Returns:
trueif the content of the buffer should be zeroed out the next time it is cleared, orfalseif not.
-
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. -
clear
Clears the contents of this buffer. If there are any outstanding sequences or sets that have been created but not closed, then they must no longer be used and any attempt to do so may yield unpredictable results. -
length
Retrieves the current length of this buffer in bytes.- Returns:
- The current length of this buffer in bytes.
-
addElement
Adds the provided ASN.1 element to this ASN.1 buffer.- Parameters:
element- The element to be added. It must not benull.
-
addBoolean
Adds a Boolean element to this ASN.1 buffer using the default BER type.- Parameters:
booleanValue- The value to use for the Boolean element.
-
addBoolean
Adds a Boolean element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the Boolean element.booleanValue- The value to use for the Boolean element.
-
addEnumerated
Adds an enumerated element to this ASN.1 buffer using the default BER type.- Parameters:
intValue- The value to use for the enumerated element.
-
addEnumerated
Adds an enumerated element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the enumerated element.intValue- The value to use for the enumerated element.
-
addGeneralizedTime
Adds a generalized time element to this ASN.1 buffer using the default BER type.- Parameters:
date- The date value that specifies the time to represent. This must not benull.
-
addGeneralizedTime
Adds a generalized time element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the generalized time element.date- The date value that specifies the time to represent. This must not benull.
-
addGeneralizedTime
Adds a generalized time element to this ASN.1 buffer using the default BER type.- Parameters:
time- The time to represent. This must be expressed in milliseconds since the epoch (the same format used bySystem.currentTimeMillis()andDate.getTime()).
-
addGeneralizedTime
Adds a generalized time element to this ASN.1 buffer using the provided BER type.- Parameters:
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 bySystem.currentTimeMillis()andDate.getTime()).
-
addInteger
Adds an integer element to this ASN.1 buffer using the default BER type.- Parameters:
intValue- The value to use for the integer element.
-
addInteger
Adds an integer element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the integer element.intValue- The value to use for the integer element.
-
addInteger
Adds an integer element to this ASN.1 buffer using the default BER type.- Parameters:
longValue- The value to use for the integer element.
-
addInteger
Adds an integer element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the integer element.longValue- The value to use for the integer element.
-
addInteger
Adds an integer element to this ASN.1 buffer using the default BER type.- Parameters:
value- The value to use for the integer element. It must not benull.
-
addInteger
Adds an integer element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the integer element.value- The value to use for the integer element. It must not benull.
-
addNull
Adds a null element to this ASN.1 buffer using the default BER type. -
addNull
Adds a null element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the null element.
-
addOctetString
Adds an octet string element to this ASN.1 buffer using the default BER type and no value. -
addOctetString
Adds an octet string element to this ASN.1 buffer using the provided BER type and no value.- Parameters:
type- The BER type to use for the octet string element.
-
addOctetString
Adds an octet string element to this ASN.1 buffer using the default BER type.- Parameters:
value- The value to use for the octet string element.
-
addOctetString
Adds an octet string element to this ASN.1 buffer using the default BER type.- Parameters:
value- The value to use for the octet string element.
-
addOctetString
Adds an octet string element to this ASN.1 buffer using the default BER type.- Parameters:
value- The value to use for the octet string element.
-
addOctetString
Adds an octet string element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the octet string element.value- The value to use for the octet string element.
-
addOctetString
Adds an octet string element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the octet string element.value- The value to use for the octet string element.
-
addOctetString
Adds an octet string element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the octet string element.value- The value to use for the octet string element.
-
addUTCTime
Adds a UTC time element to this ASN.1 buffer using the default BER type.- Parameters:
date- The date value that specifies the time to represent. This must not benull.
-
addUTCTime
Adds a UTC time element to this ASN.1 buffer using the provided BER type.- Parameters:
type- The BER type to use for the UTC time element.date- The date value that specifies the time to represent. This must not benull.
-
addUTCTime
Adds a UTC time element to this ASN.1 buffer using the default BER type.- Parameters:
time- The time to represent. This must be expressed in milliseconds since the epoch (the same format used bySystem.currentTimeMillis()andDate.getTime()).
-
addUTCTime
Adds a UTC time element to this ASN.1 buffer using the provided BER type.- Parameters:
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 bySystem.currentTimeMillis()andDate.getTime()).
-
beginSequence
Begins adding elements to an ASN.1 sequence using the default BER type.- Returns:
- An object that may be used to indicate when the end of the
sequence has been reached. Once all embedded sequence elements
have been added, then the
ASN1BufferSequence.end()method MUST be called to ensure that the sequence is properly encoded.
-
beginSequence
Begins adding elements to an ASN.1 sequence using the provided BER type.- Parameters:
type- The BER type to use for the sequence.- Returns:
- An object that may be used to indicate when the end of the
sequence has been reached. Once all embedded sequence elements
have been added, then the
ASN1BufferSequence.end()method MUST be called to ensure that the sequence is properly encoded.
-
beginSet
Begins adding elements to an ASN.1 set using the default BER type.- Returns:
- An object that may be used to indicate when the end of the set has
been reached. Once all embedded set elements have been added,
then the
ASN1BufferSet.end()method MUST be called to ensure that the set is properly encoded.
-
beginSet
Begins adding elements to an ASN.1 set using the provided BER type.- Parameters:
type- The BER type to use for the set.- Returns:
- An object that may be used to indicate when the end of the set has
been reached. Once all embedded set elements have been added,
then the
ASN1BufferSet.end()method MUST be called to ensure that the set is properly encoded.
-
writeTo
Writes the contents of this buffer to the provided output stream.- Parameters:
outputStream- The output stream to which the data should be written.- Throws:
IOException- If a problem occurs while writing to the provided output stream.
-
toByteArray
Retrieves a byte array containing the contents of this ASN.1 buffer.- Returns:
- A byte array containing the contents of this ASN.1 buffer.
-
asByteBuffer
Retrieves a byte buffer that wraps the data associated with this ASN.1 buffer. The position will be set to the beginning of the data, and the limit will be set to one byte after the end of the data. The contents of the returned byte buffer must not be altered in any way, and the contents of this ASN.1 buffer must not be altered until theByteBufferis no longer needed.- Returns:
- A byte buffer that wraps the data associated with this ASN.1 buffer.
-