Function freetsa::timestamp_file
source · [−]pub async fn timestamp_file(
path: impl AsRef<Path>
) -> Result<TimestampResponse, TimestampFileError>
Expand description
Timestamp a file.
This method generates a SHA512 hash of the specified file and submits it to FreeTSA to be timestamped.
This method is available only if freetsa is built with the "file"
feature.
Example
use freetsa::prelude::*;
use tokio::fs::OpenOptions;
use tokio::io::AsyncWriteExt;
#[tokio::main]
async fn main() {
// request timestamp with automatically generated file hash
let TimestampResponse { reply, .. } = timestamp_file("path/to/file").await.unwrap();
// create file where we'll persist the timestamp reply
let mut reply_file = OpenOptions::new()
.create(true)
.write(true)
.open("example.tsr")
.await
.unwrap();
// write timestamp reply to file
reply_file.write_all(&reply).await.unwrap();
// ensure os has completed writing all data
reply_file.flush().await.unwrap();
}