Skip to content

Commit

Permalink
digest: document three levels of organization
Browse files Browse the repository at this point in the history
The new `*Dirty` traits add another level of organization to the crate's
design. This commit updates the documentation to reflect that.
  • Loading branch information
tarcieri committed Jun 9, 2020
1 parent 63816fc commit 342af17
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 3 additions & 1 deletion digest/src/fixed.rs
Expand Up @@ -49,7 +49,9 @@ pub trait FixedOutputDirty {

/// Retrieve result into provided buffer and leave hasher in a dirty state.
///
/// Implementations should panic if this is called twice without resetting.
/// This method is expected to only be called once unless
/// [`Reset::reset`] is called, after which point it can be
/// called again and reset again (and so on).
fn finalize_into_dirty(&mut self, out: &mut GenericArray<u8, Self::OutputSize>);
}

Expand Down
22 changes: 15 additions & 7 deletions digest/src/lib.rs
@@ -1,15 +1,23 @@
//! This crate provides traits which describe functionality of cryptographic hash
//! functions.
//!
//! Traits in this repository can be separated into two levels:
//! - Low level traits: [`Update`], [`BlockInput`], [`Reset`], [`FixedOutput`],
//! [`VariableOutput`], [`ExtendableOutput`]. These traits atomically describe
//! available functionality of hash function implementations.
//! - Convenience trait: [`Digest`], [`DynDigest`]. They are wrappers around
//! low level traits for most common hash-function use-cases.
//! Traits in this repository are organized into high-level convenience traits,
//! mid-level traits which expose more fine-grained functionality, and
//! low-level traits intended to only be used by algorithm implementations:
//!
//! - **High-level convenience traits**: [`Digest`], [`DynDigest`]. They are wrappers
//! around lower-level traits for most common hash-function use-cases.
//! - **Mid-level traits**: [`Update`], [`BlockInput`], [`Reset`], [`FixedOutput`],
//! [`VariableOutput`], [`ExtendableOutput`]. These traits atomically describe
//! available functionality of hash function implementations.
//! - **Low-level traits**: [`FixedOutputDirty`], [`VariableOutputDirty`],
//! [`ExtendableOutputDirty`]. These traits are intended to be implemented by
//! low-level algorithm providers only and simplify the amount of work
//! implementers need to do and therefore shouldn't be used in
//! application-level code.
//!
//! Additionally hash functions implement traits from `std`: `Default`, `Clone`,
//! `Write`. (the latter depends on enabled-by-default `std` crate feature)
//! `Write`. (the latter depends on the downstream crate having a `std` feature)
//!
//! The [`Digest`] trait is the most commonly used trait.

Expand Down
4 changes: 3 additions & 1 deletion digest/src/variable.rs
Expand Up @@ -78,7 +78,9 @@ pub trait VariableOutputDirty: Sized {

/// Retrieve result into provided buffer and leave hasher in a dirty state.
///
/// Implementations should panic if this is called twice without resetting.
/// This method is expected to only be called once unless
/// [`Reset::reset`] is called, after which point it can be
/// called again and reset again (and so on).
fn finalize_variable_dirty(&mut self, f: impl FnOnce(&[u8]));
}

Expand Down
6 changes: 4 additions & 2 deletions digest/src/xof.rs
Expand Up @@ -77,9 +77,11 @@ pub trait ExtendableOutputDirty: Sized {
/// Reader
type Reader: XofReader;

/// Retrieve XOF reader and consume hasher instance.
/// Retrieve XOF reader.
///
/// Implementations should panic if this is called twice without resetting.
/// This method is expected to only be called once unless
/// [`Reset::reset`] is called, after which point it can be
/// called again and reset again (and so on).
fn finalize_xof_dirty(&mut self) -> Self::Reader;
}

Expand Down

0 comments on commit 342af17

Please sign in to comment.