Skip to content

Commit b6d5bd9

Browse files
committed
Add CMSAuthEnvelopedDataStreamGenerator.open taking a dataType
- remove redundant override in CMSAuthEnvelopedGenerator - see #2221
1 parent da8984b commit b6d5bd9

File tree

3 files changed

+30
-48
lines changed

3 files changed

+30
-48
lines changed

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ public void setBEREncodeRecipients(
5656
_berEncodeRecipientSet = berEncodeRecipientSet;
5757
}
5858

59-
private OutputStream doOpen(
60-
ASN1ObjectIdentifier dataType,
61-
OutputStream out,
62-
OutputAEADEncryptor encryptor)
63-
throws IOException, CMSException
64-
{
65-
ASN1EncodableVector recipientInfos = CMSUtils.getRecipentInfos(encryptor.getKey(), recipientInfoGenerators);
66-
67-
return open(dataType, out, recipientInfos, encryptor);
68-
}
69-
7059
protected OutputStream open(
7160
ASN1ObjectIdentifier dataType,
7261
OutputStream out,
@@ -123,22 +112,41 @@ protected OutputStream open(
123112
}
124113

125114
/**
126-
* generate an enveloped object that contains an CMS Enveloped Data object using the given encryptor.
115+
* Generate authenticated-enveloped-data using the given encryptor, and marking the encapsulated
116+
* bytes as being of type DATA.
117+
* <p>
118+
* <b>Stream handling note:</b> Closing the returned stream finalizes the CMS structure but <b>does
119+
* not close</b> the underlying output stream. The caller remains responsible for managing the
120+
* lifecycle of {@code out}.
121+
*
122+
* @param out the output stream to write the CMS structure to
123+
* @param encryptor the cipher to use for encryption
124+
* @return an output stream that writes encrypted and authenticated content
125+
*/
126+
public OutputStream open(OutputStream out, OutputAEADEncryptor encryptor) throws CMSException, IOException
127+
{
128+
return open(CMSObjectIdentifiers.data, out, encryptor);
129+
}
130+
131+
/**
132+
* Generate authenticated-enveloped-data using the given encryptor, and marking the encapsulated
133+
* bytes as being of the passed in type.
127134
* <p>
128135
* <b>Stream handling note:</b> Closing the returned stream finalizes the CMS structure but
129136
* <b>does not close</b> the underlying output stream. The caller remains responsible for
130137
* managing the lifecycle of {@code out}.
131138
*
139+
* @param dataType the type of the data being written to the object.
132140
* @param out the output stream to write the CMS structure to
133141
* @param encryptor the cipher to use for encryption
134142
* @return an output stream that writes encrypted and authenticated content
135143
*/
136-
public OutputStream open(
137-
OutputStream out,
138-
OutputAEADEncryptor encryptor)
144+
public OutputStream open(ASN1ObjectIdentifier dataType, OutputStream out, OutputAEADEncryptor encryptor)
139145
throws CMSException, IOException
140146
{
141-
return doOpen(CMSObjectIdentifiers.data, out, encryptor);
147+
ASN1EncodableVector recipientInfos = CMSUtils.getRecipentInfos(encryptor.getKey(), recipientInfoGenerators);
148+
149+
return open(dataType, out, recipientInfos, encryptor);
142150
}
143151

144152
private class CMSAuthEnvelopedDataOutputStream

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,4 @@ public void setOriginatorInfo(OriginatorInformation originatorInfo)
4343
{
4444
this.originatorInfo = originatorInfo.toASN1Structure();
4545
}
46-
47-
/**
48-
* Add a generator to produce the recipient info required.
49-
*
50-
* @param recipientGenerator a generator of a recipient info object.
51-
*/
52-
public void addRecipientInfoGenerator(RecipientInfoGenerator recipientGenerator)
53-
{
54-
recipientInfoGenerators.add(recipientGenerator);
55-
}
5646
}

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.IOException;
44
import java.io.OutputStream;
5-
import java.util.Collections;
65

76
import org.bouncycastle.asn1.ASN1EncodableVector;
87
import org.bouncycastle.asn1.ASN1Integer;
@@ -77,17 +76,6 @@ private ASN1Integer getVersion(ASN1EncodableVector recipientInfos)
7776
return new ASN1Integer(EnvelopedData.calculateVersion(originatorInfo, new DLSet(recipientInfos), null));
7877
}
7978

80-
private OutputStream doOpen(
81-
ASN1ObjectIdentifier dataType,
82-
OutputStream out,
83-
OutputEncryptor encryptor)
84-
throws IOException, CMSException
85-
{
86-
ASN1EncodableVector recipientInfos = CMSUtils.getRecipentInfos(encryptor.getKey(), recipientInfoGenerators);
87-
88-
return open(dataType, out, recipientInfos, encryptor);
89-
}
90-
9179
protected OutputStream open(
9280
ASN1ObjectIdentifier dataType,
9381
OutputStream out,
@@ -147,26 +135,22 @@ protected OutputStream open(
147135
* generate an enveloped object that contains an CMS Enveloped Data
148136
* object using the given encryptor.
149137
*/
150-
public OutputStream open(
151-
OutputStream out,
152-
OutputEncryptor encryptor)
153-
throws CMSException, IOException
138+
public OutputStream open(OutputStream out, OutputEncryptor encryptor) throws CMSException, IOException
154139
{
155-
return doOpen(CMSObjectIdentifiers.data, out, encryptor);
140+
return open(CMSObjectIdentifiers.data, out, encryptor);
156141
}
157142

158143
/**
159144
* generate an enveloped object that contains an CMS Enveloped Data
160145
* object using the given encryptor and marking the data as being of the passed
161146
* in type.
162147
*/
163-
public OutputStream open(
164-
ASN1ObjectIdentifier dataType,
165-
OutputStream out,
166-
OutputEncryptor encryptor)
148+
public OutputStream open(ASN1ObjectIdentifier dataType, OutputStream out, OutputEncryptor encryptor)
167149
throws CMSException, IOException
168150
{
169-
return doOpen(dataType, out, encryptor);
151+
ASN1EncodableVector recipientInfos = CMSUtils.getRecipentInfos(encryptor.getKey(), recipientInfoGenerators);
152+
153+
return open(dataType, out, recipientInfos, encryptor);
170154
}
171155

172156
private class CmsEnvelopedDataOutputStream

0 commit comments

Comments
 (0)