Skip to content

Commit

Permalink
fix(GODT-1224): Do not strip trailing whitespace for ClearScheme but …
Browse files Browse the repository at this point in the history
…for all others.
  • Loading branch information
rlejeune74 committed Oct 30, 2023
1 parent 8fc2478 commit dbfd133
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions message_send_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func newMIMEPackage(
mimeBody string,
prefs map[string]SendPreferences,
) (*MessagePackage, error) {
decBodyKey, encBodyData, err := encSplit(kr, mimeBody)
decBodyKey, encBodyData, err := encSplit(kr, mimeBody, true)
if err != nil {
return nil, fmt.Errorf("failed to encrypt MIME body: %w", err)
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func newTextPackage(
return nil, fmt.Errorf("invalid MIME type for package: %s", mimeType)
}

decBodyKey, encBodyData, err := encSplit(kr, body)
decBodyKey, encBodyData, err := encSplit(kr, body, true)
if err != nil {
return nil, fmt.Errorf("failed to encrypt message body: %w", err)
}
Expand Down Expand Up @@ -304,22 +304,13 @@ func newClearSignedPackage(
prefs map[string]SendPreferences,
attKeys map[string]*crypto.SessionKey,
) (*MessagePackage, error) {
encBody, err := kr.Encrypt(crypto.NewPlainMessage([]byte(body)), kr)
if err != nil {
return nil, fmt.Errorf("failed to encrypt MIME body: %w", err)
}

splitEncBody, err := encBody.SplitMessage()
if err != nil {
return nil, fmt.Errorf("failed to split message: %w", err)
}

decBodyKey, err := kr.DecryptSessionKey(splitEncBody.GetBinaryKeyPacket())
decBodyKey, encBodyData, err := encSplit(kr, body, false)
if err != nil {
return nil, fmt.Errorf("failed to decrypt session key: %w", err)
return nil, fmt.Errorf("failed to encrypt message body: %w", err)
}

pkg := newMessagePackage(rfc822.TextPlain, splitEncBody.GetBinaryDataPacket())
pkg := newMessagePackage(rfc822.TextPlain, encBodyData)

for addr, prefs := range prefs {
if prefs.MIMEType != rfc822.TextPlain {
Expand Down Expand Up @@ -353,10 +344,20 @@ func newClearSignedPackage(
return pkg, nil
}

func encSplit(kr *crypto.KeyRing, body string) (*crypto.SessionKey, []byte, error) {
encBody, err := kr.Encrypt(crypto.NewPlainMessage([]byte(body)), kr)
if err != nil {
return nil, nil, fmt.Errorf("failed to encrypt MIME body: %w", err)
func encSplit(kr *crypto.KeyRing, body string, stripSpaces bool) (*crypto.SessionKey, []byte, error) {
var encBody *crypto.PGPMessage
if stripSpaces {
enc, err := kr.Encrypt(crypto.NewPlainMessage([]byte(body)), kr)
if err != nil {
return nil, nil, fmt.Errorf("failed to encrypt MIME body: %w", err)
}
encBody = enc
} else {
enc, err := kr.Encrypt(crypto.NewPlainMessageFromString(body), kr)
if err != nil {
return nil, nil, fmt.Errorf("failed to encrypt MIME body: %w", err)
}
encBody = enc
}

splitEncBody, err := encBody.SplitMessage()
Expand Down

0 comments on commit dbfd133

Please sign in to comment.