Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
RustCrypto: Digest Algorithm Traits
Traits which describe functionality of cryptographic hash functions, a.k.a. digest algorithms.
See RustCrypto/hashes for implementations which use this trait.
Usage
Let us demonstrate how to use crates in this repository using Sha256 as an example.
First add the sha2
crate to your Cargo.toml
:
[]
= "0.11"
sha2
and other crates re-export digest
crate and Digest
trait for
convenience, so you don't have to add digest
crate as an explicit dependency.
Now you can write the following code:
use ;
let mut hasher = new;
let data = b"Hello world!";
hasher.update;
// `input` can be called repeatedly and is generic over `AsRef<[u8]>`
hasher.update;
// Note that calling `finalize()` consumes hasher
let hash = hasher.finalize;
println!;
In this example hash
has type Array<u8, U32>
, which is a generic
alternative to [u8; 32]
.
Alternatively you can use chained approach, which is equivalent to the previous example:
let hash = new
.chain_update
.chain_update
.finalize;
println!;
If the whole message is available you also can use convenience digest
method:
let hash = digest;
println!;
Generic code
You can write generic code over Digest
(or other traits from digest
crate)
trait which will work over different hash functions:
use Digest;
// Toy example, do not use it in practice!
// Instead use crates from: https://github.com/RustCrypto/password-hashing
let mut buf1 = ;
let mut buf2 = ;
;
;
If you want to use hash functions with trait objects, use digest::DynDigest
trait.
License
Licensed under either of:
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.