package mlkem_test

import "seekia/internal/cryptography/mlkem"

import "testing"

func TestEncryptDecryptMlkem(t *testing.T) {

	testPublicKey, testPrivateKey, err := mlkem.GetNewRandomPublicPrivateMlkemKeys()
	if (err != nil) {
		t.Fatal("Failed to derive Mlkem keys: " + err.Error())
	}

	encryptedKey, encryptedBytes, err := mlkem.EncryptNewRandomKeyWithMlkem(testPublicKey)
	if (err != nil) {
		t.Fatal("Failed to encrypt Mlkem: " + err.Error())
	}

	ableToDecrypt, decryptedKey, err := mlkem.DecryptMlkemEncryptedKey(encryptedBytes, testPrivateKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt Mlkem: " + err.Error())
	}
	if (ableToDecrypt == false){
		t.Fatal("Failed to decrypt Mlkem")
	}

	if (decryptedKey != encryptedKey){
		t.Fatal("Mlkem decrypted key does not match.") 
	}
}



