hash.rs

Overview

The hash.rs file provides utility functions for handling SHA-256 cryptographic hashes within the system. It defines a fixed-size hash type alias, functions to compute SHA-256 hashes from byte data, compare two hashes lexicographically, and generate a human-readable hexadecimal string representation of a hash. These capabilities are essential for operations where data integrity verification, cryptographic fingerprinting, or deterministic byte sequence comparison is required.

Types

Sha256Hash

pub(crate) type Sha256Hash = [u8; 32];

Functions

compare_hashes

pub fn compare_hashes(lhs: &Sha256Hash, rhs: &Sha256Hash) -> Ordering

debug_hash

pub(crate) fn debug_hash(hash: &Sha256Hash) -> String

calculate_hash

pub fn calculate_hash(data: &[u8]) -> anyhow::Result<Sha256Hash>

Implementation Details

Interaction with Other System Components

Diagram

flowchart TD
A["Input Data (&[u8"])] --> B[calculate_hash]
B --> C[Sha256 Hasher]
C --> D["Hash Output (Sha256Hash)"]
D --> E{Use Cases}
E --> F[compare_hashes]
E --> G[debug_hash]
F --> H[Ordering Result]
G --> I[Hex String]