Bouncy Castle Cryptography Library 1.85

org.bouncycastle.asn1
Class DLOctetStringGenerator

java.lang.Object
  extended byorg.bouncycastle.asn1.ASN1Generator
      extended byorg.bouncycastle.asn1.DLGenerator
          extended byorg.bouncycastle.asn1.DLOctetStringGenerator

public class DLOctetStringGenerator
extends DLGenerator

A stream generator for definite-length (primitive) OCTET STRINGs. The caller commits to the octet count up front; the header is written immediately and the octets then stream through getOctetOutputStream(), which enforces the count — writing past it fails immediately, and close() fails if it was not reached. The count is a , so content larger than a Java array can carry is supported.

The result is a single primitive OCTET STRING (as DER requires), in contrast to BEROctetStringGenerator's indefinite-length constructed chunking.


Field Summary
 
Fields inherited from class org.bouncycastle.asn1.ASN1Generator
_out
 
Constructor Summary
DLOctetStringGenerator(java.io.OutputStream out, int tagNo, boolean isExplicit, long octetCount)
          Use the passed in stream as the target for the generator, writing out the header for a tagged definite-length OCTET STRING (primitive when implicit, per X.690 8.14.3).
DLOctetStringGenerator(java.io.OutputStream out, long octetCount)
          Use the passed in stream as the target for the generator, writing out the header for a definite-length primitive OCTET STRING.
 
Method Summary
 void close()
          Verify the declared octet count was written in full.
 java.io.OutputStream getOctetOutputStream()
          Return the content target for this OCTET STRING.
 
Methods inherited from class org.bouncycastle.asn1.DLGenerator
getDLEncodingLength, getLengthOctetCount, getRawOutputStream, writeDLHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DLOctetStringGenerator

public DLOctetStringGenerator(java.io.OutputStream out,
                              long octetCount)
                       throws java.io.IOException
Use the passed in stream as the target for the generator, writing out the header for a definite-length primitive OCTET STRING.

Parameters:
out - target stream
octetCount - the exact number of octets that will be written
Throws:
java.io.IOException - if the target stream cannot be written to.

DLOctetStringGenerator

public DLOctetStringGenerator(java.io.OutputStream out,
                              int tagNo,
                              boolean isExplicit,
                              long octetCount)
                       throws java.io.IOException
Use the passed in stream as the target for the generator, writing out the header for a tagged definite-length OCTET STRING (primitive when implicit, per X.690 8.14.3).

Parameters:
out - target stream
tagNo - the tag number to introduce
isExplicit - true if this is an explicitly tagged object, false otherwise.
octetCount - the exact number of octets that will be written
Throws:
java.io.IOException - if the target stream cannot be written to.
Method Detail

getOctetOutputStream

public java.io.OutputStream getOctetOutputStream()
Return the content target for this OCTET STRING. Writes are counted against the count declared at construction; writing past it fails immediately.


close

public void close()
           throws java.io.IOException
Verify the declared octet count was written in full.

Throws:
java.io.IOException - if fewer octets were written than declared.

Bouncy Castle Cryptography Library 1.85