blob: e338789c63cfb41d1bb2e9c57d978b2cca35296c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# sha256 crypto digest
[docsrs]: https://docs.rs/sha256
[![GitHub Actions](https://github.com/baoyachi/sha256-rs/workflows/check/badge.svg)](https://github.com/baoyachi/sha256-rs/actions?query=workflow%3Abuild)
[![Crates.io](https://img.shields.io/crates/v/sha256.svg)](https://crates.io/crates/sha256)
[![Docs.rs](https://docs.rs/sha256/badge.svg)](https://docs.rs/sha256)
[![Download](https://img.shields.io/crates/d/sha256)](https://crates.io/crates/sha256)
## Examples
#### sha256 digest function
```rust
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
```rust
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");
}
```
|