Module wdp

Module wdp 

Source
Expand description

WDP (Waddling Diagnostic Protocol) Conformant Hash Implementation

This module provides hash functions that are fully conformant with the WDP specification (Parts 5 and 7).

§WDP Part 5: Compact IDs

Error codes are hashed using xxHash3 with the seed 0x000031762D706477:

  • Input is normalized (trimmed and uppercased)
  • Output is 5 Base62 characters

§WDP Part 7: Namespaces

Namespaces are hashed using xxHash3 with a different seed 0x31762D736E706477:

  • This prevents collisions between namespace and code hashes
  • Combined format: namespace_hash-code_hash (e.g., h4tYw2-81E9g)

§Example

use waddling_errors_hash::wdp::{
    compute_wdp_hash,
    compute_wdp_namespace_hash,
    compute_wdp_full_id,
};

// Hash an error code (WDP Part 5)
let hash = compute_wdp_hash("E.Auth.Token.001");
assert_eq!(hash.len(), 5);

// Hash a namespace (WDP Part 7)
let ns_hash = compute_wdp_namespace_hash("auth_lib");
assert_eq!(ns_hash.len(), 5);

// Combined identifier (namespace_hash-code_hash)
let full_id = compute_wdp_full_id("auth_lib", "E.Auth.Token.001");
assert_eq!(full_id.len(), 11); // 5 + 1 + 5
assert!(full_id.contains('-'));

Constants§

WDP_CODE_SEED
WDP v1 seed for error code hashes (Part 5: Compact IDs)
WDP_NAMESPACE_SEED
WDP v1 seed for namespace hashes (Part 7: Namespaces)

Functions§

compute_wdp_full_id
Compute a full WDP identifier: namespace_hash-code_hash
compute_wdp_hash
Compute a WDP-conformant hash for an error code (Part 5: Compact IDs)
compute_wdp_hash_normalized
Compute WDP hash without normalization (for pre-normalized input)
compute_wdp_namespace_hash
Compute a WDP-conformant hash for a namespace (Part 7: Namespaces)
const_format_sequence
Format a sequence number as 3-digit zero-padded string bytes
const_hash_to_base62
Convert a u64 hash to a 5-character Base62 array (const-compatible)
const_wdp_hash
Compute a WDP-conformant hash at compile time
const_wdp_hash_bytes
Compute WDP hash at compile time from a byte slice
const_wdp_hash_from_parts
Compute WDP hash from error code parts at compile time
normalize_wdp_input
Normalize input for WDP hash computation
parse_wdp_full_id
Parse a WDP full identifier into namespace hash and code hash
verify_wdp_hash
Verify that a hash matches the input code (WDP-conformant)
verify_wdp_namespace_hash
Verify that a namespace hash matches the input namespace