Vasiliy Tolstov
43b0dbb123
* tunnel: reduce allocation and improve performance BenchmarkSha256Old-16 100000 156748 ns/op 11835 B/op 168 allocs/op BenchmarkSha256Old-16 100000 156229 ns/op 11819 B/op 168 allocs/op BenchmarkSha256New-16 100000 154751 ns/op 11107 B/op 161 allocs/op BenchmarkSha256New-16 100000 154263 ns/op 11110 B/op 161 allocs/op simple change lowers allocations and brings performance Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * fix Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * tunnel: reuse buf in Decrypt Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * fix unneeded conversations Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * base32 string is smaller than hex string Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
42 lines
855 B
Go
42 lines
855 B
Go
package tunnel
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestEncrypt(t *testing.T) {
|
|
key := []byte("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 := []byte("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")
|
|
}
|
|
}
|