protonmail: add cipherFunctionString

This commit is contained in:
emersion 2018-10-21 14:05:26 +02:00
parent 6f5f315be9
commit 905b9e170b
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 15 additions and 2 deletions

View File

@ -35,7 +35,7 @@ type Address struct {
Receive int
Status AddressStatus
Type AddressType
Order int
Order int64
DisplayName string
Signature string // HTML
HasKeys int

View File

@ -491,6 +491,19 @@ func (set *MessagePackageSet) Encrypt(mimeType string, signed *openpgp.Entity) (
}, nil
}
func cipherFunctionString(cipherFunc packet.CipherFunction) string {
switch cipherFunc {
case packet.CipherAES128:
return "aes128"
case packet.CipherAES192:
return "aes192"
case packet.CipherAES256:
return "aes256"
default:
panic("protonmail: unsupported cipher function")
}
}
func (set *MessagePackageSet) AddCleartext(addr string) (*MessagePackage, error) {
pkg := &MessagePackage{
Type: MessagePackageCleartext,
@ -501,7 +514,7 @@ func (set *MessagePackageSet) AddCleartext(addr string) (*MessagePackage, error)
if set.BodyKey == nil || set.AttachmentKeys == nil {
set.BodyKey = &MessageBodyKey{
Algorithm: "aes256",
Algorithm: cipherFunctionString(set.bodyKey.CipherFunc),
Key: base64.StdEncoding.EncodeToString(set.bodyKey.Key),
}