pub struct Writer<D>(/* private fields */);Expand description
A wrapper around Digest type that allows to use Write trait for hashing
§Example
extern crate sha2;
extern crate digest;
extern crate digest_writer;
use std::fs::File;
use std::io::{self, Write};
use digest::FixedOutput;
use digest_writer::Writer;
let mut digest = Writer::new(sha2::Sha256::default());
let mut f = File::open("LICENSE-MIT").unwrap();
io::copy(&mut f, &mut digest).unwrap();
digest.fixed_result();Implementations§
Source§impl<D: Input + FixedOutput> Writer<D>
impl<D: Input + FixedOutput> Writer<D>
Sourcepub fn into_inner(self) -> D
pub fn into_inner(self) -> D
Return the original Digest
Trait Implementations§
Source§impl<D> BlockInput for Writer<D>
impl<D> BlockInput for Writer<D>
type BlockSize = <D as BlockInput>::BlockSize
Source§impl<D> FixedOutput for Writer<D>
impl<D> FixedOutput for Writer<D>
type OutputSize = <D as FixedOutput>::OutputSize
Source§fn fixed_result(self) -> GenericArray<u8, Self::OutputSize>
fn fixed_result(self) -> GenericArray<u8, Self::OutputSize>
Retrieve the digest result. This method consumes digest instance.
Source§impl<D: VariableOutput> VariableOutput for Writer<D>
impl<D: VariableOutput> VariableOutput for Writer<D>
Source§fn new(output_size: usize) -> Result<Writer<D>, InvalidLength>
fn new(output_size: usize) -> Result<Writer<D>, InvalidLength>
Create new hasher instance with given output size. Will return
Err(InvalidLength) in case if hasher can not work with the given
output size. Will always return an error if output size equals to zero.Source§fn output_size(&self) -> usize
fn output_size(&self) -> usize
Get output size of the hasher instance provided to the
new methodSource§fn variable_result(self, buffer: &mut [u8]) -> Result<&[u8], InvalidLength>
fn variable_result(self, buffer: &mut [u8]) -> Result<&[u8], InvalidLength>
Retrieve the digest result into provided buffer. Length of the buffer
must be equal to output size provided to the
new method, otherwise
Err(InvalidLength) will be returnedSource§impl<D: Input> Write for Writer<D>
impl<D: Input> Write for Writer<D>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations§
impl<D> Freeze for Writer<D>where
D: Freeze,
impl<D> RefUnwindSafe for Writer<D>where
D: RefUnwindSafe,
impl<D> Send for Writer<D>where
D: Send,
impl<D> Sync for Writer<D>where
D: Sync,
impl<D> Unpin for Writer<D>where
D: Unpin,
impl<D> UnwindSafe for Writer<D>where
D: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> Digest for D
impl<D> Digest for D
Source§fn input(&mut self, input: &[u8])
fn input(&mut self, input: &[u8])
Digest input data. This method can be called repeatedly
for use with streaming messages.
Source§fn result(self) -> GenericArray<u8, Self::OutputSize>
fn result(self) -> GenericArray<u8, Self::OutputSize>
Retrieve the digest result. This method consumes digest instance.
Source§fn digest(data: &[u8]) -> GenericArray<u8, Self::OutputSize>
fn digest(data: &[u8]) -> GenericArray<u8, Self::OutputSize>
Convenience function to compute hash of the
data. It will handle
hasher creation, data feeding and finalization. Read moreSource§fn digest_str(str: &str) -> GenericArray<u8, Self::OutputSize>
fn digest_str(str: &str) -> GenericArray<u8, Self::OutputSize>
Convenience function to compute hash of the string. It’s equivalent to
digest(input_string.as_bytes()).