diff --git a/crates/idfoto-core/src/ids.rs b/crates/idfoto-core/src/ids.rs index 9da53a0..58c403e 100644 --- a/crates/idfoto-core/src/ids.rs +++ b/crates/idfoto-core/src/ids.rs @@ -31,6 +31,10 @@ impl ItemId { pub fn as_str(&self) -> &str { &self.0 } } +impl Default for ItemId { + fn default() -> Self { Self::new() } +} + impl FieldId { pub fn new() -> Self { let mut bytes = [0u8; 8]; @@ -40,6 +44,10 @@ impl FieldId { pub fn as_str(&self) -> &str { &self.0 } } +impl Default for FieldId { + fn default() -> Self { Self::new() } +} + impl AttachmentId { pub fn from_plaintext(plaintext: &[u8]) -> Self { let digest = Sha256::digest(plaintext); @@ -74,6 +82,14 @@ mod tests { assert!(id.0.chars().all(|c| c.is_ascii_hexdigit())); } + #[test] + fn field_ids_are_unique() { + let mut seen = std::collections::HashSet::new(); + for _ in 0..10_000 { + assert!(seen.insert(FieldId::new().0)); + } + } + #[test] fn attachment_id_is_deterministic() { let plaintext = b"hello world";