Top Description Fields Constructors Methods
sun.security.util

public final Class DerOutputStream

extends ByteArrayOutputStream
implements DerEncoder
Class Inheritance
All Implemented Interfaces
sun.security.util.DerEncoder
Imports
java.io.ByteArrayOutputStream, java.math.BigInteger, java.nio.charset.Charset, java.text.SimpleDateFormat, java.util.Date, .TimeZone, .Comparator, .Arrays, .Locale

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.

Authors
David Brownell, Amit Kapoor, Hemma Prafullchandra

Field Summary

Modifier and TypeField and Description
private static final ByteArrayLexOrder
lexOrder

Lexicographical order comparison on byte arrays, for ordering elements of a SET OF objects in DER encoding.

private static final ByteArrayTagOrder
tagOrder

Tag order comparison on byte arrays, for ordering elements of SET objects in DER encoding.

private static final Date
utcHigh

12/31/2049 is the highest date that RFC 2630 serializes to UTC time

private static final Date
utcLow

1/1/1950 is the lowest date that RFC 2630 serializes to UTC time

Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
public
DerOutputStream(int
how large a buffer to preallocate.
size
)

Construct a DER output stream.

public
DerOutputStream()

Construct a DER output stream.

Method Summary

Modifier and TypeMethod and Description
pack-priv byte[]
buf()

public void
encode(DerOutputStream
the stream on which the DER encoding is written.
out
)

Implements sun.security.util.DerEncoder.encode.

Write the current contents of this DerOutputStream to an OutputStream.

public DerOutputStream
putBitString(byte[]
the bit string, MSB first
bits
)

Marshals a DER bit string on the output stream.

public DerOutputStream
putBMPString(String s)

Marshals a string as a DER encoded BMPString.

public DerOutputStream
putBoolean(boolean val)

Marshals a DER boolean on the output stream.

public DerOutputStream
putDerValue(DerValue val)

Marshals pre-encoded DER value onto the output stream.

public DerOutputStream
putEnumerated(int
the enumerated value.
i
)

Marshals a DER enumerated on the output stream.

public DerOutputStream
putGeneralizedTime(Date d)

Marshals a DER Generalized Time/date value.

public DerOutputStream
putGeneralString(String s)

Marshals a string as a DER encoded GeneralString.

public DerOutputStream
putIA5String(String s)

Marshals a string as a DER encoded IA5String.

public DerOutputStream
putInteger(BigInteger
the integer in the form of a BigInteger.
i
)

Marshals a DER integer on the output stream.

public DerOutputStream
putInteger(byte[]
the integer in bytes, equivalent to BigInteger::toByteArray.
buf
)

Marshals a DER integer on the output stream.

public DerOutputStream
putInteger(Integer
the integer in the form of an Integer.
i
)

Marshals a DER integer on the output stream.

public DerOutputStream
putInteger(int
the integer.
i
)

Marshals a DER integer on the output stream.

private void
public void
putLength(int
the length of the attribute.
len
)

Put the encoding of the length in the stream.

public DerOutputStream
putNull()

Marshals a DER "null" value on the output stream.

public DerOutputStream
putOctetString(byte[]
the octet string
octets
)

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

public DerOutputStream
putOID(ObjectIdentifier oid)

Marshals an object identifier (OID) on the output stream.

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

Marshals the contents of a set on the output stream.

private DerOutputStream
putOrderedSet(byte tag, DerEncoder[] set, Comparator<byte[]>
the order to use when sorting encodings of components.
order
)

Marshals the contents of a set on the output stream with the encoding of elements sorted in increasing order.

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

Marshals the contents of a set on the output stream.

public DerOutputStream
putPrintableString(String s)

Marshals a string as a DER encoded PrintableString.

public DerOutputStream
putSequence(DerValue[] seq)

Marshals a sequence on the output stream.

public DerOutputStream
putSet(DerValue[] set)

Marshals the contents of a set on the output stream without ordering the elements.

public DerOutputStream
putT61String(String s)

Marshals a string as a DER encoded T61String.

public DerOutputStream
putTime(Date d)

Takes a Date and chooses UTC or GeneralizedTime as per RFC 2630

private DerOutputStream
putTime(Date
the date to be marshalled
d
,
byte
the tag for UTC Time or Generalized Time
tag
)

Private helper routine for marshalling a DER UTC/Generalized time/date value.

public DerOutputStream
putTruncatedUnalignedBitString(BitArray
the bit string, MSB first
ba
)

Marshals a truncated DER bit string on the output stream.

public DerOutputStream
putUnalignedBitString(BitArray
the bit string, MSB first
ba
)

Marshals a DER bit string on the output stream.

public DerOutputStream
putUTCTime(Date d)

Marshals a DER UTC time/date value.

public DerOutputStream
putUTF8String(String s)

Marshals a string as a DER encoded UTF8String.

public DerOutputStream
write(byte
the DER value tag for the data, such as DerValue.tag_Sequence
tag
,
byte[]
buffered data, which must be DER-encoded
buf
)

Writes tagged, pre-marshaled data.

public DerOutputStream
write(byte
the DER value tag for the data, such as DerValue.tag_Sequence
tag
,
DerOutputStream
buffered data
out
)

Writes tagged data using buffer-to-buffer copy.

public DerOutputStream
write(DerEncoder
the DerEncoder
encoder
)

Write a DerEncoder onto the output stream.

public DerOutputStream
writeImplicit(byte
the DER value of the context-specific tag that replaces original tag of the value in the output, such as in
          <field> [N] IMPLICIT <type>
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.
tag
,
DerOutputStream
original value being implicitly tagged
value
)

Writes implicitly tagged data using buffer-to-buffer copy.

private DerOutputStream
writeString(String
the string to write
s
,
byte
one of the DER string tags that indicate which encoding should be used to write the string out.
stringTag
,
Charset
the charset that should be used corresponding to the above tag.
charset
)

Private helper routine for writing DER encoded string values.

Inherited from java.io.ByteArrayOutputStream:
closeresetsizetoByteArraytoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Field Detail

lexOrderback to summary
private static final ByteArrayLexOrder lexOrder

Lexicographical order comparison on byte arrays, for ordering elements of a SET OF objects in DER encoding.

tagOrderback to summary
private static final ByteArrayTagOrder tagOrder

Tag order comparison on byte arrays, for ordering elements of SET objects in DER encoding.

utcHighback to summary
private static final Date utcHigh

12/31/2049 is the highest date that RFC 2630 serializes to UTC time

utcLowback to summary
private static final Date utcLow

1/1/1950 is the lowest date that RFC 2630 serializes to UTC time

Constructor Detail

DerOutputStreamback to summary
public DerOutputStream(int size)

Construct a DER output stream.

Parameters
size:int

how large a buffer to preallocate.

DerOutputStreamback to summary
public DerOutputStream()

Construct a DER output stream.

Method Detail

bufback to summary
pack-priv byte[] buf()
encodeback to summary
public void encode(DerOutputStream out)

Implements sun.security.util.DerEncoder.encode.

Write the current contents of this DerOutputStream to an OutputStream.

Parameters
out:DerOutputStream

Doc from sun.security.util.DerEncoder.encode.

the stream on which the DER encoding is written.

Annotations
@Override
putBitStringback to summary
public DerOutputStream putBitString(byte[] bits)

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

Parameters
bits:byte[]

the bit string, MSB first

putBMPStringback to summary
public DerOutputStream putBMPString(String s)

Marshals a string as a DER encoded BMPString.

putBooleanback to summary
public DerOutputStream putBoolean(boolean val)

Marshals a DER boolean on the output stream.

putDerValueback to summary
public DerOutputStream putDerValue(DerValue val)

Marshals pre-encoded DER value onto the output stream.

putEnumeratedback to summary
public DerOutputStream putEnumerated(int i)

Marshals a DER enumerated on the output stream.

Parameters
i:int

the enumerated value.

putGeneralizedTimeback to summary
public DerOutputStream 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 5280.

putGeneralStringback to summary
public DerOutputStream putGeneralString(String s)

Marshals a string as a DER encoded GeneralString.

putIA5Stringback to summary
public DerOutputStream putIA5String(String s)

Marshals a string as a DER encoded IA5String.

putIntegerback to summary
public DerOutputStream putInteger(BigInteger i)

Marshals a DER integer on the output stream.

Parameters
i:BigInteger

the integer in the form of a BigInteger.

putIntegerback to summary
public DerOutputStream putInteger(byte[] buf)

Marshals a DER integer on the output stream.

Parameters
buf:byte[]

the integer in bytes, equivalent to BigInteger::toByteArray.

putIntegerback to summary
public DerOutputStream putInteger(Integer i)

Marshals a DER integer on the output stream.

Parameters
i:Integer

the integer in the form of an Integer.

putIntegerback to summary
public DerOutputStream putInteger(int i)

Marshals a DER integer on the output stream.

Parameters
i:int

the integer.

putIntegerContentsback to summary
private void putIntegerContents(int i)
putLengthback to summary
public void putLength(int len)

Put the encoding of the length in the stream.

Parameters
len:int

the length of the attribute.

putNullback to summary
public DerOutputStream putNull()

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

putOctetStringback to summary
public DerOutputStream putOctetString(byte[] octets)

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

Parameters
octets:byte[]

the octet string

putOIDback to summary
public DerOutputStream putOID(ObjectIdentifier oid)

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

putOrderedSetback to summary
public DerOutputStream 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.

putOrderedSetback to summary
private DerOutputStream putOrderedSet(byte tag, DerEncoder[] set, Comparator<byte[]> order)

Marshals the contents of a set on the output stream with the encoding of elements sorted in increasing order.

Parameters
order:Comparator<byte[]>

the order to use when sorting encodings of components.

putOrderedSetOfback to summary
public DerOutputStream 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.

putPrintableStringback to summary
public DerOutputStream putPrintableString(String s)

Marshals a string as a DER encoded PrintableString.

putSequenceback to summary
public DerOutputStream 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.

putSetback to summary
public DerOutputStream 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().

putT61Stringback to summary
public DerOutputStream putT61String(String s)

Marshals a string as a DER encoded T61String.

putTimeback to summary
public DerOutputStream putTime(Date d)

Takes a Date and chooses UTC or GeneralizedTime as per RFC 2630

putTimeback to summary
private DerOutputStream putTime(Date d, byte tag)

Private helper routine for marshalling a DER UTC/Generalized time/date value. If the tag specified is not that for UTC Time then it defaults to Generalized Time.

Parameters
d:Date

the date to be marshalled

tag:byte

the tag for UTC Time or Generalized Time

putTruncatedUnalignedBitStringback to summary
public DerOutputStream putTruncatedUnalignedBitString(BitArray ba)

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

Parameters
ba:BitArray

the bit string, MSB first

putUnalignedBitStringback to summary
public DerOutputStream putUnalignedBitString(BitArray ba)

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

Parameters
ba:BitArray

the bit string, MSB first

putUTCTimeback to summary
public DerOutputStream 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 5280.

putUTF8Stringback to summary
public DerOutputStream putUTF8String(String s)

Marshals a string as a DER encoded UTF8String.

writeback to summary
public DerOutputStream write(byte tag, byte[] buf)

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

Parameters
tag:byte

the DER value tag for the data, such as DerValue.tag_Sequence

buf:byte[]

buffered data, which must be DER-encoded

writeback to summary
public DerOutputStream 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:byte

the DER value tag for the data, such as DerValue.tag_Sequence

out:DerOutputStream

buffered data

writeback to summary
public DerOutputStream write(DerEncoder encoder)

Write a DerEncoder onto the output stream.

Parameters
encoder:DerEncoder

the DerEncoder

writeImplicitback to summary
public DerOutputStream 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:byte

the DER value of the context-specific tag that replaces original tag of the value in the output, such as in

          <field> [N] IMPLICIT <type>
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:DerOutputStream

original value being implicitly tagged

writeStringback to summary
private DerOutputStream writeString(String s, byte stringTag, Charset charset)

Private helper routine for writing DER encoded string values.

Parameters
s:String

the string to write

stringTag:byte

one of the DER string tags that indicate which encoding should be used to write the string out.

charset:Charset

the charset that should be used corresponding to the above tag.