Created
December 12, 2021 15:47
-
-
Save koolquark/a7df77dcc131b28fc4a2176933afa4c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use sha2::{Digest, Sha256}; | |
use std::path::{Path, PathBuf}; | |
fn hash(data: String) -> [u8; 32] { | |
let mut hasher = Sha256::new(); | |
hasher.update(data.as_bytes()); | |
let r: [u8; 32] = hasher | |
.finalize() | |
.as_slice() | |
.try_into() | |
.expect("Wrong Length"); | |
return r; | |
} | |
fn main() { | |
// let hashvalue = sha2::Sha256::digest(&[3, 2, 6, 4, 3]); | |
// let x: [u8; 32] = hashvalue.as_slice().try_into().expect("Wrong length"); | |
// println!("{:?}", x); | |
// let mut k = PathBuf::new(); | |
// k.push("/home/test.jpg"); | |
// let f = k.file_name().unwrap(); | |
// let s: &str = f.to_str().unwrap(); | |
// println!("{}", s); | |
let mut k = PathBuf::new(); | |
k.push("/home/test.jpg"); | |
let filename = k.file_name().unwrap(); | |
let hv = hash(filename.to_str().unwrap().to_owned()); | |
println!("{:?}", hv); | |
println!("{}", hv[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment