Skip to content

Document Hash Integrity Validator #189

@mftee

Description

@mftee

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 HashValidator struct with the following methods:
    • validate_sha256(hash: &str) -> Result<(), ValidationError> — ensures the hash is a 64-character lowercase hex string
    • validate_sha512(hash: &str) -> Result<(), ValidationError> — ensures 128-character lowercase hex
    • normalize(hash: &str) -> String — lowercases and trims whitespace
    • detect_algorithm(hash: &str) -> Option<HashAlgorithm> — returns SHA256, SHA512, or None based on length
  • Create a ValidationError enum:
    pub enum ValidationError {
        WrongLength { expected: usize, actual: usize },
        InvalidCharacter { position: usize, character: char },
        EmptyHash,
    }
  • Apply HashValidator::validate_sha256 to all incoming document_hash fields in /verify, /submit, /revoke, and /transfer endpoints, returning 400 with 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 InvalidCharacter specifying the position
  • Comprehensive unit tests covering all error variants
  • detect_algorithm correctly identifies SHA-256 vs SHA-512 hashes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions