Add reusable strict JSON, rate limiting, and sealed secrets
This commit is contained in:
10 files changed
+778
-40
No files matched your search
@@ -3,6 +3,7 @@
|
||||
#include <Void/Testing/Suite.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -91,5 +92,40 @@ namespace
|
||||
Void::Testing::expect(!*invalid);
|
||||
Void::Testing::expect(!*malformed);
|
||||
}
|
||||
|
||||
Test sealed_secrets_round_trip_and_use_random_nonces()
|
||||
{
|
||||
auto key = Void::Security::random_secret_key();
|
||||
Void::Testing::require(key.has_value());
|
||||
const std::vector<unsigned char> plaintext{'s', 'e', 'c',
|
||||
'r', 'e', 't'};
|
||||
auto first = Void::Security::seal_secret(plaintext, *key);
|
||||
auto second = Void::Security::seal_secret(plaintext, *key);
|
||||
Void::Testing::require(first.has_value());
|
||||
Void::Testing::require(second.has_value());
|
||||
Void::Testing::expect_ne(*first, *second);
|
||||
|
||||
auto opened = Void::Security::open_secret(*first, *key);
|
||||
Void::Testing::require(opened.has_value());
|
||||
Void::Testing::expect_eq(*opened, plaintext);
|
||||
}
|
||||
|
||||
Test sealed_secrets_reject_tampering_and_wrong_keys()
|
||||
{
|
||||
auto key = Void::Security::random_secret_key();
|
||||
auto wrong = Void::Security::random_secret_key();
|
||||
Void::Testing::require(key.has_value());
|
||||
Void::Testing::require(wrong.has_value());
|
||||
const std::vector<unsigned char> plaintext{'t', 'o', 'k', 'e',
|
||||
'n'};
|
||||
auto envelope = Void::Security::seal_secret(plaintext, *key);
|
||||
Void::Testing::require(envelope.has_value());
|
||||
|
||||
auto wrong_key = Void::Security::open_secret(*envelope, *wrong);
|
||||
Void::Testing::expect(!wrong_key.has_value());
|
||||
envelope->back() ^= 0x01U;
|
||||
auto tampered = Void::Security::open_secret(*envelope, *key);
|
||||
Void::Testing::expect(!tampered.has_value());
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
Reference in new issue
Block a user