Translated encryption/decryption consistency tests to catch2

This commit is contained in:
Leonetienne 2022-05-16 23:26:29 +02:00
parent 14e1fbe32c
commit f75a41d8dc
No known key found for this signature in database
GPG Key ID: C33879CD92E9708C

View File

@ -1,22 +1,14 @@
/*
#include "CppUnitTest.h"
#include "../GhettoCrypt/Cipher.h"
#include "../GhettoCrypt/Util.h"
#include <GCrypt/Cipher.h>
#include <GCrypt/Util.h>
#include "Catch2.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace GhettoCipher;
using namespace Leonetienne::GCrypt;
// THESE TESTS ASSUME BLOCK_SIZE == 512
namespace SimpleTests
{
TEST_CLASS(EncryptEqualsDecrypt)
{
public:
// Tests that encrypting a message of exactly BLOCK_SIZE yields the exact message back
TEST_CASE(__FILE__"/SingleBlock_NoPadding", "[Encryption/Decryption consistency]") {
// Tests that encrypting a message of exactly BLOCK_SIZE yields the exact message back
TEST_METHOD(SingleBlock_NoPadding)
{
// Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234");
const Cipher cipher(key);
@ -39,15 +31,15 @@ namespace SimpleTests
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext
Assert::AreEqual(
cleartext_bits,
REQUIRE(
cleartext_bits ==
decryptedBits
);
}
}
// Tests that encrypting a message of less than BLOCK_SIZE yields the exact message plus zero-padding back
TEST_CASE(__FILE__"/SingleBlock_Padding", "[Encryption/Decryption consistency]") {
// Tests that encrypting a message of less than BLOCK_SIZE yields the exact message plus zero-padding back
TEST_METHOD(SingleBlock_Padding)
{
// Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234");
const Cipher cipher(key);
@ -79,15 +71,15 @@ namespace SimpleTests
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext
Assert::AreEqual(
cleartext_bits_EXPECTED_RESULT,
REQUIRE(
cleartext_bits_EXPECTED_RESULT ==
decryptedBits
);
}
}
// Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks
TEST_CASE(__FILE__"MultiBlock_NoPadding/", "[Encryption/Decryption consistency]") {
// Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks
TEST_METHOD(MultiBlock_NoPadding)
{
// Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234");
const Cipher cipher(key);
@ -134,15 +126,15 @@ namespace SimpleTests
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext
Assert::AreEqual(
cleartext_bits,
REQUIRE(
cleartext_bits ==
decryptedBits
);
}
}
// Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks
TEST_CASE(__FILE__"MultiBlock_Padding/", "[Encryption/Decryption consistency]") {
// Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks
TEST_METHOD(MultiBlock_Padding)
{
// Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234");
const Cipher cipher(key);
@ -222,11 +214,9 @@ namespace SimpleTests
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext
Assert::AreEqual(
cleartext_bits_EXPECTED_RESULT,
REQUIRE(
cleartext_bits_EXPECTED_RESULT ==
decryptedBits
);
}
};
}
*/