Package org.bouncycastle.asn1
Class DLSequenceGenerator
- java.lang.Object
-
- org.bouncycastle.asn1.ASN1Generator
-
- org.bouncycastle.asn1.DLGenerator
-
- org.bouncycastle.asn1.DLSequenceGenerator
-
public class DLSequenceGenerator extends DLGenerator
A stream generator for definite-length SEQUENCEs. The caller commits to the total length of the SEQUENCE body up front; the header is written immediately and the body then streams throughgetRawOutputStream()/addObject(ASN1Encodable).close()verifies the body came out at exactly the promised length and throws anIOExceptionotherwise — by then the output is not usable, but every length mismatch is a caller arithmetic bug that must not pass silently.Unlike
DERSequenceGeneratornothing is buffered, so the body may exceed the size of a Java array; the trade-off is that the length has to be known before any content is produced.
-
-
Field Summary
-
Fields inherited from class org.bouncycastle.asn1.ASN1Generator
_out
-
-
Constructor Summary
Constructors Constructor Description DLSequenceGenerator(java.io.OutputStream out, int tagNo, boolean isExplicit, long bodyLength)Use the passed in stream as the target for the generator, writing out the header for a tagged definite-length constructed SEQUENCE (possibly implicit).DLSequenceGenerator(java.io.OutputStream out, long bodyLength)Use the passed in stream as the target for the generator, writing out the header for a definite-length constructed SEQUENCE.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObject(ASN1Encodable object)Add the DL encoding of the passed in object to the SEQUENCE body.voidclose()Verify the declared body length was written in full.java.io.OutputStreamgetRawOutputStream()Return the target stream for the SEQUENCE body.-
Methods inherited from class org.bouncycastle.asn1.DLGenerator
getDLEncodingLength, getLengthOctetCount, writeDLHeader
-
-
-
-
Constructor Detail
-
DLSequenceGenerator
public DLSequenceGenerator(java.io.OutputStream out, long bodyLength) throws java.io.IOExceptionUse the passed in stream as the target for the generator, writing out the header for a definite-length constructed SEQUENCE.- Parameters:
out- target streambodyLength- the exact number of content octets that will be written- Throws:
java.io.IOException- if the target stream cannot be written to.
-
DLSequenceGenerator
public DLSequenceGenerator(java.io.OutputStream out, int tagNo, boolean isExplicit, long bodyLength) throws java.io.IOExceptionUse the passed in stream as the target for the generator, writing out the header for a tagged definite-length constructed SEQUENCE (possibly implicit).- Parameters:
out- target streamtagNo- the tag number to introduceisExplicit- true if this is an explicitly tagged object, false otherwise.bodyLength- the exact number of content octets that will be written- Throws:
java.io.IOException- if the target stream cannot be written to.
-
-
Method Detail
-
getRawOutputStream
public java.io.OutputStream getRawOutputStream()
Return the target stream for the SEQUENCE body. Writes are counted against the length declared at construction; writing past it fails immediately.- Overrides:
getRawOutputStreamin classDLGenerator- Returns:
- the stream that is directly encoded to.
-
addObject
public void addObject(ASN1Encodable object) throws java.io.IOException
Add the DL encoding of the passed in object to the SEQUENCE body.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionVerify the declared body length was written in full.- Throws:
java.io.IOException- if fewer content octets were written than declared.
-
-