diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5fb62884..45dbb9a8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -28,9 +28,9 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: '1.22' + go-version: '1.23' - uses: actions/checkout@v4 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.2 \ No newline at end of file + version: v1.64.5 diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 4df1b195..b2da42f7 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -12,10 +12,10 @@ jobs: runs-on: macos-latest steps: - - name: Set up xcode 15.3.0 + - name: Set up xcode 16.0.0 uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: 15.3.0 + xcode-version: 16.0.0 id: xcode - name: Set up Go 1.x diff --git a/.golangci.yml b/.golangci.yml index 33f2e665..c0c62fc6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,11 @@ issues: - ST1003 # CamelCase variables; see constants/cipher.go - missing output for example, go test can't validate it - variable 'hasExpiredEntity' is only used in the if-statement + - G101 + - Magic number + - param max has same name as predeclared identifier + - G115 + - the methods of "signatureCollector" exclude-rules: - path: crypto/key_clear.go text: "SA1019" @@ -31,6 +36,8 @@ issues: text: "Using the variable on range scope" - path: crypto/sign_verify_test.go text: "Using the variable on range scope" + - path: crypto/interop_test.go + text: "G101: Potential hardcoded credentials" linters: enable-all: true diff --git a/CHANGELOG.md b/CHANGELOG.md index cf3051e2..802636c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.4.0] – 2026-03-18 +### Added +- `InsecureAllowAllKeyFlagsWhenMissing` profile option. Allows usage of keys without key flags. + +### Changed +- Upgraded `go-crypto` fork to **v1.4.1**. + ## [3.3.0] – 2025-05-23 ### Added - MaxDecompressedSize option to control the maximum size of decompressed messages. diff --git a/constants/version.go b/constants/version.go index df6cf048..e670d6f2 100644 --- a/constants/version.go +++ b/constants/version.go @@ -1,3 +1,3 @@ package constants -const Version = "3.3.0" +const Version = "3.4.0" diff --git a/crypto/encrypt_decrypt_test.go b/crypto/encrypt_decrypt_test.go index 23adc2ac..befb0c28 100644 --- a/crypto/encrypt_decrypt_test.go +++ b/crypto/encrypt_decrypt_test.go @@ -927,7 +927,7 @@ func TestEncryptDecryptKey(t *testing.T) { func TestEncryptCompressionApplied(t *testing.T) { const numReplicas = 10 builder := strings.Builder{} - for i := 0; i < numReplicas; i++ { + for range numReplicas { builder.WriteString(testMessage) } messageToEncrypt := builder.String() diff --git a/crypto/keyring_test.go b/crypto/keyring_test.go index 5cd5dcd3..cc7dd9e5 100644 --- a/crypto/keyring_test.go +++ b/crypto/keyring_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/ProtonMail/go-crypto/openpgp/ecdh" "github.com/ProtonMail/go-crypto/openpgp/eddsa" @@ -121,11 +122,11 @@ func TestKeyIds(t *testing.T) { } func TestMultipleKeyRing(t *testing.T) { - assert.Exactly(t, 3, len(keyRingTestMultiple.entities)) + assert.Len(t, keyRingTestMultiple.entities, 3) assert.Exactly(t, 3, keyRingTestMultiple.CountEntities()) assert.Exactly(t, 3, keyRingTestMultiple.CountDecryptionEntities(testTime)) - assert.Exactly(t, 3, len(keyRingTestMultiple.GetKeys())) + assert.Len(t, keyRingTestMultiple.GetKeys(), 3) testKey, err := keyRingTestMultiple.GetKey(1) if err != nil { @@ -134,28 +135,28 @@ func TestMultipleKeyRing(t *testing.T) { assert.Exactly(t, keyTestEC, testKey) _, err = keyRingTestMultiple.GetKey(3) - assert.NotNil(t, err) + require.Error(t, err) singleKeyRing, err := keyRingTestMultiple.FirstKey() if err != nil { t.Fatal("Expected no error while filtering the first key, got:", err) } - assert.Exactly(t, 1, len(singleKeyRing.entities)) + assert.Len(t, singleKeyRing.entities, 1) assert.Exactly(t, 1, singleKeyRing.CountEntities()) assert.Exactly(t, 1, singleKeyRing.CountDecryptionEntities(testTime)) } func TestSerializeParse(t *testing.T) { serialized, err := keyRingTestMultiple.Serialize() - assert.Nil(t, err) + require.NoError(t, err) parsed, err := NewKeyRingFromBinary(serialized) - assert.Nil(t, err) + require.NoError(t, err) - assert.Exactly(t, 3, len(parsed.GetKeys())) + assert.Len(t, parsed.GetKeys(), 3) for i, parsedKey := range parsed.GetKeys() { expectedKey, err := keyRingTestMultiple.GetKey(i) - assert.Nil(t, err) + require.NoError(t, err) assert.Exactly(t, parsedKey.GetFingerprint(), expectedKey.GetFingerprint()) } } @@ -167,7 +168,7 @@ func TestClearPrivateKey(t *testing.T) { } for _, key := range keyRingCopy.GetKeys() { - assert.Nil(t, clearPrivateKey(key.entity.PrivateKey.PrivateKey)) + require.NoError(t, clearPrivateKey(key.entity.PrivateKey.PrivateKey)) } keys := keyRingCopy.GetKeys() diff --git a/crypto/message_test.go b/crypto/message_test.go index af999010..b6c69cef 100644 --- a/crypto/message_test.go +++ b/crypto/message_test.go @@ -11,6 +11,7 @@ import ( "github.com/ProtonMail/go-crypto/openpgp/packet" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestTextMessageEncryptionWithPassword(t *testing.T) { @@ -32,7 +33,7 @@ func TestTextMessageEncryptionWithPassword(t *testing.T) { } sessionKey, ok := p.(*packet.SymmetricKeyEncrypted) if ok { - assert.Equal(t, sessionKey.CipherFunc, packet.CipherAES256) + assert.Equal(t, packet.CipherAES256, sessionKey.CipherFunc) foundSk = true break } @@ -43,7 +44,7 @@ func TestTextMessageEncryptionWithPassword(t *testing.T) { // Decrypt data with wrong password decryptorWrong, _ := testPGP.Decryption().Password([]byte("Wrong password")).New() _, err = decryptorWrong.Decrypt(encrypted.Bytes(), Bytes) - assert.NotNil(t, err) + require.Error(t, err) // Decrypt data with the good password decryptor, _ := testPGP.Decryption().Password(testSymmetricKey).New() @@ -67,7 +68,7 @@ func TestBinaryMessageEncryptionWithPassword(t *testing.T) { // Decrypt data with wrong password decryptorWrong, _ := testPGP.Decryption().Password([]byte("Wrong password")).New() _, err = decryptorWrong.Decrypt(encrypted.Bytes(), Bytes) - assert.NotNil(t, err) + require.Error(t, err) // Decrypt data with the good password decryptor, _ := testPGP.Decryption().Password(testSymmetricKey).New() @@ -305,7 +306,7 @@ func TestSHA1SignedMessageDecryption(t *testing.T) { func TestMultipleKeyMessageEncryption(t *testing.T) { var message = []byte("plain text") - assert.Exactly(t, 3, len(keyRingTestMultiple.entities)) + assert.Len(t, keyRingTestMultiple.entities, 3) encryptor, _ := testPGP.Encryption().Recipients(keyRingTestMultiple).SigningKeys(keyRingTestPrivate).New() ciphertext, err := encryptor.Encrypt(message) @@ -317,7 +318,7 @@ func TestMultipleKeyMessageEncryption(t *testing.T) { // followed by a single symmetrically encrypted data packet (tag 18) var p packet.Packet packets := packet.NewReader(bytes.NewReader(ciphertext.Bytes())) - for i := 0; i < 3; i++ { + for range 3 { if p, err = packets.Next(); err != nil { t.Fatal(err.Error()) } @@ -349,7 +350,7 @@ func TestMultipleKeyMessageEncryption(t *testing.T) { func TestMessageGetEncryptionKeyIDs(t *testing.T) { var message = []byte("plain text") - assert.Exactly(t, 3, len(keyRingTestMultiple.entities)) + assert.Len(t, keyRingTestMultiple.entities, 3) encryptor, _ := testPGP.Encryption().Recipients(keyRingTestMultiple).SigningKeys(keyRingTestPrivate).New() ciphertext, err := encryptor.Encrypt(message) @@ -357,7 +358,7 @@ func TestMessageGetEncryptionKeyIDs(t *testing.T) { t.Fatal("Expected no error when encrypting, got:", err) } ids, ok := ciphertext.EncryptionKeyIDs() - assert.Exactly(t, 3, len(ids)) + assert.Len(t, ids, 3) assert.True(t, ok) encKey, ok := keyRingTestMultiple.entities[0].EncryptionKey(time.Now(), nil) assert.True(t, ok) @@ -371,7 +372,7 @@ func TestMessageGetHexGetEncryptionKeyIDs(t *testing.T) { } ids, ok := ciphertext.HexEncryptionKeyIDs() - assert.Exactly(t, 2, len(ids)) + assert.Len(t, ids, 2) assert.True(t, ok) assert.Exactly(t, "76ad736fa7e0e83c", ids[0]) @@ -388,7 +389,7 @@ func TestMessageGetSignatureKeyIDs(t *testing.T) { } ids, ok := SignatureKeyIDs(signature) - assert.Exactly(t, 1, len(ids)) + assert.Len(t, ids, 1) assert.True(t, ok) signingKey, ok := keyRingTestPrivate.entities[0].SigningKey(time.Now(), nil) assert.True(t, ok) @@ -402,7 +403,7 @@ func TestMessageGetHexSignatureKeyIDs(t *testing.T) { } ids, ok := ciphertext.HexSignatureKeyIDs() - assert.Exactly(t, 2, len(ids)) + assert.Len(t, ids, 2) assert.True(t, ok) assert.Exactly(t, "3eb6259edf21df24", ids[0]) diff --git a/crypto/sessionkey_test.go b/crypto/sessionkey_test.go index 7b002bf1..dfd20963 100644 --- a/crypto/sessionkey_test.go +++ b/crypto/sessionkey_test.go @@ -11,6 +11,7 @@ import ( "github.com/ProtonMail/gopenpgp/v3/constants" "github.com/ProtonMail/gopenpgp/v3/profile" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var testSessionKey *SessionKey @@ -81,7 +82,7 @@ func TestSymmetricKeyPacket(t *testing.T) { decHandle, _ := testPGP.Decryption().Password([]byte("Wrong password")).New() wrongSymmetricKey, err := decHandle.DecryptSessionKey(keyPacket) if err != nil { - assert.EqualError(t, err, "gopenpgp: unable to decrypt any packet") + require.EqualError(t, err, "gopenpgp: unable to decrypt any packet") } else { assert.NotEqual(t, testSessionKey, wrongSymmetricKey) } @@ -134,7 +135,7 @@ func TestDataPacketEncryption(t *testing.T) { } decryptor, _ := testPGP.Decryption().SessionKey(wrongKey).New() _, err = decryptor.Decrypt(pgpMessage.BinaryDataPacket(), Bytes) - assert.NotNil(t, err) + require.Error(t, err) // Decrypt data with the good session key decryptor, _ = testPGP.Decryption().SessionKey(testSessionKey).New() @@ -145,7 +146,7 @@ func TestDataPacketEncryption(t *testing.T) { assert.Exactly(t, message, decrypted.Bytes()) // Encrypt session key - assert.Exactly(t, 3, len(keyRingTestMultiple.entities)) + assert.Len(t, keyRingTestMultiple.entities, 3) encryptor, _ = testPGP.Encryption().Recipients(keyRingTestMultiple).New() keyPackets, err := encryptor.EncryptSessionKey(testSessionKey) if err != nil { @@ -167,7 +168,7 @@ func TestDataPacketEncryption(t *testing.T) { } ids, ok := pgpMessage.EncryptionKeyIDs() assert.True(t, ok) - assert.Exactly(t, 3, len(ids)) + assert.Len(t, ids, 3) // Test if final decryption succeeds decryptor, _ = testPGP.Decryption().DecryptionKeys(keyRingTestPrivate).New() @@ -239,7 +240,7 @@ func TestDataPacketEncryptionAndSignature(t *testing.T) { } decryptor, _ := testPGP.Decryption().SessionKey(wrongKey).New() _, err = decryptor.Decrypt(pgpMessage.BinaryDataPacket(), Bytes) - assert.NotNil(t, err) + require.Error(t, err) // Decrypt data with the good session key decryptor, _ = testPGP.Decryption().SessionKey(testSessionKey).New() @@ -276,7 +277,7 @@ func TestDataPacketEncryptionAndSignature(t *testing.T) { assert.Exactly(t, message, decrypted.Bytes()) // Encrypt session key - assert.Exactly(t, 3, len(keyRingTestMultiple.entities)) + assert.Len(t, keyRingTestMultiple.entities, 3) encryptor, _ = testPGP.Encryption().Recipients(keyRingTestMultiple).New() keyPacket, err := encryptor.EncryptSessionKey(testSessionKey) if err != nil { @@ -298,7 +299,7 @@ func TestDataPacketEncryptionAndSignature(t *testing.T) { } ids, ok := pgpMessage.EncryptionKeyIDs() assert.True(t, ok) - assert.Exactly(t, 3, len(ids)) + assert.Len(t, ids, 3) // Test if final decryption & verification succeeds decryptor, _ = testPGP.Decryption().DecryptionKeys(keyRingTestPrivate).VerificationKeys(keyRingTestPublic).New() @@ -345,7 +346,7 @@ func TestMDCFailDecryption(t *testing.T) { decryptor, _ := testPGP.Decryption().SessionKey(sessionKey).New() _, err = decryptor.Decrypt(pgpMessage.BinaryDataPacket(), Bytes) - assert.NotNil(t, err) + assert.Error(t, err) } func TestAsymmetricKeyPacketDecryptionFailure(t *testing.T) { diff --git a/crypto/signature_test.go b/crypto/signature_test.go index b9648315..32efb6c6 100644 --- a/crypto/signature_test.go +++ b/crypto/signature_test.go @@ -176,9 +176,6 @@ func Test_KeyRing_GetVerifiedSignatureTimestampSuccess(t *testing.T) { t.Fatal(err) } actualTime := verificationResult.SignatureCreationTime() - if err != nil { - t.Errorf("Got an error while parsing the signature creation time: %v", err) - } if timeLocal != actualTime { t.Errorf("Expected creation time to be %d, got %d", timeLocal, actualTime) } @@ -226,9 +223,6 @@ func Test_KeyRing_GetVerifiedSignatureWithTwoKeysTimestampSuccess(t *testing.T) } actualTime := verificationResult.SignatureCreationTime() otherTime := verificationResult.Signatures[1].Signature.CreationTime.Unix() - if err != nil { - t.Errorf("Got an error while parsing the signature creation time: %v", err) - } if time2 != otherTime { t.Errorf("Expected creation time to be %d, got %d", otherTime, time2) diff --git a/go.mod b/go.mod index 812a3eb6..894ca148 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,21 @@ module github.com/ProtonMail/gopenpgp/v3 -go 1.22.0 +go 1.23.0 require ( - github.com/ProtonMail/go-crypto v1.3.0 + github.com/ProtonMail/go-crypto v1.4.1 github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f github.com/stretchr/testify v1.10.0 ) require ( - github.com/cloudflare/circl v1.6.0 // indirect + github.com/cloudflare/circl v1.6.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/pretty v0.2.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.33.0 // indirect - golang.org/x/sys v0.30.0 // indirect - golang.org/x/text v0.22.0 // indirect + golang.org/x/crypto v0.41.0 // indirect + golang.org/x/sys v0.35.0 // indirect + golang.org/x/text v0.28.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 3a5eb37c..ddfe87ce 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,9 @@ -github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw= -github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE= +github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM= +github.com/ProtonMail/go-crypto v1.4.1/go.mod h1:e1OaTyu5SYVrO9gKOEhTc+5UcXtTUa+P3uLudwcgPqo= github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k= github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw= -github.com/cloudflare/circl v1.6.0 h1:cr5JKic4HI+LkINy2lg3W2jF8sHCVTBncJr5gIIq7qk= -github.com/cloudflare/circl v1.6.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= +github.com/cloudflare/circl v1.6.2 h1:hL7VBpHHKzrV5WTfHCaBsgx/HGbBYlgrwvNXEVDYYsQ= +github.com/cloudflare/circl v1.6.2/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= @@ -18,8 +18,8 @@ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= -golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= +golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4= +golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -35,8 +35,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= +golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -45,8 +45,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= -golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= +golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/sanitize_string_test.go b/internal/sanitize_string_test.go index 981272b3..4548eda8 100644 --- a/internal/sanitize_string_test.go +++ b/internal/sanitize_string_test.go @@ -23,7 +23,7 @@ func testStringSanitizeReader(t *testing.T, test string) { n, err = reader.Read(smallBuff) byteBuffer.Write(smallBuff[:n]) } - assert.Equal(t, byteBuffer.String(), expectedOutput(test)) + assert.Equal(t, expectedOutput(test), byteBuffer.String()) } func TestStringSanitizeReader(t *testing.T) { diff --git a/mime/mime.go b/mime/mime.go index a7dc6c85..9411eb70 100644 --- a/mime/mime.go +++ b/mime/mime.go @@ -62,7 +62,7 @@ func Decrypt( bodyContent, bodyMimeType := body.GetBody() bodyContentSanitized := internal.SanitizeString(bodyContent) callbacks.OnBody(bodyContentSanitized, bodyMimeType) - for i := 0; i < len(attachments); i++ { + for i := range attachments { callbacks.OnAttachment(attachmentHeaders[i], []byte(attachments[i])) } callbacks.OnEncryptedHeaders("") diff --git a/mime/mime_test.go b/mime/mime_test.go index 3653a6b8..3b4ad970 100644 --- a/mime/mime_test.go +++ b/mime/mime_test.go @@ -22,18 +22,18 @@ func (t *Callbacks) OnBody(body string, mimetype string) { assert.Exactly(t.Testing, readTestFile("mime_decryptedBody", false), body) } -func (t Callbacks) OnAttachment(headers string, data []byte) { +func (t *Callbacks) OnAttachment(headers string, data []byte) { assert.Exactly(t.Testing, 1, data) } -func (t Callbacks) OnEncryptedHeaders(headers string) { +func (t *Callbacks) OnEncryptedHeaders(headers string) { assert.Exactly(t.Testing, "", headers) } -func (t Callbacks) OnVerified(verified int) { +func (t *Callbacks) OnVerified(verified int) { } -func (t Callbacks) OnError(err error) { +func (t *Callbacks) OnError(err error) { t.Testing.Fatal("Error in decrypting MIME message: ", err) }