aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ecies/ecies_test.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-02-29 22:05:37 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-02-29 22:05:37 +0800
commit4044a8cea44cd4cee3a8ddaf51a76b71c9d22042 (patch)
tree1aa3776381e8e117b66e4a8ed1bf83e29d966ff1 /crypto/ecies/ecies_test.go
parentc541b38fb36587d23c60f5e2f2b9b3c8700ec489 (diff)
parent61be63bb9b8527bb3e2357ad35a0f4ef29304da1 (diff)
downloadgo-tangerine-1.3.4.tar
go-tangerine-1.3.4.tar.gz
go-tangerine-1.3.4.tar.bz2
go-tangerine-1.3.4.tar.lz
go-tangerine-1.3.4.tar.xz
go-tangerine-1.3.4.tar.zst
go-tangerine-1.3.4.zip
Merge pull request #2258 from obscuren/release/1.3.4v1.3.4
Homestead Release Candidate
Diffstat (limited to 'crypto/ecies/ecies_test.go')
-rw-r--r--crypto/ecies/ecies_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/crypto/ecies/ecies_test.go b/crypto/ecies/ecies_test.go
index 1c391f938..5d46c32ce 100644
--- a/crypto/ecies/ecies_test.go
+++ b/crypto/ecies/ecies_test.go
@@ -353,6 +353,36 @@ func TestEncryptDecrypt(t *testing.T) {
}
}
+func TestDecryptShared2(t *testing.T) {
+ prv, err := GenerateKey(rand.Reader, DefaultCurve, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ message := []byte("Hello, world.")
+ shared2 := []byte("shared data 2")
+ ct, err := Encrypt(rand.Reader, &prv.PublicKey, message, nil, shared2)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // Check that decrypting with correct shared data works.
+ pt, err := prv.Decrypt(rand.Reader, ct, nil, shared2)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !bytes.Equal(pt, message) {
+ t.Fatal("ecies: plaintext doesn't match message")
+ }
+
+ // Decrypting without shared data or incorrect shared data fails.
+ if _, err = prv.Decrypt(rand.Reader, ct, nil, nil); err == nil {
+ t.Fatal("ecies: decrypting without shared data didn't fail")
+ }
+ if _, err = prv.Decrypt(rand.Reader, ct, nil, []byte("garbage")); err == nil {
+ t.Fatal("ecies: decrypting with incorrect shared data didn't fail")
+ }
+}
+
// TestMarshalEncryption validates the encode/decode produces a valid
// ECIES encryption key.
func TestMarshalEncryption(t *testing.T) {