Skip to content

Commit 0289b87

Browse files
fix: delegate to inner type zeroize implementations for SecretKey and SecurePlaintext
1 parent 087e7d0 commit 0289b87

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

arm/src/encryption.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize};
2020
use std::io::Write;
2121
use zeroize::{Zeroize, ZeroizeOnDrop};
2222

23-
#[derive(Clone, Serialize, Deserialize)]
23+
#[derive(Clone, Serialize, Deserialize, Zeroize, ZeroizeOnDrop)]
2424
pub struct SecretKey(Scalar);
2525

2626
impl SecretKey {
@@ -44,20 +44,6 @@ impl Default for SecretKey {
4444
}
4545
}
4646

47-
impl Zeroize for SecretKey {
48-
fn zeroize(&mut self) {
49-
// Manually zero the Scalar's inner U256
50-
// Use volatile write to prevent compiler optimization
51-
unsafe {
52-
let ptr = &mut self.0 as *mut Scalar as *mut [u8; 32];
53-
core::ptr::write_volatile(ptr, [0u8; 32]);
54-
}
55-
}
56-
}
57-
58-
// Mark as ZeroizeOnDrop - auto-generates Drop impl that calls zeroize()
59-
impl ZeroizeOnDrop for SecretKey {}
60-
6147
#[cfg(feature = "nif")]
6248
fn do_encode<'a>(secret_key: &SecretKey, env: Env<'a>) -> Result<Term<'a>, Error> {
6349
let bytes = bincode::serialize(&secret_key.0).unwrap();
@@ -240,12 +226,9 @@ impl InnerSecretKey {
240226
}
241227
}
242228

243-
/// Wrapper for plaintext that automatically zeros on drop
229+
#[derive(Zeroize, ZeroizeOnDrop)]
244230
pub struct SecurePlaintext(Vec<u8>);
245231

246-
// Vec<u8> already implements Zeroize, so we can implement ZeroizeOnDrop
247-
impl ZeroizeOnDrop for SecurePlaintext {}
248-
249232
impl SecurePlaintext {
250233
pub fn new(data: Vec<u8>) -> Self {
251234
SecurePlaintext(data)

0 commit comments

Comments
 (0)