use alloc::boxed::Box;
use zeroize::Zeroize;
pub trait Hmac: Send + Sync {
fn with_key(&self, key: &[u8]) -> Box<dyn Key>;
fn hash_output_len(&self) -> usize;
fn fips(&self) -> bool {
false
}
}
#[derive(Clone)]
pub struct Tag {
buf: [u8; Self::MAX_LEN],
used: usize,
}
impl Tag {
pub fn new(bytes: &[u8]) -> Self {
let mut tag = Self {
buf: [0u8; Self::MAX_LEN],
used: bytes.len(),
};
tag.buf[..bytes.len()].copy_from_slice(bytes);
tag
}
pub const MAX_LEN: usize = 64;
}
impl Drop for Tag {
fn drop(&mut self) {
self.buf.zeroize();
}
}
impl AsRef<[u8]> for Tag {
fn as_ref(&self) -> &[u8] {
&self.buf[..self.used]
}
}
pub trait Key: Send + Sync {
fn sign(&self, data: &[&[u8]]) -> Tag {
self.sign_concat(&[], data, &[])
}
fn sign_concat(&self, first: &[u8], middle: &[&[u8]], last: &[u8]) -> Tag;
fn tag_len(&self) -> usize;
}