tap_msg/utils.rs
1//! Utility functions for TAP core
2//!
3//! This module provides utility functions used throughout the TAP core library.
4
5pub mod name_hash;
6
7use crate::error::Error;
8use crate::Result;
9use std::time::SystemTime;
10
11pub use name_hash::{hash_name, NameHashable};
12
13/// Gets the current time as a unix timestamp (seconds since the epoch)
14///
15/// # Returns
16///
17/// * `Result<u64>` - The current time as a unix timestamp, or an error if
18/// the system time cannot be determined.
19pub fn get_current_time() -> Result<u64> {
20 SystemTime::now()
21 .duration_since(SystemTime::UNIX_EPOCH)
22 .map_err(|e| Error::ParseError(format!("Failed to get current time: {}", e)))
23 .map(|duration| duration.as_secs())
24}