@@ -62,6 +62,8 @@ type encryptionHandle struct {
6262
6363 encryptionTimeOverride Clock
6464 clock Clock
65+
66+ messageSizeHint int
6567}
6668
6769// --- Default decryption handle to build from
@@ -74,6 +76,13 @@ func defaultEncryptionHandle(profile EncryptionProfile, clock Clock) *encryption
7476}
7577
7678// --- Implements PGPEncryption interface
79+ // SetMessageSizeHint gives the encryption handle a hint about the
80+ // expected size of the message, in order to set an appropriate chunk
81+ // size when using AEAD. Nothing will break when the message size hint
82+ // turns out to be wrong.
83+ func (eh * encryptionHandle ) SetMessageSizeHint (messageSizeHint int ) {
84+ eh .messageSizeHint = messageSizeHint
85+ }
7786
7887// EncryptingWriter returns a wrapper around underlying output Writer,
7988// such that any write-operation via the wrapper results in a write to an encrypted pgp message.
@@ -95,6 +104,7 @@ func (eh *encryptionHandle) EncryptingWriter(outputWriter Writer, encoding int8)
95104
96105// Encrypt encrypts a plaintext message.
97106func (eh * encryptionHandle ) Encrypt (message []byte ) (* PGPMessage , error ) {
107+ eh .messageSizeHint = len (message )
98108 pgpMessageBuffer := NewPGPMessageBuffer ()
99109 // Enforce that for a PGPMessage struct the output should not be armored.
100110 encryptingWriter , err := eh .EncryptingWriter (pgpMessageBuffer , Bytes )
@@ -116,7 +126,7 @@ func (eh *encryptionHandle) Encrypt(message []byte) (*PGPMessage, error) {
116126// EncryptSessionKey encrypts a session key with the encryption handle.
117127// To encrypt a session key, the handle must contain either recipients or a password.
118128func (eh * encryptionHandle ) EncryptSessionKey (sessionKey * SessionKey ) ([]byte , error ) {
119- config := eh .profile .EncryptionConfig ()
129+ config := eh .profile .EncryptionConfig (0 )
120130 config .Time = NewConstantClock (eh .clock ().Unix ())
121131 switch {
122132 case eh .Password != nil :
@@ -159,7 +169,7 @@ func (eh *encryptionHandle) armorChecksumRequired() bool {
159169 // the logic for the RFC9580 check.
160170 return false
161171 }
162- encryptionConfig := eh .profile .EncryptionConfig ()
172+ encryptionConfig := eh .profile .EncryptionConfig (0 )
163173 if encryptionConfig .AEADConfig == nil {
164174 return true
165175 }
0 commit comments