[][src]Struct sequoia_openpgp::crypto::hash::Context

pub struct Context { /* fields omitted */ }

State of a hash function.

This provides an abstract interface to the hash functions used in OpenPGP.

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");

Implementations

impl Context[src]

pub fn algo(&self) -> HashAlgorithm[src]

Returns the algorithm.

pub fn digest_size(&self) -> usize[src]

Size of the digest in bytes

pub fn update<D: AsRef<[u8]>>(&mut self, data: D)[src]

Writes data into the hash function.

pub fn digest<D: AsMut<[u8]>>(&mut self, digest: D)[src]

Finalizes the hash function and writes the digest into the provided slice.

Resets the hash function contexts.

digest must be at least self.digest_size() bytes large, otherwise the digest will be truncated.

Trait Implementations

impl Clone for Context[src]

impl From<Context> for MDC[src]

impl Write for Context[src]

Auto Trait Implementations

impl !RefUnwindSafe for Context

impl !Send for Context

impl !Sync for Context

impl Unpin for Context

impl !UnwindSafe for Context

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.