go-crypt/crypt/crypt_test.go
Claude 8498ecf890
feat: extract crypto/security packages from core/go
ChaCha20-Poly1305, AES-256-GCM, Argon2 key derivation, OpenPGP
challenge-response auth, and trust tier policy engine.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 15:25:54 +00:00

45 lines
1.1 KiB
Go

package crypt
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEncryptDecrypt_Good(t *testing.T) {
plaintext := []byte("hello, world!")
passphrase := []byte("correct-horse-battery-staple")
encrypted, err := Encrypt(plaintext, passphrase)
assert.NoError(t, err)
assert.NotEqual(t, plaintext, encrypted)
decrypted, err := Decrypt(encrypted, passphrase)
assert.NoError(t, err)
assert.Equal(t, plaintext, decrypted)
}
func TestEncryptDecrypt_Bad(t *testing.T) {
plaintext := []byte("secret data")
passphrase := []byte("correct-passphrase")
wrongPassphrase := []byte("wrong-passphrase")
encrypted, err := Encrypt(plaintext, passphrase)
assert.NoError(t, err)
_, err = Decrypt(encrypted, wrongPassphrase)
assert.Error(t, err)
}
func TestEncryptDecryptAES_Good(t *testing.T) {
plaintext := []byte("hello, AES world!")
passphrase := []byte("my-secure-passphrase")
encrypted, err := EncryptAES(plaintext, passphrase)
assert.NoError(t, err)
assert.NotEqual(t, plaintext, encrypted)
decrypted, err := DecryptAES(encrypted, passphrase)
assert.NoError(t, err)
assert.Equal(t, plaintext, decrypted)
}