use crate::Result;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
#[cfg(feature = "sha2")]
use sha2::{Digest, Sha256, Sha512};
pub trait Writer: Sized {
fn write(&mut self, bytes: &[u8]) -> Result<()>;
}
#[cfg(feature = "alloc")]
impl Writer for Vec<u8> {
fn write(&mut self, bytes: &[u8]) -> Result<()> {
self.extend_from_slice(bytes);
Ok(())
}
}
#[cfg(feature = "sha2")]
impl Writer for Sha256 {
fn write(&mut self, bytes: &[u8]) -> Result<()> {
self.update(bytes);
Ok(())
}
}
#[cfg(feature = "sha2")]
impl Writer for Sha512 {
fn write(&mut self, bytes: &[u8]) -> Result<()> {
self.update(bytes);
Ok(())
}
}