icydb_model/base/validator/hash.rs
1//! Module: base::validator::hash
2//!
3//! Responsibility: base validator definitions.
4//! Does not own: normalization policy, persistence, or schema mutation semantics.
5//! Boundary: reports typed visitor issues for facade schema values.
6
7use crate::{prelude::*, visitor::Validator};
8
9///
10/// Sha256
11///
12/// Validates canonical SHA-256 hex digests.
13/// Accepted values are exactly 64 ASCII hexadecimal characters.
14///
15
16#[validator]
17pub struct Sha256;
18
19impl Validator<str> for Sha256 {
20 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
21 // length check
22 if s.len() != 64 {
23 ctx.issue(format!("SHA-256 hex digest length {} must be 64", s.len()));
24 return;
25 }
26
27 // hex characters
28 if !s.chars().all(|c| c.is_ascii_hexdigit()) {
29 ctx.issue("SHA-256 digest must contain only hexadecimal characters");
30 }
31 }
32}