pub trait HashFunction: Sealed {
// Required method
fn hash_data(data: &Value) -> Result<String, CryptoError>;
}Expand description
Core trait for hash functions used in sentinel-crypto. This trait abstracts hashing operations to allow easy switching between different hash algorithms while maintaining a consistent interface.
Design choice: Trait-based design enables compile-time algorithm selection and allows for future extensions (e.g., SHA-256, SHA-3) without changing the API. The trait is sealed to prevent external implementations that might not meet security requirements.
Required Methods§
Sourcefn hash_data(data: &Value) -> Result<String, CryptoError>
fn hash_data(data: &Value) -> Result<String, CryptoError>
Computes a cryptographic hash of the given JSON data. The data is canonicalized via JSON serialization before hashing to ensure deterministic results.
§Arguments
data- The JSON value to hash
§Returns
A hex-encoded string representing the hash digest
§Errors
Returns CryptoError::Hashing if JSON serialization fails
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.