Initial commit with sha256 implementation.
This commit is contained in:
commit
1cf4cdf1cc
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "hexihasher"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Bill Thiede <git@xinu.tv>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
sha2 = "0.8.1"
|
||||||
|
faster-hex = "0.4.1"
|
||||||
23
src/lib.rs
Normal file
23
src/lib.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//! This module contains various helpers for generating the hashes in hex representation.
|
||||||
|
use faster_hex;
|
||||||
|
use sha2;
|
||||||
|
use sha2::Digest;
|
||||||
|
|
||||||
|
/// Return hex string representation of the sha256 hash of v.
|
||||||
|
/// ```
|
||||||
|
/// use hexihasher;
|
||||||
|
/// let s = hexihasher::sha256(&[0, 1, 2, 3][..]);
|
||||||
|
///
|
||||||
|
/// assert_eq!(s, "054edec1d0211f624fed0cbca9d4f9400b0e491c43742af2c5b0abebf0c990d8");
|
||||||
|
/// ```
|
||||||
|
pub fn sha256(v: &[u8]) -> String {
|
||||||
|
// create a Sha256 object
|
||||||
|
let mut hasher = sha2::Sha256::new();
|
||||||
|
|
||||||
|
// write input message
|
||||||
|
hasher.input(v);
|
||||||
|
|
||||||
|
// read hash digest and consume hasher
|
||||||
|
let result = hasher.result();
|
||||||
|
faster_hex::hex_string(&result).expect("failed to hash")
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user