55 lines
2.5 KiB
C++
55 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <filesystem>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace Void::Build::Provenance {
|
|
|
|
// Ed25519 package-signing primitives. Every operation fails closed with an
|
|
// explicit error when the linked Void::Crypto has no usable Ed25519 backend
|
|
// (OpenSSL or the built-in implementation).
|
|
[[nodiscard]] bool signing_available() noexcept;
|
|
|
|
// Writes a fresh random 32-byte Ed25519 seed as 64 lowercase hex characters
|
|
// plus a trailing newline, creating the file owner read/write only (0600).
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
generate_signing_seed(const std::filesystem::path &seed_path);
|
|
|
|
// Derives the 32-byte Ed25519 public key (64 lowercase hex characters) from a
|
|
// seed file holding exactly 64 hex characters plus optional trailing whitespace.
|
|
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
|
public_key_from_seed(const std::filesystem::path &seed_path);
|
|
|
|
// Signs arbitrary exact message bytes and returns 128 lowercase hex characters.
|
|
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
|
sign_message(std::span<const std::byte> message, const std::filesystem::path &seed_path);
|
|
|
|
// Verifies a detached signature over arbitrary exact message bytes.
|
|
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
|
|
verify_message(std::span<const std::byte> message, std::string_view signature_hex,
|
|
std::string_view public_key_hex);
|
|
|
|
// Canonical package message signed by vbs:
|
|
// "vbs-package-v1\n<name>@<version>\nsha256:<digest-hex>\n"
|
|
[[nodiscard]] std::string canonical_package_message(std::string_view name, std::string_view version,
|
|
std::string_view sha256_hex);
|
|
|
|
// Detached Ed25519 signature (128 lowercase hex characters) over the canonical message.
|
|
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
|
sign_package(std::string_view name, std::string_view version, std::string_view sha256_hex,
|
|
const std::filesystem::path &seed_path);
|
|
|
|
// Verifies a detached signature over the canonical message. Well-formed but invalid
|
|
// signatures return false; malformed hex, key, or signature sizes return an error.
|
|
[[nodiscard]] Void::Result::Result<bool, Void::Result::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);
|
|
|
|
} // namespace Void::Build::Provenance
|