Skip to content

Commit

Permalink
move zeroize test out of macro (also in advance of incorporating secp…
Browse files Browse the repository at this point in the history
…256k1)
  • Loading branch information
brentstone committed Jul 5, 2022
1 parent 6d1d92e commit ea17369
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions shared/src/types/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,26 +415,31 @@ macro_rules! sigscheme_test {
println!("Public key: {}", public_key);
println!("Secret key: {}", secret_key);
}

#[test]
fn zeroize_keypair() {
use rand::thread_rng;

let sk = ed25519::SecretKey(Box::new(
ed25519_consensus::SigningKey::new(thread_rng()),
));
let len = sk.0.as_bytes().len();
let ptr = sk.0.as_bytes().as_ptr();

drop(sk);

assert_eq!(&[0u8; 32], unsafe {
core::slice::from_raw_parts(ptr, len)
});
}
}
};
}

#[cfg(test)]
sigscheme_test! {ed25519_test, ed25519::SigScheme}

#[cfg(test)]
mod more_tests {
use super::*;

#[test]
fn zeroize_keypair_ed25519() {
use rand::thread_rng;

let sk = ed25519::SecretKey(Box::new(
ed25519_consensus::SigningKey::new(thread_rng()),
));
let len = sk.0.as_bytes().len();
let ptr = sk.0.as_bytes().as_ptr();

drop(sk);

assert_eq!(&[0u8; 32], unsafe {
core::slice::from_raw_parts(ptr, len)
});
}
}

0 comments on commit ea17369

Please sign in to comment.