Identify the exact stored knowledge revision, not only its Markdown body. Length-prefixing keeps the hash input unambiguous while preserving the raw stored frontmatter as part of the revision contract.
(entry: &VaultEntry)
| 682 | /// Length-prefixing keeps the hash input unambiguous while preserving the raw |
| 683 | /// stored frontmatter as part of the revision contract. |
| 684 | fn vault_revision_hash(entry: &VaultEntry) -> String { |
| 685 | let mut bytes = b"atomic-vault-revision-v1".to_vec(); |
| 686 | append_hash_field(&mut bytes, entry.entry_type.as_str().as_bytes()); |
| 687 | append_hash_field(&mut bytes, entry.frontmatter_json.as_bytes()); |
| 688 | append_hash_field(&mut bytes, &entry.content_bytes); |
| 689 | Hash::of(&bytes).to_base32() |
| 690 | } |
| 691 | |
| 692 | fn append_hash_field(target: &mut Vec<u8>, value: &[u8]) { |
| 693 | target.extend_from_slice(&(value.len() as u64).to_be_bytes()); |
no test coverage detected