diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-03-30 17:14:00 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-03-30 17:14:00 +0200 |
commit | be0709040b09b5c9acb4b03c647b313ba9924f8d (patch) | |
tree | 178e90c7682087e4e55f7513cdfc988e62784a46 | |
parent | d377ef0006e9b54833105bebb83301bc6fa14a49 (diff) |
openpgp: New doctest for crypto::hash::Context.
-rw-r--r-- | openpgp/src/crypto/hash.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs index fa15c462..a6b7df83 100644 --- a/openpgp/src/crypto/hash.rs +++ b/openpgp/src/crypto/hash.rs @@ -22,6 +22,30 @@ use std::io::{self, Write}; const DUMP_HASHED_VALUES: Option<&str> = None; /// State of a hash function. +/// +/// This provides an abstract interface to the hash functions used in +/// OpenPGP. +/// +/// ```rust +/// # f().unwrap(); fn f() -> sequoia_openpgp::Result<()> { +/// use sequoia_openpgp::types::HashAlgorithm; +/// +/// // Create a context and feed data to it. +/// let mut ctx = HashAlgorithm::SHA512.context()?; +/// ctx.update(&b"The quick brown fox jumps over the lazy dog."[..]); +/// +/// // Extract the digest. +/// let mut digest = vec![0; ctx.digest_size()]; +/// ctx.digest(&mut digest); +/// +/// use sequoia_openpgp::fmt::hex; +/// assert_eq!(&hex::encode(digest), +/// "91EA1245F20D46AE9A037A989F54F1F7\ +/// 90F0A47607EEB8A14D12890CEA77A1BB\ +/// C6C7ED9CF205E67B7F2B8FD4C7DFD3A7\ +/// A8617E45F3C463D481C7E586C39AC1ED"); +/// # Ok(()) } +/// ``` #[derive(Clone)] pub struct Context { algo: HashAlgorithm, |