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: Adds Error 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

Enums

  • Errorerror
    A common error type for the current crate.

Traits

Functions

  • Creates default hash instance.
  • Computes hash of given input.

Type Definitions