@@ -237,14 +237,8 @@ func (eh *encryptionHandle) encryptStreamWithSessionKeyHelper(
237
237
return nil , nil , fmt .Errorf ("gopenpgp: unable to encrypt: %w" , err )
238
238
}
239
239
240
- if algo := config .Compression (); algo != packet .CompressionNone {
241
- encryptWriter , err = packet .SerializeCompressed (encryptWriter , algo , config .CompressionConfig )
242
- if err != nil {
243
- return nil , nil , fmt .Errorf ("gopenpgp: error in compression: %w" , err )
244
- }
245
- }
246
-
247
240
if signers != nil {
241
+ // SignWithParams handles compression.
248
242
signWriter , err = openpgp .SignWithParams (encryptWriter , signers , & openpgp.SignParams {
249
243
Hints : hints ,
250
244
TextSig : eh .IsUTF8 ,
@@ -255,6 +249,13 @@ func (eh *encryptionHandle) encryptStreamWithSessionKeyHelper(
255
249
return nil , nil , fmt .Errorf ("gopenpgp: unable to sign: %w" , err )
256
250
}
257
251
} else {
252
+ // We need to handle compression outside of go-crypto.
253
+ if algo := config .Compression (); algo != packet .CompressionNone {
254
+ encryptWriter , err = packet .SerializeCompressed (encryptWriter , algo , config .CompressionConfig )
255
+ if err != nil {
256
+ return nil , nil , fmt .Errorf ("gopenpgp: error in compression: %w" , err )
257
+ }
258
+ }
258
259
encryptWriter , err = packet .SerializeLiteral (
259
260
encryptWriter ,
260
261
! plainMessageMetadata .IsUtf8 (),
0 commit comments