kanidmd_core/https/
javascript.rs
1use std::path::PathBuf;
2
3pub fn generate_integrity_hash(filename: String) -> Result<String, String> {
5 let filepath = PathBuf::from(filename);
6 match filepath.exists() {
7 false => Err(format!("Can't find {:?} to generate file hash", &filepath)),
8 true => {
9 let filecontents = match std::fs::read(&filepath) {
10 Ok(value) => value,
11 Err(error) => {
12 return Err(format!(
13 "Failed to read {:?}, skipping: {:?}",
14 filepath, error
15 ));
16 }
17 };
18 let shasum = openssl::hash::hash(openssl::hash::MessageDigest::sha384(), &filecontents)
19 .map_err(|_| {
20 format!("Failed to generate SHA384 hash for file at {:?}", filepath)
21 })?;
22 Ok(openssl::base64::encode_block(&shasum))
23 }
24 }
25}
26
27#[derive(Clone)]
28pub struct JavaScriptFile {
29 pub hash: String,
31}