1use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
6
7pub const HKDF_SHA384_PRK_LENGTH: usize = 48;
9
10#[derive(Zeroize, ZeroizeOnDrop)]
12pub struct HkdfInputKeyMaterial {
13 bytes: Vec<u8>,
14}
15
16impl HkdfInputKeyMaterial {
17 pub fn from_slice(input: &[u8]) -> Self {
19 Self {
20 bytes: input.to_vec(),
21 }
22 }
23
24 pub fn as_bytes(&self) -> &[u8] {
26 &self.bytes
27 }
28}
29
30#[derive(Zeroize, ZeroizeOnDrop)]
36pub struct HkdfSalt {
37 bytes: Vec<u8>,
38}
39
40impl HkdfSalt {
41 pub fn from_slice(input: &[u8]) -> Self {
43 Self {
44 bytes: input.to_vec(),
45 }
46 }
47
48 pub fn as_bytes(&self) -> &[u8] {
50 &self.bytes
51 }
52}
53
54#[derive(Zeroize, ZeroizeOnDrop, PartialEq, Eq)]
60pub struct HkdfInfo {
61 bytes: Vec<u8>,
62}
63
64impl core::fmt::Debug for HkdfInfo {
65 fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
66 formatter.write_str("HkdfInfo(<redacted>)")
67 }
68}
69
70impl HkdfInfo {
71 pub fn from_slice(input: &[u8]) -> Self {
73 Self {
74 bytes: input.to_vec(),
75 }
76 }
77
78 pub fn as_bytes(&self) -> &[u8] {
80 &self.bytes
81 }
82
83 pub(crate) fn from_vec(bytes: Vec<u8>) -> Self {
84 Self { bytes }
85 }
86}
87
88#[derive(Zeroize, ZeroizeOnDrop)]
90pub struct HkdfOutput<const N: usize> {
91 bytes: [u8; N],
92}
93
94#[derive(Zeroize, ZeroizeOnDrop)]
99pub struct HkdfSha384Prk {
100 bytes: [u8; HKDF_SHA384_PRK_LENGTH],
101}
102
103impl HkdfSha384Prk {
104 pub fn as_bytes(&self) -> &[u8; HKDF_SHA384_PRK_LENGTH] {
106 &self.bytes
107 }
108
109 pub(crate) fn from_array(bytes: [u8; HKDF_SHA384_PRK_LENGTH]) -> Self {
110 Self { bytes }
111 }
112}
113
114impl<const N: usize> HkdfOutput<N> {
115 pub fn as_bytes(&self) -> &[u8; N] {
117 &self.bytes
118 }
119
120 pub fn into_zeroizing(self) -> Zeroizing<[u8; N]> {
122 Zeroizing::new(self.bytes)
123 }
124
125 pub(crate) fn from_array(bytes: [u8; N]) -> Self {
126 Self { bytes }
127 }
128}