gix_hash/
lib.rs

1//! This crate provides types for identifying git objects using a hash digest.
2//!
3//! These are provided in [borrowed versions][oid] as well as an [owned one][ObjectId].
4//! ## Feature Flags
5#![cfg_attr(
6    all(doc, feature = "document-features"),
7    doc = ::document_features::document_features!()
8)]
9#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg))]
10#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
11
12// Remove this once other hashes (e.g., SHA-256, and potentially others)
13// are supported, and this crate can build without [`ObjectId::Sha1`].
14#[cfg(not(feature = "sha1"))]
15compile_error!("Please set the `sha1` feature flag");
16
17#[path = "oid.rs"]
18mod borrowed;
19pub use borrowed::{oid, Error};
20
21/// Hash functions and hash utilities
22pub mod hasher;
23pub use hasher::_impl::{hasher, Hasher};
24
25/// Error types for utility hash functions
26pub mod io;
27pub use io::_impl::{bytes, bytes_of_file, bytes_with_hasher};
28
29mod object_id;
30pub use object_id::{decode, ObjectId};
31
32///
33pub mod prefix;
34
35///
36pub mod verify;
37
38/// A partial, owned hash possibly identifying an object uniquely, whose non-prefix bytes are zeroed.
39///
40/// An example would `0000000000000000000000000000000032bd3242`, where `32bd3242` is the prefix,
41/// which would be able to match all hashes that *start with* `32bd3242`.
42#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy, Debug)]
43#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44pub struct Prefix {
45    bytes: ObjectId,
46    hex_len: usize,
47}
48
49/// The size of a SHA1 hash digest in bytes.
50const SIZE_OF_SHA1_DIGEST: usize = 20;
51
52/// Denotes the kind of function to produce a [`ObjectId`].
53#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
54#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
55#[non_exhaustive]
56pub enum Kind {
57    /// The Sha1 hash with 160 bits.
58    #[default]
59    Sha1 = 1,
60}
61
62mod kind;