package encryption_test

import (
	"crypto/rand"
	"testing"

	"numenor-labs.us/dsfx/dsfx/internal/lib/crypto/encryption"
)

func TestEncryptDecrypt(t *testing.T) {
	key := make([]byte, 32)
	_, err := rand.Read(key)
	if err != nil {
		t.Fatal(err)
		return
	}

	plaintext := []byte("Hello, Worlskljfsjflskfjlskjfjslkfjsfjslkfjsfd!")
	ciphertext, err := encryption.Encrypt(key, plaintext)
	if err != nil {
		t.Fatal(err)
		return
	}

	decrypted, err := encryption.Decrypt(key, ciphertext)
	if err != nil {
		t.Fatal(err)
		return
	}

	if string(decrypted) != string(plaintext) {
		t.Errorf("decrypted text does not match original plaintext")
		return
	}
}