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