feat(crypto,archive): implement VL-007 built-in hashes and VL-006 archive creation/gzip/tar fallback
This commit is contained in:
1 parent
b50131f52e
commit
22c8538754
19 files changed
+3326
-133
No files matched your search
@@ -29,9 +29,14 @@ namespace Void::Archive
|
||||
std::uint64_t bytes{0};
|
||||
};
|
||||
|
||||
/// Extract a tar/tar.zst archive incrementally into `destination` without
|
||||
/// invoking an external process. Preserved 1.x incremental API; callers
|
||||
/// requiring all-or-nothing directory visibility should use
|
||||
/// Returns true if Void::Archive was built with LibArchive support (required
|
||||
/// for .tar.zst and .tar.gz compression/decompression; uncompressed USTAR/PAX
|
||||
/// .tar reading and writing work with zero external dependencies).
|
||||
[[nodiscard]] bool has_libarchive_backend() noexcept;
|
||||
|
||||
/// Extract a tar/tar.gz/tar.zst archive incrementally into `destination`
|
||||
/// without invoking an external process. Preserved 1.x incremental API;
|
||||
/// callers requiring all-or-nothing directory visibility should use
|
||||
/// `extract_staged` + `StagedTree::publish`.
|
||||
[[nodiscard]] Void::Result::Result<ExtractionResult>
|
||||
extract(const std::filesystem::path& archivePath,
|
||||
@@ -177,9 +182,9 @@ namespace Void::Archive
|
||||
std::chrono::seconds min_age =
|
||||
std::chrono::seconds{300});
|
||||
|
||||
/// Create a bounded, optionally reproducible tar or tar.zst archive from
|
||||
/// regular file and directory entries. Sorts normalized paths, rejects
|
||||
/// duplicates/conflicts, and opens source files with O_NOFOLLOW.
|
||||
/// Create a bounded, optionally reproducible tar, tar.gz, or tar.zst
|
||||
/// archive from regular file and directory entries. Sorts normalized
|
||||
/// paths, rejects duplicates/conflicts, and opens source files with O_NOFOLLOW.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
create_archive(ByteSink& sink, std::span<const CreateEntry> entries,
|
||||
const CreationOptions& options = {});
|
||||
@@ -189,6 +194,16 @@ namespace Void::Archive
|
||||
std::span<const CreateEntry> entries,
|
||||
const CreationOptions& options = {});
|
||||
|
||||
/// Canonical snake_case alias for `create_archive`.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
create(ByteSink& sink, std::span<const CreateEntry> entries,
|
||||
const CreationOptions& options = {});
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
create(const std::filesystem::path& output_path,
|
||||
std::span<const CreateEntry> entries,
|
||||
const CreationOptions& options = {});
|
||||
|
||||
/// Hardened untrusted-input profile: extracts the archive in an isolated
|
||||
/// System child process with bounded execution time and RSS checks, then
|
||||
/// independently verifies the staged tree and inventory in the parent
|
||||
|
||||
@@ -175,13 +175,17 @@ namespace Void::Archive
|
||||
ProgressCallback on_progress{};
|
||||
};
|
||||
|
||||
enum class ArchiveCompression : std::uint8_t { None = 0, Zstd };
|
||||
enum class ArchiveCompression : std::uint8_t { None = 0, Zstd, Gzip };
|
||||
|
||||
struct CreationOptions {
|
||||
ArchiveCompression compression{ArchiveCompression::Zstd};
|
||||
bool reproducible{true};
|
||||
ReadLimits limits{};
|
||||
std::stop_token stop{};
|
||||
std::int64_t canonical_mtime{0};
|
||||
std::uint32_t canonical_uid{0};
|
||||
std::uint32_t canonical_gid{0};
|
||||
bool prefer_builtin_tar{false};
|
||||
};
|
||||
|
||||
struct CreateEntry {
|
||||
@@ -190,6 +194,7 @@ namespace Void::Archive
|
||||
bool executable{false};
|
||||
std::vector<std::byte> content{};
|
||||
std::optional<std::filesystem::path> source_file{};
|
||||
std::optional<std::uint32_t> mode{};
|
||||
};
|
||||
|
||||
struct IsolationOptions {
|
||||
|
||||
@@ -13,9 +13,14 @@
|
||||
|
||||
namespace Void::Crypto
|
||||
{
|
||||
enum class HashAlgorithm { Sha1, Sha256, Sha512 };
|
||||
enum class HashAlgorithm { Sha1, Sha256, Sha512, Blake2b256, Blake2b512 };
|
||||
using Digest = std::vector<std::byte>;
|
||||
|
||||
/// Returns true if Void::Crypto was built with OpenSSL support (required
|
||||
/// for Ed25519; hashing/HMAC/HKDF work on the built-in pure-C++ backend
|
||||
/// with zero external dependencies).
|
||||
[[nodiscard]] bool has_openssl_backend() noexcept;
|
||||
|
||||
class Hasher
|
||||
{
|
||||
public:
|
||||
@@ -60,6 +65,11 @@ namespace Void::Crypto
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
hashFile(HashAlgorithm algorithm, const std::filesystem::path& path,
|
||||
const ProviderOptions& provider);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
hash_file(HashAlgorithm algorithm, const std::filesystem::path& path);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
hash_file(HashAlgorithm algorithm, const std::filesystem::path& path,
|
||||
const ProviderOptions& provider);
|
||||
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
sha1(std::span<const std::byte> data);
|
||||
@@ -70,12 +80,29 @@ namespace Void::Crypto
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
sha512(std::span<const std::byte> data);
|
||||
[[nodiscard]] Void::Result::Result<Digest> sha512(std::string_view data);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
blake2b256(std::span<const std::byte> data);
|
||||
[[nodiscard]] Void::Result::Result<Digest> blake2b256(std::string_view data);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
blake2b512(std::span<const std::byte> data);
|
||||
[[nodiscard]] Void::Result::Result<Digest> blake2b512(std::string_view data);
|
||||
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
sha1File(const std::filesystem::path& path);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
sha256File(const std::filesystem::path& path);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
sha512File(const std::filesystem::path& path);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
sha1_file(const std::filesystem::path& path);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
sha256_file(const std::filesystem::path& path);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
sha512_file(const std::filesystem::path& path);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
blake2b256_file(const std::filesystem::path& path);
|
||||
[[nodiscard]] Void::Result::Result<Digest>
|
||||
blake2b512_file(const std::filesystem::path& path);
|
||||
|
||||
/// Move-only owning Ed25519 private key handle. Has no implicit copy,
|
||||
/// string conversion, or secret formatting.
|
||||
|
||||
@@ -111,10 +111,11 @@ namespace Void::Crypto
|
||||
MovedFrom
|
||||
};
|
||||
|
||||
/// Per-operation OpenSSL 3 provider selection. Never mutates process-wide
|
||||
/// Per-operation backend/provider selection. Never mutates process-wide
|
||||
/// provider state.
|
||||
struct ProviderOptions {
|
||||
std::string property_query{};
|
||||
bool prefer_builtin{false};
|
||||
};
|
||||
|
||||
struct Ed25519PublicKey {
|
||||
|
||||
Reference in new issue
Block a user