A command-line tool using the saltpack messaging format and the keys.pub Go library.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
715 B

package salty
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCrypto(t *testing.T) {
assert := assert.New(t)
key, pub := GenerateKeys(io.Discard)
assert.NotEmpty(key)
assert.NotEmpty(pub)
assert.Equal(key.PublicKey().String(), pub)
input := []byte("Hello World!")
encrypted, err := Encrypt(key, input, []string{pub})
assert.NoError(err)
decrypted, sender, err := Decrypt(key, encrypted)
assert.NoError(err)
assert.Equal(pub, sender.String())
assert.Equal(decrypted, input)
signed, err := Sign(key, input)
assert.NoError(err)
out, signer, err := Verify(signed)
assert.NoError(err)
assert.Equal(signer.ID().String(), key.ID().String())
assert.Equal(input, out)
}