Skip to content
This repository was archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
crypto/cert: add test for bad signature in Verify
Browse files Browse the repository at this point in the history
david415 committed Apr 4, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 1ddb4d1 commit 761a42c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion crypto/cert/ed25519_test.go
Original file line number Diff line number Diff line change
@@ -71,6 +71,26 @@ func TestEd25519Certificate(t *testing.T) {
func TestEd25519BadCertificate(t *testing.T) {
assert := assert.New(t)

signingPrivKey, err := eddsa.NewKeypair(rand.Reader)
assert.NoError(err)

// expiration in six months
expiration := time.Now().AddDate(0, 6, 0).Unix()
certified := signingPrivKey.PublicKey().Bytes()
certified[3] = 235 // modify the signed data so that the Verify will fail

certificate, err := Sign(signingPrivKey, certified, expiration)
assert.NoError(err)

mesg, err := Verify(signingPrivKey.PublicKey(), certificate)
assert.Error(err)
assert.Equal(ErrBadSignature, err)
assert.Nil(mesg)
}

func TestEd25519WrongCertificate(t *testing.T) {
assert := assert.New(t)

ephemeralPrivKey, err := eddsa.NewKeypair(rand.Reader)
assert.NoError(err)

@@ -79,7 +99,6 @@ func TestEd25519BadCertificate(t *testing.T) {

// expiration in six months
expiration := time.Now().AddDate(0, 6, 0).Unix()

certificate, err := Sign(signingPrivKey, ephemeralPrivKey.PublicKey().Bytes(), expiration)
assert.NoError(err)

0 comments on commit 761a42c

Please sign in to comment.