Skip to content

fidius-core::hash Rust

FNV-1a interface hashing for compile-time ABI drift detection.

The proc macro computes an interface_hash from the sorted required method signatures of a trait. The host checks this hash at load time to reject plugins compiled against a different interface.

Functions

fidius-core::hash::fnv1a

pub

const fn fnv1a (bytes : & [u8]) -> u64

Compute the FNV-1a 64-bit hash of a byte slice.

Source
pub const fn fnv1a(bytes: &[u8]) -> u64 {
    let mut hash = FNV_OFFSET_BASIS;
    let mut i = 0;
    while i < bytes.len() {
        hash ^= bytes[i] as u64;
        hash = hash.wrapping_mul(FNV_PRIME);
        i += 1;
    }
    hash
}

fidius-core::hash::interface_hash

pub

fn interface_hash (signatures : & [& str]) -> u64

Compute the interface hash from a set of method signatures.

Signatures are sorted lexicographically before hashing to ensure order-independence. Each signature is joined with \n as a separator. This function is not const because it allocates for sorting. The proc macro calls this at compile time via a build-script-like pattern, or uses fnv1a directly on pre-sorted, concatenated signatures.

Source
pub fn interface_hash(signatures: &[&str]) -> u64 {
    let mut sorted: Vec<&str> = signatures.to_vec();
    sorted.sort();
    let combined = sorted.join("\n");
    fnv1a(combined.as_bytes())
}