use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
pub const HKDF_SHA384_PRK_LENGTH: usize = 48;
#[derive(Zeroize, ZeroizeOnDrop)]
pub struct HkdfInputKeyMaterial {
bytes: Vec<u8>,
}
impl HkdfInputKeyMaterial {
pub fn from_slice(input: &[u8]) -> Self {
Self {
bytes: input.to_vec(),
}
}
pub fn as_bytes(&self) -> &[u8] {
&self.bytes
}
}
#[derive(Zeroize, ZeroizeOnDrop)]
pub struct HkdfSalt {
bytes: Vec<u8>,
}
impl HkdfSalt {
pub fn from_slice(input: &[u8]) -> Self {
Self {
bytes: input.to_vec(),
}
}
pub fn as_bytes(&self) -> &[u8] {
&self.bytes
}
}
#[derive(Zeroize, ZeroizeOnDrop, PartialEq, Eq)]
pub struct HkdfInfo {
bytes: Vec<u8>,
}
impl core::fmt::Debug for HkdfInfo {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
formatter.write_str("HkdfInfo(<redacted>)")
}
}
impl HkdfInfo {
pub fn from_slice(input: &[u8]) -> Self {
Self {
bytes: input.to_vec(),
}
}
pub fn as_bytes(&self) -> &[u8] {
&self.bytes
}
pub(crate) fn from_vec(bytes: Vec<u8>) -> Self {
Self { bytes }
}
}
#[derive(Zeroize, ZeroizeOnDrop)]
pub struct HkdfOutput<const N: usize> {
bytes: [u8; N],
}
#[derive(Zeroize, ZeroizeOnDrop)]
pub struct HkdfSha384Prk {
bytes: [u8; HKDF_SHA384_PRK_LENGTH],
}
impl HkdfSha384Prk {
pub fn as_bytes(&self) -> &[u8; HKDF_SHA384_PRK_LENGTH] {
&self.bytes
}
pub(crate) fn from_array(bytes: [u8; HKDF_SHA384_PRK_LENGTH]) -> Self {
Self { bytes }
}
}
impl<const N: usize> HkdfOutput<N> {
pub fn as_bytes(&self) -> &[u8; N] {
&self.bytes
}
pub fn into_zeroizing(self) -> Zeroizing<[u8; N]> {
Zeroizing::new(self.bytes)
}
pub(crate) fn from_array(bytes: [u8; N]) -> Self {
Self { bytes }
}
}