Expand description
Hash utilities for Git objects with selectable algorithms (SHA-1, SHA-256 and BLAKE3-256).
§Algorithms
Sha1(20 bytes / 40 hex) andSha256(32 bytes / 64 hex) follow the standard Git object formats.Blake3(32 bytes / 64 hex) is a git-internal / Libra extension: a repository created with it is a separate object namespace that standard Git does not understand. Because SHA-256 and BLAKE3 IDs have the same width, a 64-hex or 32-byte value can only be interpreted inside a known repositoryHashKindcontext (see the explicit-kind API below) or when it carries its algorithm tag (blake3:HEX); nothing in this module guesses BLAKE3 from a length.- BLAKE3 here is the repository object ID algorithm only. It does not
change
crate::internal::object::integrity::IntegrityHash(always SHA-256) or any application-level digest (Buck manifests, policy digests, HMACs).
§Thread-local default versus explicit HashKind
Two families of API live here:
- Thread-local compatibility wrappers —
ObjectHash::new,ObjectHash::from_type_and_data,ObjectHash::from_bytes,ObjectHash::from_streamandcrate::utils::HashAlgorithm::newread the thread-localHashKindset byset_hash_kind. They exist for the established single-repository workflow: configure the kind once at startup on the thread that does the work, then call the parameterless API. - Explicit-kind API —
ObjectHash::new_for_kind,ObjectHash::from_type_and_data_for_kind,ObjectHash::from_hex_for_kind,ObjectHash::from_bytes_for_kind,ObjectHash::from_stream_for_kind,ObjectHash::zero_for_kindandcrate::utils::HashAlgorithm::new_for_kindtake the repositoryHashKindas a parameter and never consult the thread-local. New code that runs on worker threads, async tasks, streams, caches, object loaders or protocol callbacks — anywhere the current thread may belong to another repository — must use this family and pass the kind of the repository it is operating on.
Raw hex IDs (Display, FromStr) stay Git-like: no algorithm prefix. The
legacy FromStr implementation infers SHA-1 for 40 hex characters and
SHA-256 for 64 hex characters purely from the length; it does not consult
the thread-local kind and must not be used where the repository format is
known. When an ID has to travel across repositories, APIs, logs or indexes
together with its algorithm, use the tagged representation
(sha1:HEX / sha256:HEX / blake3:HEX) via
ObjectHash::to_tagged_string and ObjectHash::from_tagged_str.
Every explicit-kind parser fails closed: a length, hex or kind mismatch is
reported through HashError (carrying the operation, the expected/actual
lengths and — whenever it can be determined — the requested kind) and never
silently falls back to another algorithm.
Hash kind is stored thread-locally; set once at startup to match your repository format. Defaults to SHA-1.
Structs§
- Hash
Kind Guard - A guard to reset the hash kind after the test
Enums§
- Archived
Hash Kind - An archived
HashKind - Archived
Object Hash - An archived
ObjectHash - Hash
Error - Errors produced by the explicit-kind
ObjectHashconstructors and parsers. - Hash
Kind - Supported hash algorithms for object IDs (selector only, no data attached). Used to configure which hash algorithm to use globally (thread-local). Defaults to SHA-1.
- Hash
Kind Resolver - The resolver for an archived
HashKind - Object
Hash - Concrete object ID value carrying the bytes for the selected algorithm (SHA-1, SHA-256 or BLAKE3-256). Used for Git object hashes. Supports conversion to/from hex strings, byte slices, and stream reading.
- Object
Hash Resolver - The resolver for an archived
ObjectHash
Functions§
- get_
hash_ kind - Retrieves the hash kind for the current thread.
- set_
hash_ kind - Set the thread-local hash kind (configure once at startup to match repo format).
- set_
hash_ kind_ for_ test - Sets the hash kind for the current thread and returns a guard to reset it later.