2020-05-29 04:39:33 +00:00
|
|
|
use super::BLS_SECRET_KEY_BYTE_SIZE;
|
2020-05-11 08:43:43 +00:00
|
|
|
use zeroize::Zeroize;
|
|
|
|
|
|
|
|
/// Provides a wrapper around a `[u8; HASH_SIZE]` that implements `Zeroize` on `Drop`.
|
|
|
|
#[derive(Zeroize)]
|
|
|
|
#[zeroize(drop)]
|
2020-05-29 04:39:33 +00:00
|
|
|
pub struct SecretHash([u8; BLS_SECRET_KEY_BYTE_SIZE]);
|
2020-05-11 08:43:43 +00:00
|
|
|
|
|
|
|
impl SecretHash {
|
|
|
|
/// Instantiates `Self` with all zeros.
|
|
|
|
pub fn zero() -> Self {
|
2020-05-29 04:39:33 +00:00
|
|
|
Self([0; BLS_SECRET_KEY_BYTE_SIZE])
|
2020-05-11 08:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 04:39:33 +00:00
|
|
|
|
|
|
|
impl From<[u8; BLS_SECRET_KEY_BYTE_SIZE]> for SecretHash {
|
|
|
|
fn from(array: [u8; BLS_SECRET_KEY_BYTE_SIZE]) -> Self {
|
|
|
|
Self(array)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<[u8]> for SecretHash {
|
|
|
|
fn as_ref(&self) -> &[u8] {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|