diff --git a/crypto/attachment_test.go b/crypto/attachment_test.go index 2b9f8ab..056c447 100644 --- a/crypto/attachment_test.go +++ b/crypto/attachment_test.go @@ -17,7 +17,7 @@ dille. const testAttachmentEncrypted = `0ksB0fHC6Duezx/0TqpK/82HSl8+qCY0c2BCuyrSFoj6Dubd93T3//32jVYa624NYvfvxX+UxFKYKJxG09gFsU1IVc87cWvUgmUmgjU=` -func TestAttachment_GetKey(t *testing.T) { +func TestAttachmentGetKey(t *testing.T) { split, err := SeparateKeyAndData(testPrivateKeyRing, strings.NewReader(testKeyPackets), len(testKeyPackets), -1) if err != nil { t.Fatal("Expected no error while decrypting attachment key, got:", err) @@ -28,8 +28,7 @@ func TestAttachment_GetKey(t *testing.T) { } } -func TestAttachment_SetKey(t *testing.T) { - +func TestAttachmentSetKey(t *testing.T) { var packets string var err error @@ -48,7 +47,7 @@ func TestAttachment_SetKey(t *testing.T) { } } -func TestAttachnent_EncryptDecrypt(t *testing.T) { +func TestAttachnentEncryptDecrypt(t *testing.T) { plainData, _ := base64.StdEncoding.DecodeString(testAttachmentCleartext) var pmCrypto = PmCrypto{} @@ -66,7 +65,7 @@ func TestAttachnent_EncryptDecrypt(t *testing.T) { s := string(redecData) if testAttachmentCleartext != s { - t.Fatalf("Invalid decrypted attachment: expected %v, got %v", testAttachmentCleartext, s) + t.Fatalf("Invalid decrypted attachment: expected\n%v\ngot\n%v", testAttachmentCleartext, s) } } diff --git a/crypto/mime.go b/crypto/mime.go index 21386be..68c8532 100644 --- a/crypto/mime.go +++ b/crypto/mime.go @@ -2,16 +2,18 @@ package crypto import ( "bytes" - "github.com/ProtonMail/go-pm-mime" - "golang.org/x/crypto/openpgp/packet" "io/ioutil" "net/mail" "net/textproto" "strings" + + pmmime "github.com/ProtonMail/go-pm-mime" + + "golang.org/x/crypto/openpgp" + "golang.org/x/crypto/openpgp/packet" ) func (pm PmCrypto) parseMIME(mimeBody string, verifierKey *KeyRing) (*pmmime.BodyCollector, int, []string, []string, error) { - mm, err := mail.ReadMessage(strings.NewReader(mimeBody)) if err != nil { return nil, 0, nil, nil, err @@ -25,10 +27,14 @@ func (pm PmCrypto) parseMIME(mimeBody string, verifierKey *KeyRing) (*pmmime.Bod bodyCollector := pmmime.NewBodyCollector(printAccepter) attachmentsCollector := pmmime.NewAttachmentsCollector(bodyCollector) mimeVisitor := pmmime.NewMimeVisitor(attachmentsCollector) - // TODO: build was failing on this unused 'str' variable. This code looks like WIP - //str, err := armor.ArmorKey(verifierKey) - signatureCollector := newSignatureCollector(mimeVisitor, verifierKey.entities, config) + var pgpKering openpgp.KeyRing + if verifierKey != nil { + pgpKering = verifierKey.entities + } + + signatureCollector := newSignatureCollector(mimeVisitor, pgpKering, config) + err = pmmime.VisitAll(bytes.NewReader(mmBodyData), h, signatureCollector) verified := signatureCollector.verified diff --git a/crypto/signature_collector.go b/crypto/signature_collector.go index d4ea0da..e0877c7 100644 --- a/crypto/signature_collector.go +++ b/crypto/signature_collector.go @@ -2,13 +2,15 @@ package crypto import ( "bytes" - "github.com/ProtonMail/go-pm-mime" - "golang.org/x/crypto/openpgp" - "golang.org/x/crypto/openpgp/packet" "io" "io/ioutil" "mime" "net/textproto" + + "github.com/ProtonMail/go-pm-mime" + + "golang.org/x/crypto/openpgp" + "golang.org/x/crypto/openpgp/packet" ) // Use: ios/android only