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, doc_auto_cfg))]
10#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
11
12#[path = "oid.rs"]
13mod borrowed;
14pub use borrowed::{oid, Error};
15
16/// Hash functions and hash utilities
17pub mod hasher;
18pub use hasher::_impl::{hasher, Hasher};
19
20/// Error types for utility hash functions
21pub mod io;
22pub use io::_impl::{bytes, bytes_of_file, bytes_with_hasher};
23
24mod object_id;
25pub use object_id::{decode, ObjectId};
26
27///
28pub mod prefix;
29
30///
31pub mod verify;
32
33/// A partial, owned hash possibly identifying an object uniquely, whose non-prefix bytes are zeroed.
34///
35/// An example would `0000000000000000000000000000000032bd3242`, where `32bd3242` is the prefix,
36/// which would be able to match all hashes that *start with* `32bd3242`.
37#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy, Debug)]
38#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
39pub struct Prefix {
40    bytes: ObjectId,
41    hex_len: usize,
42}
43
44/// The size of a SHA1 hash digest in bytes.
45const SIZE_OF_SHA1_DIGEST: usize = 20;
46
47/// Denotes the kind of function to produce a [`ObjectId`].
48#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
49#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
50pub enum Kind {
51    /// The Sha1 hash with 160 bits.
52    #[default]
53    Sha1 = 1,
54}
55
56mod kind;