Skip to main content

mkit_core/
lib.rs

1//! mkit-core — BLAKE3 hashing and canonical v1 object byte format.
2//!
3//! The byte layout implemented here is defined, normatively, in
4//! `docs/SPEC-OBJECTS.md` (version `0x01`, magic `"MKT1"`). Any change
5//! to this crate MUST update the spec in the same PR.
6//!
7//! The library depends on `std` to keep the code readable. No `serde`,
8//! no `anyhow`, no panics on unchecked input.
9
10// `deny(unsafe_code)` rather than `forbid` so a single, justified
11// `#[allow(unsafe_code)]` callsite can use `libc::geteuid()` in
12// `sign::load_key` for the POSIX uid check. Every other module
13// remains under the same prohibition; a code-review gate (CONTRIBUTING)
14// requires SAFETY notes on any new `unsafe` block.
15#![deny(unsafe_code)]
16// `ed25519-dalek` v2.2 still pulls in older sha2/cpufeatures (and
17// rand_core 0.6 which transitively wants getrandom 0.2). These are
18// transitive duplicates we cannot dedupe without forking dalek; allow
19// them. cargo-deny still tracks them at warn level via deny.toml.
20#![allow(clippy::multiple_crate_versions)]
21
22pub mod batch;
23pub mod chunker;
24pub mod delta;
25pub mod hash;
26pub mod object;
27pub mod ops;
28pub mod pack;
29// Erasure-coded pack delivery (Reed-Solomon). Feature-gated because
30// the dep stack (`commonware-coding` + `commonware-cryptography` +
31// `commonware-parallel` + `commonware-storage`) is large and only
32// needed by the shard-aware transports — see
33// `docs/SPEC-PACK-SHARDS.md`. Sibling of `pack`, not nested: the
34// on-disk pack format stays untouched; shards are a wire-level
35// encoding *of* a pack.
36#[cfg(feature = "pack-shards")]
37pub mod pack_shard;
38pub mod serialize;
39pub mod sign;
40pub mod store;
41
42// Phase 4 — refs + index + worktree + ignore + repo_lock.
43pub(crate) mod atomic;
44pub mod ignore;
45pub mod index;
46pub mod refs;
47pub mod repo_lock;
48pub mod worktree;
49
50// Phase 7a — transport trait surface (vtable + SSH framing + retry policy).
51pub mod protocol;
52
53// Phase 1 of issue #157 — append-only MMR over the commit chain for
54// O(log n) inclusion proofs. Feature-gated so the `commonware-storage`
55// dep tree only materialises for downstream callers that opt in.
56// Persisted (journaled) MMR + commit-field integration are Phase 2/3
57// — see docs/SPEC-HISTORY-PROOF.md.
58#[cfg(feature = "history-mmr")]
59pub mod history;
60
61// Verifiable sparse-checkout (issue #158, Phase 2). Feature-gated
62// because the upstream `commonware-storage::AuthenticatedBitMap` is
63// ALPHA-tier and pulls in `commonware-runtime` /
64// `commonware-cryptography`. Off by default.
65#[cfg(feature = "sparse-checkout")]
66pub mod sparse;
67
68#[cfg(feature = "sparse-checkout")]
69pub use sparse::{
70    MAX_FILTER_PATHS as SPARSE_MAX_FILTER_PATHS, MAX_LEAVES as SPARSE_MAX_LEAVES, SPARSE_CACHE_DIR,
71    SPARSE_CACHE_MAGIC, SPARSE_CACHE_VERSION, SPARSE_WIRE_MAGIC, SPARSE_WIRE_MAX_BYTES,
72    SPARSE_WIRE_VERSION, SparseError, SparseManifest, SparseProof, SparseResponse, SparseWireError,
73    build_sparse, decode_sparse_cache, decode_sparse_response, encode_sparse_cache,
74    encode_sparse_response, hash_filter, verify_sparse,
75};
76
77pub use hash::{HASH_LEN, HEX_LEN, Hash, Hasher, to_hex, to_hex_bytes};
78pub use object::{
79    Blob, ChunkedBlob, Commit, Delta, EntryMode, IDENTITY_MAX_LEN, Identity, IdentityKind, MAGIC,
80    MkitError, Object, ObjectType, Remix, RemixSource, SCHEMA_VERSION, TAG_NAME_MAX_LEN, Tag, Tree,
81    TreeEntry,
82};
83pub use serialize::{deserialize, serialize};
84pub use sign::{
85    COMMIT_DOMAIN, KeyPair, PublicKey, REMIX_DOMAIN, SecretSeed, Signature, TAG_DOMAIN,
86    commit_signing_bytes, commit_signing_hash, remix_signing_bytes, remix_signing_hash,
87    sign_commit, sign_remix, sign_tag, tag_signing_bytes, tag_signing_hash, verify, verify_commit,
88    verify_remix, verify_tag,
89};
90pub use store::{
91    MAX_RAW_OBJECT_SIZE, MAX_TREE_DEPTH, MKIT_DIR, OBJECTS_DIR, ObjectStore, StoreError,
92    StoreResult,
93};
94
95// Phase 3 — content-defined chunker (FastCDC v1).
96pub use chunker::{
97    AVG_SIZE as CHUNK_AVG_SIZE, ChunkBoundary, ChunkIterator, FastCdc, MASK_L as CHUNK_MASK_L,
98    MASK_S as CHUNK_MASK_S, MAX_SIZE as CHUNK_MAX_SIZE, MIN_SIZE as CHUNK_MIN_SIZE,
99    SEED as CHUNK_SEED, chunk_boundaries, gear_table_digest,
100};
101
102// Phase 3 — delta instruction stream (SPEC-DELTA v1).
103pub use delta::{HEADER_LEN as DELTA_HEADER_LEN, MAX_INSERT_LEN, OP_COPY, STREAM_VERSION};
104
105// Phase 3 — packfile reader/writer (SPEC-PACKFILE v1).
106pub use pack::{
107    HEADER_LEN as PACK_HEADER_LEN, MAGIC as PACK_MAGIC, MAX_ENTRIES as PACK_MAX_ENTRIES,
108    MAX_TOTAL_PAYLOAD as PACK_MAX_TOTAL_PAYLOAD, PackError, PackReader, PackWriter,
109    TRAILER_LEN as PACK_TRAILER_LEN, UnpackReport, VERSION as PACK_VERSION, pack_key,
110};
111
112// Phase 4 — refs + index + worktree + ignore + repo_lock.
113pub use ignore::{IgnoreError, IgnoreList, MAX_IGNORE_FILE_BYTES, Pattern, glob_match};
114pub use index::{
115    EntryStatus, INDEX_FILE, Index, IndexEntry, IndexError, IndexResult, MAGIC as INDEX_MAGIC,
116    MAX_INDEX_BYTES, MAX_PATH_LEN, validate_index_path,
117};
118pub use refs::{
119    HEAD_FILE, HEADS_DIR, Head, REFS_DIR, Ref, RefError, RefResult, RefWriteCondition,
120    SHALLOW_FILE, TAGS_DIR, decode_ref_wire, encode_ref_wire, validate_ref_name,
121    validate_ref_prefix,
122};
123pub use repo_lock::{DEFAULT_TIMEOUT as LOCK_DEFAULT_TIMEOUT, LockError, LockResult, RepoLock};
124pub use worktree::{
125    CHUNK_THRESHOLD, MAX_FILE_BYTES, WorktreeError, WorktreeResult, read_blob, store_file_object,
126    validate_symlink_target,
127};
128
129// Cross-transport types. The SSH-specific wire bytes live in
130// mkit-rpc's ssh.proto and are consumed by mkit-transport-ssh
131// directly.
132pub use protocol::{
133    BACKOFF_CAP, BACKOFF_INITIAL, BACKOFF_MAX_ATTEMPTS, BackoffIterator, PackKey, Transport,
134    TransportError, TransportResult, is_retryable, pack_key_from_hex,
135};
136
137// Phase 5 — ops re-exports (OPS1: diff/graph/merge/cherry_pick).
138// OPS2's rebase/bisect/blame/stash/restore are accessed via
139// `mkit_core::ops::{rebase, bisect, ...}` directly rather than re-exported
140// at the crate root — the submodule is typically the right import scope
141// for state-machine APIs.
142pub use ops::{
143    CherryPickError, CherryPickResult, Conflict, ConflictKind, DiffEntry, DiffError, DiffKind,
144    DiffResult, MergeResult, StatusEntry, StatusStaging, cherry_pick, collect_ancestor_set,
145    diff_trees, find_merge_base, is_ancestor, merge_trees, status_diff,
146};