feat(provenance): probe built-in Ed25519 capability (VoidLibrary #52 follow-up)
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 9s

This commit is contained in:
faumaray committed 2026-12-03 18:16:36 +03:00
1 parent 55272d3e6b
commit a02d2b0d5d
6 files changed
+52 -16

No files matched your search

+24 -10
View File
@@ -33,16 +33,16 @@ constexpr std::size_t SeedHexLength = 64;
constexpr std::size_t PublicKeyHexLength = 64;
constexpr std::size_t SignatureHexLength = 128;
constexpr std::size_t MaxSeedFileBytes = 4096;
constexpr std::string_view OpenSslRequirement =
"Ed25519 package signing requires the OpenSSL backend of Void::Crypto";
constexpr std::string_view Ed25519Requirement =
"Ed25519 package signing is unavailable in the linked Void::Crypto backend";
Error make_error(ErrorKind kind, std::string message) { return Error{kind, std::move(message)}; }
Result<void, Error> require_openssl_backend() {
if (Void::Crypto::has_openssl_backend()) {
Result<void, Error> require_signing_backend() {
if (signing_available()) {
return {};
}
return std::unexpected{make_error(ErrorKind::unsupported, std::string{OpenSslRequirement})};
return std::unexpected{make_error(ErrorKind::unsupported, std::string{Ed25519Requirement})};
}
bool is_hex_digit(char c) noexcept {
@@ -256,10 +256,24 @@ Result<void, Error> write_private_file(const std::filesystem::path &path,
} // namespace
bool signing_available() noexcept { return Void::Crypto::has_openssl_backend(); }
bool signing_available() noexcept {
// Probe the actual Ed25519 capability instead of assuming OpenSSL: Void::Crypto may provide
// a built-in Ed25519 backend when OpenSSL is absent.
static const bool available = []() noexcept {
std::array<std::byte, Void::Crypto::Ed25519SeedSize> seed{};
seed.fill(std::byte{0x42});
auto key = Void::Crypto::Ed25519PrivateKey::from_raw_seed(seed);
if (!key) {
return false;
}
constexpr std::array<std::byte, 1> message{std::byte{0x01}};
return Void::Crypto::sign_ed25519(message, *key).has_value();
}();
return available;
}
Result<void, Error> generate_signing_seed(const std::filesystem::path &seed_path) {
if (auto backend = require_openssl_backend(); !backend) {
if (auto backend = require_signing_backend(); !backend) {
return backend;
}
@@ -279,7 +293,7 @@ Result<void, Error> generate_signing_seed(const std::filesystem::path &seed_path
}
Result<std::string, Error> public_key_from_seed(const std::filesystem::path &seed_path) {
if (auto backend = require_openssl_backend(); !backend) {
if (auto backend = require_signing_backend(); !backend) {
return std::unexpected{backend.error()};
}
@@ -315,7 +329,7 @@ std::string canonical_package_message(std::string_view name, std::string_view ve
Result<std::string, Error> sign_package(std::string_view name, std::string_view version,
std::string_view sha256_hex,
const std::filesystem::path &seed_path) {
if (auto backend = require_openssl_backend(); !backend) {
if (auto backend = require_signing_backend(); !backend) {
return std::unexpected{backend.error()};
}
@@ -340,7 +354,7 @@ Result<std::string, Error> sign_package(std::string_view name, std::string_view
Result<bool, Error> verify_package(std::string_view name, std::string_view version,
std::string_view sha256_hex, std::string_view signature_hex,
std::string_view public_key_hex) {
if (auto backend = require_openssl_backend(); !backend) {
if (auto backend = require_signing_backend(); !backend) {
return std::unexpected{backend.error()};
}