mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-25 09:43:20 +01:00
24 lines
577 B
Go
24 lines
577 B
Go
package data
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ddworken/hishtory/shared"
|
|
)
|
|
|
|
func TestEncryptDecrypt(t *testing.T) {
|
|
k1 := EncryptionKey("key")
|
|
k2 := EncryptionKey("key")
|
|
if string(k1) != string(k2) {
|
|
t.Fatalf("Expected EncryptionKey to be deterministic!")
|
|
}
|
|
|
|
ciphertext, nonce, err := Encrypt("key", []byte("hello world!"), []byte("extra"))
|
|
shared.Check(t, err)
|
|
plaintext, err := Decrypt("key", ciphertext, []byte("extra"), nonce)
|
|
shared.Check(t, err)
|
|
if string(plaintext) != "hello world!" {
|
|
t.Fatalf("Expected decrypt(encrypt(x)) to work, but it didn't!")
|
|
}
|
|
}
|