Skip to main content

DigestProvider

Trait DigestProvider 

Source
pub trait DigestProvider<'a>: Sized {
    type Error;
    type Identity;
    type State;
    type Output: AsRef<[u8]>;

    // Required methods
    fn resolve_digest(
        &'a self,
        identifier: DigestAlgorithm<'a>,
        encoding: Encoding,
        parent: &Reader<'a>,
    ) -> Result<Resolution<Self::Identity>, Self::Error>;
    fn compare_digest<W: Work>(
        &self,
        left: &Self::Identity,
        right: &Self::Identity,
        execution: &W,
    ) -> Result<Ordering, Self::Error>;
    fn digest_width(&self, identity: &Self::Identity) -> Option<usize>;
    fn start_digest<W: Work>(
        &'a self,
        identity: &Self::Identity,
        execution: &W,
    ) -> Result<Self::State, Self::Error>;
    fn update_digest<W: Work>(
        &self,
        state: &mut Self::State,
        bytes: &[u8],
        execution: &W,
    ) -> Result<(), Self::Error>;
    fn finish_digest<W: Work>(
        &self,
        state: Self::State,
        execution: &W,
    ) -> Result<Self::Output, Self::Error>;
    fn matches_digest<W: Work>(
        &self,
        digest: Prehash<'_, '_, Self, Self::Identity>,
        expected: &[u8],
        execution: &W,
    ) -> Result<bool, Self::Error>;
}
Expand description

Narrow digest operations from one explicitly selected provider instance.

Identities must include algorithm parameters/defaults/output semantics, not just an OID or byte width. compare is a total semantic order: Equal means the outputs can be shared. Every callback admits its complete transitive work/storage before execution through the supplied domain. Errors preserve provider/resource causes; they are never converted to unsupported/malformed. States/outputs may borrow the selected provider or original document and impose no Clone, Send or Sync requirement. State initialization must not retain a reference to the temporary identity object itself.

Common processing borrows a stable nonzero-sized selection owner. Ordinary adapters containing engine/context references already satisfy this. Wrap a zero-sized stateless adapter in ProviderSession before using common processing; otherwise it returns a processing ProviderMismatch before dispatch. Distinct ZST addresses cannot supply instance provenance.

Required Associated Types§

Source

type Error

Original callback failure, including that provider’s resource refusal.

Source

type Identity

Fully resolved digest identity.

Source

type State

Digest state, independently movable from its identity object.

Source

type Output: AsRef<[u8]>

Final output, inline or retaining its own admitted allocation charge.

Required Methods§

Source

fn resolve_digest( &'a self, identifier: DigestAlgorithm<'a>, encoding: Encoding, parent: &Reader<'a>, ) -> Result<Resolution<Self::Identity>, Self::Error>

Resolves original parameters under their producing encoding/work domain.

Source

fn compare_digest<W: Work>( &self, left: &Self::Identity, right: &Self::Identity, execution: &W, ) -> Result<Ordering, Self::Error>

Compares full resolved identities after admitting any parameter traversal.

Source

fn digest_width(&self, identity: &Self::Identity) -> Option<usize>

Expected fixed output width, or None for an identity without a fixed width. This is O(1) metadata access on the already resolved identity, not parsing.

Source

fn start_digest<W: Work>( &'a self, identity: &Self::Identity, execution: &W, ) -> Result<Self::State, Self::Error>

Initializes a state without borrowing the address of identity.

Source

fn update_digest<W: Work>( &self, state: &mut Self::State, bytes: &[u8], execution: &W, ) -> Result<(), Self::Error>

Admits and processes each complete logical chunk exactly once.

Source

fn finish_digest<W: Work>( &self, state: Self::State, execution: &W, ) -> Result<Self::Output, Self::Error>

Consumes a completed state once; no opaque state cloning or repeated finish.

Source

fn matches_digest<W: Work>( &self, digest: Prehash<'_, '_, Self, Self::Identity>, expected: &[u8], execution: &W, ) -> Result<bool, Self::Error>

Compares completed bytes with a declared imprint, without hashing again.

Common schema processing rejects an impossible fixed expected width first and checks declared versus actual finalized width even when the identity has no fixed width. The callback admits the complete byte comparison in execution, preserves resource failures and applies its backend’s comparison strategy, including constant-time equality where its contract requires. CMS payload message-digest, ESS certificate hashes and TSP imprints use this same operation with their distinct original covered inputs.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§