public class

DerOutputStream

extends ByteArrayOutputStream
implements DerEncoder
java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.ByteArrayOutputStream
       ↳ sun.security.util.DerOutputStream

Class Overview

Output stream marshaling DER-encoded data. This is eventually provided in the form of a byte array; there is no advance limit on the size of that byte array.

At this time, this class supports only a subset of the types of DER data encodings which are defined. That subset is sufficient for generating most X.509 certificates.

Summary

[Expand]
Inherited Fields
From class java.io.ByteArrayOutputStream
Public Constructors
DerOutputStream(int size)
Construct an DER output stream.
DerOutputStream()
Construct an DER output stream.
Public Methods
void derEncode(OutputStream out)
Write the current contents of this DerOutputStream to an OutputStream.
void putBMPString(String s)
Marshals a string as a DER encoded BMPString.
void putBitString(byte[] bits)
Marshals a DER bit string on the output stream.
void putBoolean(boolean val)
Marshals a DER boolean on the output stream.
void putDerValue(DerValue val)
Marshals pre-encoded DER value onto the output stream.
void putEnumerated(int i)
Marshals a DER enumerated on the output stream.
void putGeneralString(String s)
Marshals a string as a DER encoded GeneralString.
void putGeneralizedTime(Date d)
Marshals a DER Generalized Time/date value.
void putIA5String(String s)
Marshals a string as a DER encoded IA5String.
void putInteger(Integer i)
Marshals a DER integer on the output stream.
void putInteger(int i)
Marshals a DER integer on the output stream.
void putInteger(BigInteger i)
Marshals a DER integer on the output stream.
void putLength(int len)
Put the encoding of the length in the stream.
void putNull()
Marshals a DER "null" value on the output stream.
void putOID(ObjectIdentifier oid)
Marshals an object identifier (OID) on the output stream.
void putOctetString(byte[] octets)
DER-encodes an ASN.1 OCTET STRING value on the output stream.
void putOrderedSet(byte tag, DerEncoder[] set)
Marshals the contents of a set on the output stream.
void putOrderedSetOf(byte tag, DerEncoder[] set)
Marshals the contents of a set on the output stream.
void putPrintableString(String s)
Marshals a string as a DER encoded PrintableString.
void putSequence(DerValue[] seq)
Marshals a sequence on the output stream.
void putSet(DerValue[] set)
Marshals the contents of a set on the output stream without ordering the elements.
void putT61String(String s)
Marshals a string as a DER encoded T61String.
void putTag(byte tagClass, boolean form, byte val)
Put the tag of the attribute in the stream.
void putTruncatedUnalignedBitString(BitArray ba)
Marshals a truncated DER bit string on the output stream.
void putUTCTime(Date d)
Marshals a DER UTC time/date value.
void putUTF8String(String s)
Marshals a string as a DER encoded UTF8String.
void putUnalignedBitString(BitArray ba)
Marshals a DER bit string on the output stream.
void write(byte tag, DerOutputStream out)
Writes tagged data using buffer-to-buffer copy.
void write(byte tag, byte[] buf)
Writes tagged, pre-marshaled data.
void writeImplicit(byte tag, DerOutputStream value)
Writes implicitly tagged data using buffer-to-buffer copy.
[Expand]
Inherited Methods
From class java.io.ByteArrayOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface sun.security.util.DerEncoder

Public Constructors

public DerOutputStream (int size)

Construct an DER output stream.

Parameters
size how large a buffer to preallocate.

public DerOutputStream ()

Construct an DER output stream.

Public Methods

public void derEncode (OutputStream out)

Write the current contents of this DerOutputStream to an OutputStream.

Parameters
out the stream on which the DER encoding is written.
Throws
IOException on output error.

public void putBMPString (String s)

Marshals a string as a DER encoded BMPString.

Throws
IOException

public void putBitString (byte[] bits)

Marshals a DER bit string on the output stream. The bit string must be byte-aligned.

Parameters
bits the bit string, MSB first
Throws
IOException

public void putBoolean (boolean val)

Marshals a DER boolean on the output stream.

Throws
IOException

public void putDerValue (DerValue val)

Marshals pre-encoded DER value onto the output stream.

Throws
IOException

public void putEnumerated (int i)

Marshals a DER enumerated on the output stream.

Parameters
i the enumerated value.
Throws
IOException

public void putGeneralString (String s)

Marshals a string as a DER encoded GeneralString.

Throws
IOException

public void putGeneralizedTime (Date d)

Marshals a DER Generalized Time/date value.

YYYYMMDDhhmmss{Z|+hhmm|-hhmm} ... emits only using Zulu time and with seconds (even if seconds=0) as per RFC 3280.

Throws
IOException

public void putIA5String (String s)

Marshals a string as a DER encoded IA5String.

Throws
IOException

public void putInteger (Integer i)

Marshals a DER integer on the output stream.

Parameters
i the integer in the form of an Integer.
Throws
IOException

public void putInteger (int i)

Marshals a DER integer on the output stream.

Parameters
i the integer.
Throws
IOException

public void putInteger (BigInteger i)

Marshals a DER integer on the output stream.

Parameters
i the integer in the form of a BigInteger.
Throws
IOException

public void putLength (int len)

Put the encoding of the length in the stream.

Throws
IOException on writing errors.

public void putNull ()

Marshals a DER "null" value on the output stream. These are often used to indicate optional values which have been omitted.

Throws
IOException

public void putOID (ObjectIdentifier oid)

Marshals an object identifier (OID) on the output stream. Corresponds to the ASN.1 "OBJECT IDENTIFIER" construct.

Throws
IOException

public void putOctetString (byte[] octets)

DER-encodes an ASN.1 OCTET STRING value on the output stream.

Parameters
octets the octet string
Throws
IOException

public void putOrderedSet (byte tag, DerEncoder[] set)

Marshals the contents of a set on the output stream. Sets are semantically unordered, but DER requires that encodings of set elements be sorted into ascending tag order before being output. Hence sets with the same tags and elements have the same DER encoding. This method supports the ASN.1 "SET" construct, but not "SET OF", which uses a different order.

Throws
IOException

public void putOrderedSetOf (byte tag, DerEncoder[] set)

Marshals the contents of a set on the output stream. Sets are semantically unordered, but DER requires that encodings of set elements be sorted into ascending lexicographical order before being output. Hence sets with the same tags and elements have the same DER encoding. This method supports the ASN.1 "SET OF" construct, but not "SET", which uses a different order.

Throws
IOException

public void putPrintableString (String s)

Marshals a string as a DER encoded PrintableString.

Throws
IOException

public void putSequence (DerValue[] seq)

Marshals a sequence on the output stream. This supports both the ASN.1 "SEQUENCE" (zero to N values) and "SEQUENCE OF" (one to N values) constructs.

Throws
IOException

public void putSet (DerValue[] set)

Marshals the contents of a set on the output stream without ordering the elements. Ok for BER encoding, but not for DER encoding. For DER encoding, use orderedPutSet() or orderedPutSetOf().

Throws
IOException

public void putT61String (String s)

Marshals a string as a DER encoded T61String.

Throws
IOException

public void putTag (byte tagClass, boolean form, byte val)

Put the tag of the attribute in the stream.

public void putTruncatedUnalignedBitString (BitArray ba)

Marshals a truncated DER bit string on the output stream. The bit strings need not be byte-aligned.

Throws
IOException

public void putUTCTime (Date d)

Marshals a DER UTC time/date value.

YYMMDDhhmmss{Z|+hhmm|-hhmm} ... emits only using Zulu time and with seconds (even if seconds=0) as per RFC 3280.

Throws
IOException

public void putUTF8String (String s)

Marshals a string as a DER encoded UTF8String.

Throws
IOException

public void putUnalignedBitString (BitArray ba)

Marshals a DER bit string on the output stream. The bit strings need not be byte-aligned.

Throws
IOException

public void write (byte tag, DerOutputStream out)

Writes tagged data using buffer-to-buffer copy. As above, this writes a standard DER record. This is often used when efficiently encapsulating values in sequences.

Parameters
tag the DER value tag for the data, such as DerValue.tag_Sequence
out buffered data
Throws
IOException

public void write (byte tag, byte[] buf)

Writes tagged, pre-marshaled data. This calcuates and encodes the length, so that the output data is the standard triple of { tag, length, data } used by all DER values.

Parameters
tag the DER value tag for the data, such as DerValue.tag_Sequence
buf buffered data, which must be DER-encoded
Throws
IOException

public void writeImplicit (byte tag, DerOutputStream value)

Writes implicitly tagged data using buffer-to-buffer copy. As above, this writes a standard DER record. This is often used when efficiently encapsulating implicitly tagged values.

Parameters
tag the DER value of the context-specific tag that replaces original tag of the value in the output, such as in
            [N] IMPLICIT 
 
For example, FooLength [1] IMPLICIT INTEGER, with value=4; would be encoded as "81 01 04" whereas in explicit tagging it would be encoded as "A1 03 02 01 04". Notice that the tag is A1 and not 81, this is because with explicit tagging the form is always constructed.
value original value being implicitly tagged
Throws
IOException