lighthouse/crypto/eth2_keystore/src/derived_key.rs
Paul Hauner 4331834003
Directory Restructure (#1163)
* Move tests -> testing

* Directory restructure

* Update Cargo.toml during restructure

* Update Makefile during restructure

* Fix arbitrary path
2020-05-18 21:24:23 +10:00

25 lines
610 B
Rust

use crate::keystore::DKLEN;
use zeroize::Zeroize;
/// Provides wrapper around `[u8; DKLEN]` that implements `Zeroize`.
#[derive(Zeroize)]
#[zeroize(drop)]
pub struct DerivedKey([u8; DKLEN as usize]);
impl DerivedKey {
/// Instantiates `Self` with an all-zeros byte array.
pub fn zero() -> Self {
Self([0; DKLEN as usize])
}
/// Returns a mutable reference to the underlying byte array.
pub fn as_mut_bytes(&mut self) -> &mut [u8] {
&mut self.0
}
/// Returns a reference to the underlying byte array.
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
}