pub trait HashPlugin: Sized {
// Required methods
fn create_with_opts(
name: &str,
opts: Option<OptionView<'_>>,
) -> PluginResult<Self>;
fn output_size(&self) -> u32;
fn block_size(&self) -> u32;
fn update(&mut self, data: &[u8]) -> PluginResult<()>;
fn reset(&mut self) -> PluginResult<()>;
fn try_clone(&self) -> PluginResult<Self>;
fn finalize(&mut self, out: &mut [u8]) -> PluginResult<()>;
}Expand description
Trait implemented by hash plugins. The macro-generated
cfmp_hash_create calls HashPlugin::create_with_opts; all other
symbols dispatch through OpaqueHandle::<Self>::borrow_raw and the
corresponding trait method.
update, reset, try_clone, and finalize may return a
PluginError; the macro maps the error into the wire status code
(non-zero) that the loader surfaces via its Error::PluginInternalError
variant.
Required Methods§
Sourcefn create_with_opts(
name: &str,
opts: Option<OptionView<'_>>,
) -> PluginResult<Self>
fn create_with_opts( name: &str, opts: Option<OptionView<'_>>, ) -> PluginResult<Self>
Construct a new hash instance for the named algorithm.
name is the algorithm name the caller passed to
cfm_hash_create (e.g. "sha-256"). opts is the caller’s
option map (or None if the caller passed NULL). Plugins that
don’t take options can ignore both.
Sourcefn output_size(&self) -> u32
fn output_size(&self) -> u32
Output length in bytes for this instance. The caller allocates a
buffer of this size before calling finalize.
Sourcefn block_size(&self) -> u32
fn block_size(&self) -> u32
Internal block size in bytes. Used by callers that want to feed input in aligned chunks; safe to return a constant (e.g. 64) if the algorithm doesn’t have a meaningful block size.
Sourcefn update(&mut self, data: &[u8]) -> PluginResult<()>
fn update(&mut self, data: &[u8]) -> PluginResult<()>
Absorb data into the hash state.
Sourcefn reset(&mut self) -> PluginResult<()>
fn reset(&mut self) -> PluginResult<()>
Reset to the initial state (post-create).
Sourcefn try_clone(&self) -> PluginResult<Self>
fn try_clone(&self) -> PluginResult<Self>
Duplicate the hash state. The clone must be independent: updates to one must not affect the other.
Sourcefn finalize(&mut self, out: &mut [u8]) -> PluginResult<()>
fn finalize(&mut self, out: &mut [u8]) -> PluginResult<()>
Write the finalized digest into out. The caller guarantees
out.len() == self.output_size(). Plugins that need to pad or
finalize internally should do so here.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".