diff options
Diffstat (limited to 'src/db')
| -rw-r--r-- | src/db/model.rs | 9 | ||||
| -rw-r--r-- | src/db/queries.rs | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/db/model.rs b/src/db/model.rs index 07065c5..e962d6f 100644 --- a/src/db/model.rs +++ b/src/db/model.rs @@ -58,11 +58,14 @@ impl Identity { /// The hash that makes I3 a fact: two byte-identical inputs never produce /// two candidates, and any change to what becomes a byte in the artifact /// produces a new one. + /// /// A digest of the canonical JSON of the identity tuple. This is the value /// an approval must echo: two candidates share an `identity_hash` only if - /// every pin, digest and version in them is identical. - pub fn hash(&self) -> String { - format!("sha256:{}", hash::hex(hash::canonical_json(self).as_bytes())) + /// every pin, digest and version in them is identical. A value that cannot + /// be serialized is an error rather than a digest — a shared fallback digest + /// would be the one way two identities could collide by accident. + pub fn hash(&self) -> crate::error::Result<String> { + Ok(format!("sha256:{}", hash::hex(hash::canonical_json(self)?.as_bytes()))) } } diff --git a/src/db/queries.rs b/src/db/queries.rs index fa530b4..ca73e5f 100644 --- a/src/db/queries.rs +++ b/src/db/queries.rs @@ -833,7 +833,7 @@ pub fn put_world_snapshot(writer: &Writer, members: &[WorldMember]) -> Result<i6 let mut sorted = members.to_vec(); sorted.sort(); sorted.dedup(); - let hash = crate::hash::canonical_json(&sorted); + let hash = crate::hash::canonical_json(&sorted)?; let json = serde_json::to_string(&sorted)?; let at = time::now(); writer.tx(move |tx| { |
