39 lines
865 B
Go
39 lines
865 B
Go
|
package pgp
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
|
||
|
"golang.org/x/crypto/openpgp"
|
||
|
)
|
||
|
|
||
|
func TestSignature(t *testing.T) {
|
||
|
fmt.Println("Signature test: START")
|
||
|
entity, err := GetEntity([]byte(testPublicKey), []byte(testPrivateKey))
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
fmt.Println("Created private key entity.")
|
||
|
|
||
|
var signature []byte
|
||
|
signature, err = Sign(entity, []byte(testMessage))
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
fmt.Println("Created signature of test message with private key entity.")
|
||
|
|
||
|
var publicKeyEntity *openpgp.Entity
|
||
|
publicKeyEntity, err = GetEntity([]byte(testPublicKey), []byte{})
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
fmt.Println("Created public key entity.")
|
||
|
|
||
|
err = Verify(publicKeyEntity, []byte(testMessage), signature)
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
fmt.Println("Signature verified using public key entity.")
|
||
|
fmt.Println("Signature test: END")
|
||
|
}
|