11package org .bouncycastle .mail .smime ;
22
3- import org .bouncycastle .asn1 .ASN1EncodableVector ;
4- import org .bouncycastle .asn1 .ASN1ObjectIdentifier ;
5- import org .bouncycastle .cms .*;
6- import org .bouncycastle .operator .OutputAEADEncryptor ;
7- import org .bouncycastle .operator .OutputEncryptor ;
3+ import java .io .IOException ;
4+ import java .io .OutputStream ;
5+ import java .security .AccessController ;
6+ import java .security .PrivilegedAction ;
87
98import javax .activation .CommandMap ;
109import javax .activation .MailcapCommandMap ;
1110import javax .mail .MessagingException ;
1211import javax .mail .internet .MimeBodyPart ;
13- import java .io .IOException ;
14- import java .io .OutputStream ;
15- import java .security .AccessController ;
16- import java .security .PrivilegedAction ;
12+
13+ import org .bouncycastle .asn1 .ASN1EncodableVector ;
14+ import org .bouncycastle .asn1 .ASN1ObjectIdentifier ;
15+ import org .bouncycastle .cms .CMSAuthEnvelopedDataGenerator ;
16+ import org .bouncycastle .cms .CMSAuthEnvelopedDataStreamGenerator ;
17+ import org .bouncycastle .cms .CMSException ;
18+ import org .bouncycastle .cms .RecipientInfoGenerator ;
19+ import org .bouncycastle .operator .OutputAEADEncryptor ;
20+ import org .bouncycastle .operator .OutputEncryptor ;
1721
1822/**
1923 * General class for generating a pkcs7-mime message using AEAD algorithm.
20- *
24+ * <p>
2125 * A simple example of usage.
2226 *
2327 * <pre>
3438public class SMIMEAuthEnvelopedGenerator
3539 extends SMIMEEnvelopedGenerator
3640{
37- public static final String AES128_GCM = CMSAuthEnvelopedDataGenerator .AES128_GCM ;
38- public static final String AES192_GCM = CMSAuthEnvelopedDataGenerator .AES192_GCM ;
39- public static final String AES256_GCM = CMSAuthEnvelopedDataGenerator .AES256_GCM ;
41+ public static final String AES128_GCM = CMSAuthEnvelopedDataGenerator .AES128_GCM ;
42+ public static final String AES192_GCM = CMSAuthEnvelopedDataGenerator .AES192_GCM ;
43+ public static final String AES256_GCM = CMSAuthEnvelopedDataGenerator .AES256_GCM ;
4044
41- private static final String AUTH_ENCRYPTED_CONTENT_TYPE = "application/pkcs7-mime; name=\" smime.p7m\" ; smime-type=authEnveloped-data" ;
45+ static final String AUTH_ENVELOPED_DATA_CONTENT_TYPE = "application/pkcs7-mime; name=\" smime.p7m\" ; smime-type=authEnveloped-data" ;
4246
4347 final private AuthEnvelopedGenerator authFact ;
4448
@@ -90,19 +94,21 @@ public void setBerEncodeRecipients(
9094 /**
9195 * return encrypted content type for enveloped data.
9296 */
93- protected String getEncryptedContentType () {
94- return AUTH_ENCRYPTED_CONTENT_TYPE ;
97+ protected String getEncryptedContentType ()
98+ {
99+ return AUTH_ENVELOPED_DATA_CONTENT_TYPE ;
95100 }
96101
97102 /**
98103 * return content encryptor.
99104 */
100105 protected SMIMEStreamingProcessor getContentEncryptor (
101- MimeBodyPart content ,
102- OutputEncryptor encryptor )
103- throws SMIMEException
106+ MimeBodyPart content ,
107+ OutputEncryptor encryptor )
108+ throws SMIMEException
104109 {
105- if (encryptor instanceof OutputAEADEncryptor ) {
110+ if (encryptor instanceof OutputAEADEncryptor )
111+ {
106112 return new ContentEncryptor (content , (OutputAEADEncryptor )encryptor );
107113 }
108114 // this would happen if the encryption algorithm is not AEAD algorithm
@@ -113,12 +119,12 @@ private static class AuthEnvelopedGenerator
113119 extends CMSAuthEnvelopedDataStreamGenerator
114120 {
115121 private ASN1ObjectIdentifier dataType ;
116- private ASN1EncodableVector recipientInfos ;
122+ private ASN1EncodableVector recipientInfos ;
117123
118124 protected OutputStream open (
119125 ASN1ObjectIdentifier dataType ,
120- OutputStream out ,
121- ASN1EncodableVector recipientInfos ,
126+ OutputStream out ,
127+ ASN1EncodableVector recipientInfos ,
122128 OutputAEADEncryptor encryptor )
123129 throws IOException
124130 {
@@ -130,31 +136,31 @@ protected OutputStream open(
130136
131137 OutputStream regenerate (
132138 OutputStream out ,
133- OutputAEADEncryptor encryptor )
139+ OutputAEADEncryptor encryptor )
134140 throws IOException
135141 {
136142 return super .open (dataType , out , recipientInfos , encryptor );
137143 }
138144 }
139145
140146 private class ContentEncryptor
141- implements SMIMEStreamingProcessor
147+ implements SMIMEStreamingProcessor
142148 {
143149 private final MimeBodyPart _content ;
144150 private OutputAEADEncryptor _encryptor ;
145151
146152 private boolean _firstTime = true ;
147153
148154 ContentEncryptor (
149- MimeBodyPart content ,
150- OutputAEADEncryptor encryptor )
155+ MimeBodyPart content ,
156+ OutputAEADEncryptor encryptor )
151157 {
152158 _content = content ;
153159 _encryptor = encryptor ;
154160 }
155161
156162 public void write (OutputStream out )
157- throws IOException
163+ throws IOException
158164 {
159165 OutputStream encrypted ;
160166
0 commit comments