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(VoidCryptoAsyncOnlyConsumer LANGUAGES CXX)
|
||||
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS CryptoAsync)
|
||||
|
||||
add_executable(void_crypto_async_only_consumer main.cpp)
|
||||
target_link_libraries(void_crypto_async_only_consumer PRIVATE Void::CryptoAsync)
|
||||
target_compile_features(void_crypto_async_only_consumer PRIVATE cxx_std_26)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME CryptoAsyncOnlyConsumer COMMAND void_crypto_async_only_consumer)
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <Void/Async/Executor.hpp>
|
||||
#include <Void/Crypto/AsyncHash.hpp>
|
||||
#include <Void/IO/Driver.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
Void::Async::ManualExecutor exec;
|
||||
auto drv = Void::IO::Driver::create(exec);
|
||||
if (!drv.has_value()) {
|
||||
return 1;
|
||||
}
|
||||
Void::CryptoAsync::AsyncFileHasher hasher{exec};
|
||||
if (hasher.stats().active != 0) {
|
||||
return 2;
|
||||
}
|
||||
(void)hasher.close_and_join();
|
||||
(void)(*drv)->shutdown_and_join();
|
||||
return 0;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -161,6 +161,24 @@ if(_has_log)
|
||||
run_consumer(LogOnly "${install_prefix}" "LogOnly" ${_no_external_deps})
|
||||
endif()
|
||||
|
||||
has_modules(_has_crypto Crypto Functional)
|
||||
if(_has_crypto)
|
||||
run_consumer(CryptoOnly "${install_prefix}" "CryptoOnly"
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_LibArchive=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE)
|
||||
endif()
|
||||
|
||||
has_modules(_has_crypto_async CryptoAsync Crypto IO Async Time Functional)
|
||||
if(_has_crypto_async)
|
||||
run_consumer(CryptoAsyncOnly "${install_prefix}" "CryptoAsyncOnly"
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_LibArchive=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE)
|
||||
endif()
|
||||
|
||||
# Foundation consumer with Core-formatting bridge and zero external packages.
|
||||
has_modules(_has_foundation Math Text Time Functional Binary FunctionalCoreFormatting Memory Core)
|
||||
if(_has_foundation)
|
||||
|
||||
Reference in new issue
Block a user