common_access_token/
utils.rs1use crate::error::Error;
4use hmac_sha256::HMAC;
5
6pub fn compute_hmac_sha256(key: &[u8], data: &[u8]) -> Vec<u8> {
8 HMAC::mac(data, key).to_vec()
9}
10
11pub fn verify_hmac_sha256(key: &[u8], data: &[u8], signature: &[u8]) -> Result<(), Error> {
13 let computed_mac = HMAC::mac(data, key);
14
15 if ct_codecs::verify(&computed_mac, signature) {
16 Ok(())
17 } else {
18 Err(Error::SignatureVerification)
19 }
20}
21
22pub fn current_timestamp() -> u64 {
24 use std::time::{SystemTime, UNIX_EPOCH};
25 SystemTime::now()
26 .duration_since(UNIX_EPOCH)
27 .expect("Time went backwards")
28 .as_secs()
29}