Skip to content

Commit

Permalink
test: verify Sign / VerifySignature
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Sep 3, 2024
1 parent deb6c91 commit 0937165
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/gpgx/signature_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package gpgx

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestGPG_Signature(t *testing.T) {
privateKey, err := ReadPrivateKeyFile(privateKeyPath, password)
require.NoError(t, err)

input := []byte("hello, world")
signedData, err := Sign(input, privateKey)
require.NoError(t, err)
require.NotEmpty(t, signedData)

publicKey, err := ReadArmoredKeyFile(publicKeyPath)
require.NoError(t, err)
require.Len(t, publicKey, 1)

var expectedFingerprint [20]byte
copy(expectedFingerprint[:], publicKey[0].PrimaryKey.Fingerprint[:])

verifiedBytes, err := VerifySignature(signedData, publicKey, expectedFingerprint)
require.NoError(t, err)
require.Equal(t, string(input), string(verifiedBytes))
}

0 comments on commit 0937165

Please sign in to comment.