pub struct EventHash(/* private fields */);Expand description
A 20-byte hash identifying a KEL event.
Serializes as a 40-character lowercase hex string, matching the encoding
used by git2::Oid::to_string(). This ensures JSON payloads, API schemas,
and cache files remain compatible when migrating from git2::Oid.
§Args
The inner [u8; 20] represents the raw SHA-1 bytes.
§Usage
use auths_core::witness::EventHash;
// From raw bytes
let bytes = [0u8; 20];
let hash = EventHash::from_bytes(bytes);
assert_eq!(hash.as_bytes(), &bytes);
// From hex string
let hash = EventHash::from_hex("0000000000000000000000000000000000000001").unwrap();
assert_eq!(hash.to_hex(), "0000000000000000000000000000000000000001");
// Serde: serializes as hex string, not integer array
let json = serde_json::to_string(&hash).unwrap();
assert_eq!(json, r#""0000000000000000000000000000000000000001""#);Implementations§
Source§impl EventHash
impl EventHash
Sourcepub const fn from_bytes(bytes: [u8; 20]) -> Self
pub const fn from_bytes(bytes: [u8; 20]) -> Self
Create an EventHash from raw bytes.
Sourcepub fn from_hex(s: &str) -> Option<Self>
pub fn from_hex(s: &str) -> Option<Self>
Create an EventHash from a hex string.
Returns None if the string is not exactly 40 hex characters.
§Example
use auths_core::witness::EventHash;
let hash = EventHash::from_hex("0123456789abcdef0123456789abcdef01234567");
assert!(hash.is_some());
// Wrong length
assert!(EventHash::from_hex("0123").is_none());
// Invalid characters
assert!(EventHash::from_hex("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz").is_none());Sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Convert this hash to a lowercase hex string.
§Example
use auths_core::witness::EventHash;
let hash = EventHash::from_bytes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
assert_eq!(hash.to_hex(), "000102030405060708090a0b0c0d0e0f10111213");Trait Implementations§
Source§impl<'de> Deserialize<'de> for EventHash
impl<'de> Deserialize<'de> for EventHash
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Copy for EventHash
impl Eq for EventHash
impl StructuralPartialEq for EventHash
Auto Trait Implementations§
impl Freeze for EventHash
impl RefUnwindSafe for EventHash
impl Send for EventHash
impl Sync for EventHash
impl Unpin for EventHash
impl UnsafeUnpin for EventHash
impl UnwindSafe for EventHash
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
Mutably borrows from an owned value. Read more