pub enum GitHash {
Sha1([u8; 20]),
Sha256([u8; 32]),
}Expand description
A Git object hash - either SHA1 (legacy) or SHA256 (modern)
Git traditionally uses SHA1 (20 bytes / 40 hex chars) for object hashes. Modern git supports SHA256 (32 bytes / 64 hex chars) but tooling support varies. This enum supports both, auto-detecting by length when parsing.
For DHT storage, use to_dht_key() which derives a 256-bit key with domain
separation per the libp2p Kademlia spec.
Variants§
Sha1([u8; 20])
SHA1 hash (20 bytes / 40 hex chars) - legacy git format
Sha256([u8; 32])
SHA256 hash (32 bytes / 64 hex chars) - modern git format
Implementations§
Source§impl GitHash
impl GitHash
Sourcepub fn from_hex(s: &str) -> Result<Self>
pub fn from_hex(s: &str) -> Result<Self>
Parse from hex string (auto-detects algorithm by length)
- 40 hex chars -> SHA1
- 64 hex chars -> SHA256
- Other lengths -> Error
Sourcepub fn from_sha1_bytes(bytes: [u8; 20]) -> Self
pub fn from_sha1_bytes(bytes: [u8; 20]) -> Self
Create from raw SHA1 bytes
Sourcepub fn from_sha256_bytes(bytes: [u8; 32]) -> Self
pub fn from_sha256_bytes(bytes: [u8; 32]) -> Self
Create from raw SHA256 bytes
Sourcepub fn to_dht_key(&self) -> [u8; 32]
pub fn to_dht_key(&self) -> [u8; 32]
Derive DHT key using domain separation per libp2p Kademlia spec
The DHT key is: sha256(DOMAIN_PREFIX || RAW_HASH_BYTES)
This ensures:
- Both SHA1 and SHA256 hashes map to 256-bit DHT keys
- Keys are in separate DHT namespaces (no collisions)
- Forward-compatible when git switches to SHA256
Sourcepub fn object_format(&self) -> ObjectFormat
pub fn object_format(&self) -> ObjectFormat
Object format (hash algorithm) this hash belongs to.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for GitHash
impl<'de> Deserialize<'de> for GitHash
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&GitHash> for ObjectFormat
impl From<&GitHash> for ObjectFormat
impl Eq for GitHash
impl StructuralPartialEq for GitHash
Auto Trait Implementations§
impl Freeze for GitHash
impl RefUnwindSafe for GitHash
impl Send for GitHash
impl Sync for GitHash
impl Unpin for GitHash
impl UnsafeUnpin for GitHash
impl UnwindSafe for GitHash
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more