mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-21 14:58:31 +00:00
Directory Restructure (#1163)
* Move tests -> testing * Directory restructure * Update Cargo.toml during restructure * Update Makefile during restructure * Fix arbitrary path
This commit is contained in:
29
crypto/eth2_key_derivation/src/secret_bytes.rs
Normal file
29
crypto/eth2_key_derivation/src/secret_bytes.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use zeroize::Zeroize;
|
||||
|
||||
/// Provides a wrapper around a `Vec<u8>` that implements `Zeroize` on `Drop`.
|
||||
#[derive(Zeroize)]
|
||||
#[zeroize(drop)]
|
||||
pub struct SecretBytes(Vec<u8>);
|
||||
|
||||
impl SecretBytes {
|
||||
/// Instantiates `Self` with an all-zeros byte array of length `len`.
|
||||
pub fn zero(len: usize) -> Self {
|
||||
Self(vec![0; len])
|
||||
}
|
||||
|
||||
/// Returns a reference to the underlying bytes.
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the underlying bytes.
|
||||
pub fn as_mut_bytes(&mut self) -> &mut [u8] {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for SecretBytes {
|
||||
fn from(vec: Vec<u8>) -> Self {
|
||||
Self(vec)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user