diff options
| author | Adam Langley <agl@golang.org> | 2011-06-13 13:04:59 -0400 |
|---|---|---|
| committer | Adam Langley <agl@golang.org> | 2011-06-13 13:04:59 -0400 |
| commit | 8834bb0bfa7cbbfeb9df0c6d1fa2296e24a431d5 (patch) | |
| tree | 71c533a866d1749384257e4895063a975db988e1 /src/pkg/crypto/openpgp/write_test.go | |
| parent | d164b6081de197612b99b405feb9a2d6e73028a3 (diff) | |
| download | go-8834bb0bfa7cbbfeb9df0c6d1fa2296e24a431d5.tar.xz | |
crypto/openpgp: flesh out Encrypt by adding support for signing.
R=bradfitz
CC=golang-dev
https://golang.org/cl/4572059
Diffstat (limited to 'src/pkg/crypto/openpgp/write_test.go')
| -rw-r--r-- | src/pkg/crypto/openpgp/write_test.go | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/pkg/crypto/openpgp/write_test.go b/src/pkg/crypto/openpgp/write_test.go index cfa1314184..028a5e087d 100644 --- a/src/pkg/crypto/openpgp/write_test.go +++ b/src/pkg/crypto/openpgp/write_test.go @@ -122,11 +122,16 @@ func TestSymmetricEncryption(t *testing.T) { } } -func TestEncryption(t *testing.T) { +func testEncryption(t *testing.T, isSigned bool) { kring, _ := ReadKeyRing(readerFromHex(testKeys1And2PrivateHex)) + var signed *Entity + if isSigned { + signed = kring[0] + } + buf := new(bytes.Buffer) - w, err := Encrypt(buf, kring[:1], nil, /* not signed */ nil /* no hints */ ) + w, err := Encrypt(buf, kring[:1], signed, nil /* no hints */ ) if err != nil { t.Errorf("error in Encrypt: %s", err) return @@ -150,6 +155,16 @@ func TestEncryption(t *testing.T) { return } + if isSigned { + expectedKeyId := kring[0].signingKey().PublicKey.KeyId + if md.SignedByKeyId != expectedKeyId { + t.Errorf("message signed by wrong key id, got: %d, want: %d", *md.SignedBy, expectedKeyId) + } + if md.SignedBy == nil { + t.Errorf("failed to find the signing Entity") + } + } + plaintext, err := ioutil.ReadAll(md.UnverifiedBody) if err != nil { t.Errorf("error reading encrypted contents: %s", err) @@ -164,4 +179,21 @@ func TestEncryption(t *testing.T) { if string(plaintext) != message { t.Errorf("got: %s, want: %s", string(plaintext), message) } + + if isSigned { + if md.SignatureError != nil { + t.Errorf("signature error: %s", err) + } + if md.Signature == nil { + t.Error("signature missing") + } + } +} + +func TestEncryption(t *testing.T) { + testEncryption(t, false /* not signed */ ) +} + +func TestEncryptAndSign(t *testing.T) { + testEncryption(t, true /* signed */ ) } |
