-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Description
Implement a HashValidator module that enforces strict validation rules on document hashes before they are submitted to or queried from the Stellar blockchain.
Requirements:
- Create a
HashValidatorstruct with the following methods:validate_sha256(hash: &str) -> Result<(), ValidationError>— ensures the hash is a 64-character lowercase hex stringvalidate_sha512(hash: &str) -> Result<(), ValidationError>— ensures 128-character lowercase hexnormalize(hash: &str) -> String— lowercases and trims whitespacedetect_algorithm(hash: &str) -> Option<HashAlgorithm>— returnsSHA256,SHA512, orNonebased on length
- Create a
ValidationErrorenum:pub enum ValidationError { WrongLength { expected: usize, actual: usize }, InvalidCharacter { position: usize, character: char }, EmptyHash, }
- Apply
HashValidator::validate_sha256to all incomingdocument_hashfields in/verify,/submit,/revoke, and/transferendpoints, returning400with a descriptive error if validation fails
Acceptance Criteria:
- A 63-char hash fails with
WrongLength - A hash containing uppercase letters passes after normalization
- A hash with a non-hex character fails with
InvalidCharacterspecifying the position - Comprehensive unit tests covering all error variants
detect_algorithmcorrectly identifies SHA-256 vs SHA-512 hashes
Reactions are currently unavailable