Canonicalize line endings for text messages (#86)
* Canonicalize line endings for text messages * Improve cleartext messages
This commit is contained in:
parent
a4d89bce32
commit
ce607e0fa8
6 changed files with 25 additions and 25 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"io/ioutil"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/armor"
|
||||
"github.com/ProtonMail/gopenpgp/v2/constants"
|
||||
|
|
@ -86,7 +87,7 @@ func NewPlainMessageFromFile(data []byte, filename string, time uint32) *PlainMe
|
|||
// ready for encryption, signature, or verification from an unencrypted string.
|
||||
func NewPlainMessageFromString(text string) *PlainMessage {
|
||||
return &PlainMessage{
|
||||
Data: []byte(text),
|
||||
Data: []byte(strings.ReplaceAll(strings.ReplaceAll(text, "\r\n", "\n"), "\n", "\r\n")),
|
||||
TextType: true,
|
||||
time: uint32(GetUnixTime()),
|
||||
}
|
||||
|
|
@ -195,7 +196,7 @@ func (msg *PlainMessage) GetBinary() []byte {
|
|||
|
||||
// GetString returns the content of the message as a string.
|
||||
func (msg *PlainMessage) GetString() string {
|
||||
return string(msg.Data)
|
||||
return strings.ReplaceAll(string(msg.Data), "\r\n", "\n")
|
||||
}
|
||||
|
||||
// GetBase64 returns the base-64 encoded binary content of the message as a
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func (keyRing *KeyRing) DecryptMIMEMessage(
|
|||
return
|
||||
}
|
||||
|
||||
body, attachments, attachmentHeaders, err := parseMIME(decryptedMessage.GetString(), verifyKey)
|
||||
body, attachments, attachmentHeaders, err := parseMIME(string(decryptedMessage.GetBinary()), verifyKey)
|
||||
if err != nil {
|
||||
callbacks.OnError(err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ func TestVerifyTextDetachedSigWrong(t *testing.T) {
|
|||
func TestSignBinDetached(t *testing.T) {
|
||||
var err error
|
||||
|
||||
binSignature, err = keyRingTestPrivate.SignDetached(NewPlainMessage([]byte(signedPlainText)))
|
||||
message = NewPlainMessage([]byte(signedPlainText))
|
||||
binSignature, err = keyRingTestPrivate.SignDetached(message)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot generate signature:", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue