Skip to content

Commit aa379f3

Browse files
committed
Merge branch '2133-javadoc-cms-streams' into 'main'
Add java doc for CMSAuthEnvelopedDataParser and CMSAuthEnvelopedDataStreamGenerator See merge request root/bc-java!116
2 parents bd60123 + 1f78028 commit aa379f3

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

pkix/src/main/java/org/bouncycastle/cms/CMSAuthEnvelopedDataParser.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
2222
import org.bouncycastle.util.Arrays;
2323

24+
/**
25+
* Parser for authenticated enveloped CMS data structures.
26+
* <p>
27+
* Important usage notes:
28+
* <ul>
29+
* <li>The constructor <b>fully drains and closes</b> the provided InputStream</li>
30+
* <li>Plaintext content is buffered in memory and available via {@code RecipientInformation}</li>
31+
* <li>Do not reuse the input stream after parsing</li>
32+
* </ul>
33+
*/
2434
public class CMSAuthEnvelopedDataParser
2535
extends CMSContentInfoParser
2636
{
@@ -36,13 +46,29 @@ public class CMSAuthEnvelopedDataParser
3646
private boolean unauthAttrNotRead;
3747
private OriginatorInformation originatorInfo;
3848

49+
/**
50+
* Create a parser from a byte array.
51+
* <p>
52+
* <b>Note:</b> The input is fully consumed during parsing. Plaintext content is buffered in memory.
53+
*
54+
* @param envelopedData the CMS auth enveloped data bytes
55+
*/
3956
public CMSAuthEnvelopedDataParser(
4057
byte[] envelopedData)
4158
throws CMSException, IOException
4259
{
4360
this(new ByteArrayInputStream(envelopedData));
4461
}
4562

63+
/**
64+
* Create a parser from an input stream.
65+
* <p>
66+
* <b>Stream handling note:</b> This constructor fully reads and <b>closes the input stream</b>
67+
* before returning. The plaintext content is buffered in memory and accessible via
68+
* {@link RecipientInformation#getContentStream}.
69+
*
70+
* @param envelopedData the CMS auth enveloped data stream
71+
*/
4672
public CMSAuthEnvelopedDataParser(
4773
InputStream envelopedData)
4874
throws CMSException, IOException

pkix/src/main/java/org/bouncycastle/cms/CMSAuthEnvelopedDataStreamGenerator.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
1616
import org.bouncycastle.operator.OutputAEADEncryptor;
1717

18+
/**
19+
* Generate authenticated enveloped CMS data with streaming support.
20+
* <p>
21+
* When using this generator, note:
22+
* <ul>
23+
* <li>The returned OutputStream must be closed to finalize encryption and authentication</li>
24+
* <li>Closing the returned stream <b>does not close</b> the underlying OutputStream passed to {@code open()}</li>
25+
* <li>Callers are responsible for closing the underlying OutputStream separately</li>
26+
* </ul>
27+
*/
1828
public class CMSAuthEnvelopedDataStreamGenerator
1929
extends CMSAuthEnvelopedGenerator
2030
{
@@ -113,10 +123,16 @@ protected OutputStream open(
113123
}
114124
}
115125

116-
117126
/**
118-
* generate an enveloped object that contains an CMS Enveloped Data
119-
* object using the given encryptor.
127+
* generate an enveloped object that contains an CMS Enveloped Data object using the given encryptor.
128+
* <p>
129+
* <b>Stream handling note:</b> Closing the returned stream finalizes the CMS structure but
130+
* <b>does not close</b> the underlying output stream. The caller remains responsible for
131+
* managing the lifecycle of {@code out}.
132+
*
133+
* @param out the output stream to write the CMS structure to
134+
* @param encryptor the cipher to use for encryption
135+
* @return an output stream that writes encrypted and authenticated content
120136
*/
121137
public OutputStream open(
122138
OutputStream out,

0 commit comments

Comments
 (0)