feat(crypto): harden Crypto primitives and add optional CryptoAsync adapter
This commit is contained in:
1 parent
8a1c15f9c0
commit
eb42228604
14 files changed
+2448
-90
No files matched your search
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
project(VoidCryptoOnlyConsumer LANGUAGES CXX)
|
||||
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS Crypto)
|
||||
|
||||
add_executable(void_crypto_only_consumer main.cpp)
|
||||
target_link_libraries(void_crypto_only_consumer PRIVATE Void::Crypto)
|
||||
target_compile_features(void_crypto_only_consumer PRIVATE cxx_std_26)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME CryptoOnlyConsumer COMMAND void_crypto_only_consumer)
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <Void/Crypto/Crypto.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <span>
|
||||
|
||||
int main()
|
||||
{
|
||||
auto digest = Void::Crypto::sha256("abc");
|
||||
if (!digest.has_value() || digest->size() != 32) {
|
||||
return 1;
|
||||
}
|
||||
auto key = Void::Crypto::Ed25519PrivateKey::generate();
|
||||
if (!key.has_value()) {
|
||||
return 2;
|
||||
}
|
||||
auto pub = key->public_key();
|
||||
if (!pub.has_value()) {
|
||||
return 3;
|
||||
}
|
||||
const std::array<std::byte, 4> msg{std::byte{1}, std::byte{2}, std::byte{3},
|
||||
std::byte{4}};
|
||||
auto sig = Void::Crypto::sign_ed25519(msg, *key);
|
||||
if (!sig.has_value()) {
|
||||
return 4;
|
||||
}
|
||||
auto ok = Void::Crypto::verify_ed25519(msg, *sig, *pub);
|
||||
if (!ok.has_value() || !*ok) {
|
||||
return 5;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user