Crate chksum_hash
source ·Expand description
A simple cryptography library that provides an interface for calculating hash digests using both batch and stream computation.
Setup
Update your Cargo.toml
by adding entry to dependencies
section.
[dependencies]
# ...
chksum-hash = "0.4.3"
Alternatively use cargo add
subcommand.
cargo add chksum-hash
Usage
Batch processing
Use hash
function for batch digest calculation.
use chksum_hash::{hash, SHA2_224};
let digest = hash::<SHA2_224, _>(b"somedata");
assert_eq!(
digest.to_hex_lowercase(),
"a39b86d838273f5ff4879c26f85e3cb333bb44d73b24f275bad1a6c6"
);
Stream processing
Use default
function to create hash instance for stream digest calculation.
use chksum_hash::{default, SHA2_256};
let digest = default::<SHA2_256>()
.update("some")
.update(b"data")
.update([0, 1, 2, 3])
.digest();
assert_eq!(
digest.to_hex_lowercase(),
"5c3bfbc8614adc72d3ec0e9b15a1fd1c55cee63e34af5a4ff058eb2eef7d8482"
);
Algorithms
MD5
use chksum_hash::md5;
let digest = md5::hash(b"data");
assert_eq!(
digest.to_hex_lowercase(),
"8d777f385d3dfec8815d20f7496026dc"
);
Check md5
module for more informations and usage examples.
SHA-1
use chksum_hash::sha1;
let digest = sha1::hash(b"data");
assert_eq!(
digest.to_hex_lowercase(),
"a17c9aaa61e80a1bf71d0d850af4e5baa9800bbd"
);
Check sha1
module for more informations and usage examples.
SHA-2
SHA-2 224
use chksum_hash::sha2;
let digest = sha2::sha224::hash(b"data");
assert_eq!(
digest.to_hex_lowercase(),
"f4739673acc03c424343b452787ee23dd62999a8a9f14f4250995769"
);
Check sha2::sha224
module for more informations and usage examples.
SHA-2 256
use chksum_hash::sha2;
let digest = sha2::sha256::hash(b"data");
assert_eq!(
digest.to_hex_lowercase(),
"3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7"
);
Check sha2::sha256
module for more informations and usage examples.
SHA-2 384
use chksum_hash::sha2;
let digest = sha2::sha384::hash(b"data");
assert_eq!(
digest.to_hex_lowercase(),
"2039e0f0b92728499fb88e23ebc3cfd0554b28400b0ed7b753055c88b5865c3c2aa72c6a1a9ae0a755d87900a4a6ff41"
);
Check sha2::sha384
module for more informations and usage examples.
SHA-2 512
use chksum_hash::sha2;
let digest = sha2::sha512::hash(b"data");
assert_eq!(
digest.to_hex_lowercase(),
"77c7ce9a5d86bb386d443bb96390faa120633158699c8844c30b13ab0bf92760b7e4416aea397db91b4ac0e5dd56b8ef7e4b066162ab1fdc088319ce6defc876"
);
Check sha2::sha512
module for more informations and usage examples.
Feature flags
Algorithms
md5
: Enables MD5 hash algorithm.sha1
: Enables SHA-1 hash algorithm.sha2
: Enables SHA-2 hash family algorithms.sha2-224
: Enables only SHA-2 224 hash algorithm.sha2-256
: Enables only SHA-2 256 hash algorithm.sha2-384
: Enables only SHA-2 384 hash algorithm.sha2-512
: Enables only SHA-2 512 hash algorithm.
By default all of them are enabled.
Compilation
error
: AddsError
related implementations.unstable
: Enables unstable options (like build script).
By default only error
is enabled.
License
MIT
Re-exports
pub use sha2::sha224 as sha2_224;
sha2-224
pub use sha2::sha256 as sha2_256;
sha2-256
pub use sha2::sha384 as sha2_384;
sha2-384
pub use sha2::sha512 as sha2_512;
sha2-512
Modules
- SHA2
sha2-224
orsha2-256
orsha2-384
orsha2-512
Module aggregator for SHA-2 family hash functions. - md5
md5
Implementation of MD5 hash function based on RFC 1321: The MD5 Message-Digest Algorithm. - sha1
sha1
Implementation of SHA-1 hash function based on RFC 3174: US Secure Hash Algorithm 1 (SHA1). - sha2
sha2-224
orsha2-256
orsha2-384
orsha2-512
Implementation of SHA-2 hash functions family based on FIPS PUB 180-4: Secure Hash Standard.
Enums
- Error
error
A common error type for the current crate.
Traits
- A digest type.
- A finalized hash type.
- An in-progress hash type.
Functions
- Creates default hash instance.
- Computes hash of given input.
Type Definitions
- MD5
md5
md5::Update
type alias. - Result
error
- SHA1
sha1
sha1::Update
type alias. - SHA2_224
sha2-224
sha2::sha224::Update
type alias. - SHA2_256
sha2-256
sha2::sha256::Update
type alias. - SHA2_384
sha2-384
sha2::sha384::Update
type alias. - SHA2_512
sha2-512
sha2::sha512::Update
type alias.