Review1
This commit is contained in:
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewKeyPair(t *testing.T) {
|
||||
@ -21,7 +23,36 @@ func TestGetKey(t *testing.T) {
|
||||
// fmt.Println(key.Armor())
|
||||
Armpubkey, _ := key.GetArmoredPublicKey()
|
||||
pubkey := base64.StdEncoding.EncodeToString([]byte(Armpubkey))
|
||||
if kp.Public != pubkey {
|
||||
log.Fatal("error in public key")
|
||||
}
|
||||
assert.Equal(t, kp.Public, pubkey, "The two public keys should be the same.")
|
||||
//if kp.Public != pubkey {
|
||||
// log.Fatal("error in public key")
|
||||
//}
|
||||
}
|
||||
|
||||
func TestEncryptDecrypt(t *testing.T) {
|
||||
kp := NewKeyPair()
|
||||
foo := "totoaimelesfrites!"
|
||||
encMess, err := Encrypt(kp.Public, []byte(foo))
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
decMess, err2 := Decrypt(kp.Private, encMess)
|
||||
if err2 != nil {
|
||||
log.Println(err2.Error())
|
||||
}
|
||||
assert.Equal(t, foo, decMess, "The two messages should be the same.")
|
||||
}
|
||||
|
||||
func TestEncryptDecryptSigned(t *testing.T) {
|
||||
kp := NewKeyPair()
|
||||
foo := "totoaimelesfrites!"
|
||||
encMess, sign, err := EncryptAndSign(kp.Public, kp.Private, []byte(foo))
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
decMess, err2 := DecryptAndCheck(kp.Private, kp.Public, encMess, sign)
|
||||
if err2 != nil {
|
||||
log.Println(err2.Error())
|
||||
}
|
||||
assert.Equal(t, foo, string(decMess), "The two messages should be the same.")
|
||||
}
|
||||
|
Reference in New Issue
Block a user