Skip to main content

qualia_core_db/net/qdnf/fixtures/
ids.rs

1//! FND-03.01 compile-time size/role table (PARTIAL).
2//!
3//! Short hashes are lookup indexes. They never authorize delivery.
4
5use crate::net::qdnf::types::{Generation, LinkId, OperationId, QHashIndex, StrongDigest};
6
7/// SHA-384 / `StrongDigest` byte length. Full security identifier.
8pub const STRONG_DIGEST_LEN: usize = 48;
9
10/// Compact `QHashIndex` byte length. Lookup only.
11pub const QHASH_INDEX_LEN: usize = 8;
12
13/// Short hashes are never proofs or authority.
14#[inline]
15pub fn short_hash_is_authority() -> bool {
16    false
17}
18
19/// True when the typed identifiers keep the FND-03.01 size table.
20#[inline]
21pub fn digest_sizes_match_types() -> bool {
22    core::mem::size_of::<StrongDigest>() == STRONG_DIGEST_LEN
23        && core::mem::size_of::<QHashIndex>() == QHASH_INDEX_LEN
24        && core::mem::size_of::<Generation>() == 8
25        && core::mem::size_of::<OperationId>() == 16
26        && core::mem::size_of::<LinkId>() == 16
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn digest_size_table_matches_types() {
35        assert!(digest_sizes_match_types());
36        assert_eq!(core::mem::size_of::<StrongDigest>(), 48);
37        assert_eq!(core::mem::size_of::<QHashIndex>(), 8);
38        assert_eq!(core::mem::size_of::<Generation>(), 8);
39        assert_eq!(core::mem::size_of::<OperationId>(), 16);
40        assert_eq!(core::mem::size_of::<LinkId>(), 16);
41        assert_ne!(STRONG_DIGEST_LEN, QHASH_INDEX_LEN);
42    }
43
44    #[test]
45    fn short_hash_is_lookup_index_only() {
46        assert!(!short_hash_is_authority());
47    }
48}