Skip to main content

aperture_cli/cache/
fingerprint.rs

1use sha2::{Digest, Sha256};
2use std::path::Path;
3
4/// Compute SHA-256 hash of content and return as hex string
5#[must_use]
6pub fn compute_content_hash(content: &[u8]) -> String {
7    let mut hasher = Sha256::new();
8    hasher.update(content);
9    format!("{:x}", hasher.finalize())
10}
11
12/// Get the modification time of a file in seconds since epoch.
13/// Returns `None` if the file metadata cannot be read.
14#[must_use]
15pub fn get_file_mtime_secs(path: &Path) -> Option<u64> {
16    std::fs::metadata(path)
17        .ok()
18        .and_then(|m| m.modified().ok())
19        .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
20        .map(|d| d.as_secs())
21}