Skip to main content

Crate gix_hash

Crate gix_hash 

Source
Expand description

This crate provides types for identifying git objects using a hash digest.

These are provided in borrowed versions as well as an owned one.

§Examples

use gix_hash::{hasher, Kind, ObjectId, Prefix};

let id = ObjectId::from_hex(b"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391").unwrap();
assert_eq!(id.kind(), Kind::Sha1);
assert!(id.is_empty_blob());

let prefix = Prefix::new(&id, 7).unwrap();
assert_eq!(prefix.to_string(), "e69de29");

let mut digest = hasher(Kind::Sha1);
digest.update(id.as_slice());
let hashed_bytes = digest.try_finalize().unwrap();
assert_eq!(hashed_bytes.kind(), Kind::Sha1);
assert_ne!(hashed_bytes, id);

§Feature Flags

  • sha1 — Support for SHA1 hashes and digests.
  • sha256 — Support for SHA256 hashes and digests.
  • serde — Data structures implement serde::Serialize and serde::Deserialize.
  • bstr — Enable comparisons between ObjectId and bstr types.

Modules§

change_id
JJ-compatible change identifiers and their reverse-hex formatting.
decode
hasher
Hash functions and hash utilities
io
Error types for utility hash functions
prefix
Object ID prefixes and their parsing and comparison.
verify
Object ID verification.

Structs§

ChangeId
An object hash used as stable identifier for a change.
Prefix
A partial, owned hash possibly identifying an object uniquely, whose non-prefix bytes are zeroed.
oid
A borrowed reference to a hash identifying objects.

Enums§

Error
The error returned when trying to convert a byte slice to an oid or ObjectId
Hasher
Hash implementations that can be used once.
Kind
Denotes the kind of function to produce a ObjectId.
ObjectId
An owned hash identifying objects, most commonly Sha1

Functions§

bytes
Similar to bytes_of_file, but operates on a stream of bytes.
bytes_of_file
Compute the hash of kind for the bytes in the file at path, hashing only the first num_bytes_from_start while initializing and calling progress.
bytes_with_hasher
Similar to bytes(), but takes a hasher instead of a hash kind.
hasher
Produce a hasher suitable for the given kind of hash.