First commit: Outline of tunnel encryption code

This commit is contained in:
Milos Gajdos
2019-11-25 14:58:12 +00:00
parent 95045be83d
commit 61fe552ac4
2 changed files with 113 additions and 0 deletions

41
tunnel/crypto_test.go Normal file
View File

@@ -0,0 +1,41 @@
package tunnel
import (
"bytes"
"testing"
)
func TestEncrypt(t *testing.T) {
key := "tokenpassphrase"
data := []byte("supersecret")
cipherText, err := Encrypt(data, key)
if err != nil {
t.Errorf("failed to encrypt data: %v", err)
}
// verify the cipherText is not the same as data
if bytes.Equal(data, cipherText) {
t.Error("encrypted data are the same as plaintext")
}
}
func TestDecrypt(t *testing.T) {
key := "tokenpassphrase"
data := []byte("supersecret")
cipherText, err := Encrypt(data, key)
if err != nil {
t.Errorf("failed to encrypt data: %v", err)
}
plainText, err := Decrypt(cipherText, key)
if err != nil {
t.Errorf("failed to decrypt data: %v", err)
}
// verify the plainText is the same as data
if !bytes.Equal(data, plainText) {
t.Error("decrypted data not the same as plaintext")
}
}