Skip to content

Commit 74cfd80

Browse files
committed
digest: implement Zeroize for the buffering newtypes
1 parent d5355ef commit 74cfd80

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

digest/src/buffer_macros/fixed.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ macro_rules! buffer_fixed {
3939
const OID: $crate::const_oid::ObjectIdentifier =
4040
$crate::const_oid::ObjectIdentifier::new_unwrap($oid);
4141
}
42+
43+
impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? Drop for $name$(< $( $lt ),+ >)? {
44+
#[inline]
45+
fn drop(&mut self) {
46+
#[cfg(feature = "zeroize")]
47+
{
48+
use $crate::zeroize::Zeroize;
49+
self.core.zeroize();
50+
self.buffer.zeroize();
51+
}
52+
}
53+
}
54+
55+
#[cfg(feature = "zeroize")]
56+
impl$(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::zeroize::ZeroizeOnDrop for $name$(< $( $lt ),+ >)? {}
57+
4258
};
4359

4460
// Terminates `impl_inner` sequences.
@@ -183,8 +199,8 @@ macro_rules! buffer_fixed {
183199
Self { core, buffer }
184200
}
185201
fn decompose(self) -> (Self::Core, $crate::block_api::Buffer<Self::Core>) {
186-
let Self { core, buffer } = self;
187-
(core, buffer)
202+
let Self { ref core, ref buffer } = self;
203+
(core.clone(), buffer.clone())
188204
}
189205
}
190206

digest/tests/dummy_fixed.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ mod block_api {
7575
})
7676
}
7777
}
78+
79+
#[cfg(feature = "zeroize")]
80+
impl zeroize::Zeroize for FixedHashCore {
81+
fn zeroize(&mut self) {
82+
self.state.zeroize()
83+
}
84+
}
7885
}
7986

8087
digest::buffer_fixed!(

0 commit comments

Comments
 (0)