Package org.bouncycastle.asn1
Class DLGenerator
- java.lang.Object
-
- org.bouncycastle.asn1.ASN1Generator
-
- org.bouncycastle.asn1.DLGenerator
-
- Direct Known Subclasses:
DLOctetStringGenerator,DLSequenceGenerator
public abstract class DLGenerator extends ASN1Generator
Base class for stream generators for definite-length structures. Unlike theBER generators, which stream indefinite-length encodings, these write a definite-length header up front from a caller-supplied body length and so can stream DL (and, with suitably canonical contents, DER) encodings of structures too large to hold in memory — body lengths arelong, so content larger than a Java array can carry is supported.The body length passed to a generator is a commitment: the matching number of content octets must subsequently be written. Subclasses verify this on
close()and fail with anIOExceptionon a mismatch, since a wrongly-sized body silently corrupts every enclosing length.
-
-
Field Summary
-
Fields inherited from class org.bouncycastle.asn1.ASN1Generator
_out
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDLGenerator(java.io.OutputStream out)protectedDLGenerator(java.io.OutputStream out, int tagNo, boolean isExplicit)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static longgetDLEncodingLength(long bodyLength)Return the total encoded length of a TLV with a single identifier octet (i.e. a tag number below 31) andbodyLengthcontent octets.static intgetLengthOctetCount(long bodyLength)Return the number of octets in the definite-length encoding ofbodyLength(the length octets only, excluding the identifier).java.io.OutputStreamgetRawOutputStream()Return the actual stream object encodings are written to.protected voidwriteDLHeader(int tag, long bodyLength)Write the definite-length header(s) for this generator's structure: the base tag withbodyLength, preceded (for an explicit tag) by a context-specific wrapper whose length covers the complete base TLV.
-
-
-
Method Detail
-
getRawOutputStream
public java.io.OutputStream getRawOutputStream()
Description copied from class:ASN1GeneratorReturn the actual stream object encodings are written to.- Specified by:
getRawOutputStreamin classASN1Generator- Returns:
- the stream that is directly encoded to.
-
getLengthOctetCount
public static int getLengthOctetCount(long bodyLength)
Return the number of octets in the definite-length encoding ofbodyLength(the length octets only, excluding the identifier).- Parameters:
bodyLength- number of content octets (>= 0)- Returns:
- 1 for the short form, 1 + number of length octets for the long form
-
getDLEncodingLength
public static long getDLEncodingLength(long bodyLength)
Return the total encoded length of a TLV with a single identifier octet (i.e. a tag number below 31) andbodyLengthcontent octets.- Parameters:
bodyLength- number of content octets (>= 0)
-
writeDLHeader
protected void writeDLHeader(int tag, long bodyLength) throws java.io.IOExceptionWrite the definite-length header(s) for this generator's structure: the base tag withbodyLength, preceded (for an explicit tag) by a context-specific wrapper whose length covers the complete base TLV. Tag numbers of 31 and above are supported for the context-specific wrapper of an implicitly tagged structure, but not for an explicit one (the wrapper length arithmetic assumes a single identifier octet).- Throws:
java.io.IOException
-
-