Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/test_crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
correctPassword);

// Try to decrypt with wrong password
EXPECT_THROW(

Check warning on line 88 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / test

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 88 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / sonar

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 88 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / build

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]
seal::Cryptography::decryptPacket(std::span<const unsigned char>(packet), wrongPassword),
std::runtime_error);
}
Expand All @@ -106,17 +106,65 @@
corrupted[corrupted.size() / 2] ^= 0xFF;

// Should fail authentication
EXPECT_THROW(

Check warning on line 109 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / test

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 109 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / sonar

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 109 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / build

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]
seal::Cryptography::decryptPacket(std::span<const unsigned char>(corrupted), password),
std::runtime_error);
}

TEST_F(CryptoTest, VerifyPacketAcceptsValidPacket)
{
auto password = make_secure_string("test_password");
std::string plaintext = "verify me";

std::vector<unsigned char> plainBytes(plaintext.begin(), plaintext.end());

auto packet =
seal::Cryptography::encryptPacket(std::span<const unsigned char>(plainBytes), password);

EXPECT_NO_THROW(
seal::Cryptography::verifyPacket(std::span<const unsigned char>(packet), password));
}

TEST_F(CryptoTest, VerifyPacketRejectsWrongPassword)
{
auto password = make_secure_string("test_password");
auto wrongPassword = make_secure_string("wrong_password");
std::string plaintext = "verify me";

std::vector<unsigned char> plainBytes(plaintext.begin(), plaintext.end());

auto packet =
seal::Cryptography::encryptPacket(std::span<const unsigned char>(plainBytes), password);

EXPECT_THROW(
seal::Cryptography::verifyPacket(std::span<const unsigned char>(packet), wrongPassword),
std::runtime_error);
}

TEST_F(CryptoTest, VerifyPacketRejectsCorruptedPacket)
{
auto password = make_secure_string("test_password");
std::string plaintext = "verify me";

std::vector<unsigned char> plainBytes(plaintext.begin(), plaintext.end());

auto packet =
seal::Cryptography::encryptPacket(std::span<const unsigned char>(plainBytes), password);

std::vector<unsigned char> corrupted = packet;
corrupted[corrupted.size() / 2] ^= 0xFF;

EXPECT_THROW(
seal::Cryptography::verifyPacket(std::span<const unsigned char>(corrupted), password),
std::runtime_error);
}

TEST_F(CryptoTest, TooShortPacketThrows)
{
auto password = make_secure_string("test_password");
std::vector<unsigned char> shortPacket(10); // Too short

EXPECT_THROW(

Check warning on line 167 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / test

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 167 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / sonar

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]

Check warning on line 167 in tests/test_crypto.cpp

View workflow job for this annotation

GitHub Actions / build

discarding return value of function with [[nodiscard]] attribute [D:\a\seal\seal\build\seal_tests.vcxproj]
seal::Cryptography::decryptPacket(std::span<const unsigned char>(shortPacket), password),
std::runtime_error);
}
Expand Down
Loading