16 stable releases

1.5.0 Jan 3, 2024
1.4.0 Aug 22, 2023
1.2.2 Jul 20, 2023
1.1.2 Feb 10, 2023
0.1.0 Mar 20, 2018

#22 in Cryptography

Download history 40785/week @ 2024-03-14 40867/week @ 2024-03-21 40307/week @ 2024-03-28 43680/week @ 2024-04-04 41482/week @ 2024-04-11 40836/week @ 2024-04-18 43861/week @ 2024-04-25 41346/week @ 2024-05-02 49478/week @ 2024-05-09 47473/week @ 2024-05-16 45602/week @ 2024-05-23 50771/week @ 2024-05-30 55225/week @ 2024-06-06 51431/week @ 2024-06-13 56483/week @ 2024-06-20 48744/week @ 2024-06-27

221,238 downloads per month
Used in 237 crates (154 directly)

MIT/Apache

18KB
341 lines

sha256 crypto digest

GitHub Actions Crates.io Docs.rs Download

Examples

sha256 digest function

use sha256::digest;

fn main() {
    let input = String::from("hello");
    let val = digest(input);
    assert_eq!(val,"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");
    
    //sha256 digest &str
    let input = "hello";
    let val = digest(input);
    assert_eq!(val,"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");
    
    //sha256 digest &mut &str
    let mut input = "hello";
    let val = digest(&mut input);
    assert_eq!(val,"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");
    
    //sha256 digest char
    let mut input = "π";
    let val = digest(input);
    assert_eq!(val,"2617fcb92baa83a96341de050f07a3186657090881eae6b833f66a035600f35a");


    let input = b"hello";
    let val = digest(input);
    assert_eq!(val, "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");
}

sha256 try_digest function

use sha256::try_digest;
use std::path::Path;

fn main() {
    let input = Path::new("./foo.file");
    let val = try_digest(input).unwrap();
    assert_eq!(val,"433855b7d2b96c23a6f60e70c655eb4305e8806b682a9596a200642f947259b1");
}

Dependencies

~0.8–2.9MB
~58K SLoC