Skip to main content

ash_validate_timestamp

Function ash_validate_timestamp 

Source
pub fn ash_validate_timestamp(
    timestamp: &str,
    max_age_seconds: u64,
    clock_skew_seconds: u64,
) -> Result<(), AshError>
Expand description

Validate a timestamp string.

§Arguments

  • timestamp - Unix timestamp as string (seconds since epoch)
  • max_age_seconds - Maximum allowed age of the timestamp
  • clock_skew_seconds - Tolerance for future timestamps (clock skew)

§Returns

Ok(()) if valid, Err with appropriate error if invalid.

§Boundary Conditions

  • A timestamp exactly max_age_seconds old is valid (boundary inclusive)
  • A timestamp exactly clock_skew_seconds in the future is valid

§Security Notes

  • SEC-005: Validates timestamps to prevent replay attacks with stale proofs
  • SEC-018: Rejects unreasonably large timestamps (beyond year 3000)

§Example

use ash_core::ash_validate_timestamp;

// Get current timestamp
let now = std::time::SystemTime::now()
    .duration_since(std::time::UNIX_EPOCH)
    .unwrap()
    .as_secs();

// Recent timestamp should be valid
assert!(ash_validate_timestamp(&now.to_string(), 300, 60).is_ok());

// Old timestamp should fail
let old = now - 600; // 10 minutes ago
assert!(ash_validate_timestamp(&old.to_string(), 300, 60).is_err());