mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-03 09:47:38 +00:00
4555e33048
* remove remaining uses of serde_derive * fix lockfile --------- Co-authored-by: João Oliveira <hello@jxs.pt>
39 lines
951 B
Rust
39 lines
951 B
Rust
use super::SECRET_KEY_BYTES_LEN;
|
|
use serde::{Deserialize, Serialize};
|
|
use zeroize::Zeroize;
|
|
|
|
/// Provides a wrapper around a `[u8; SECRET_KEY_BYTES_LEN]` that implements `Zeroize` on `Drop`.
|
|
#[derive(Zeroize, Serialize, Deserialize)]
|
|
#[zeroize(drop)]
|
|
#[serde(transparent)]
|
|
pub struct ZeroizeHash([u8; SECRET_KEY_BYTES_LEN]);
|
|
|
|
impl ZeroizeHash {
|
|
/// Instantiates `Self` with all zeros.
|
|
pub fn zero() -> Self {
|
|
Self([0; SECRET_KEY_BYTES_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<[u8; SECRET_KEY_BYTES_LEN]> for ZeroizeHash {
|
|
fn from(array: [u8; SECRET_KEY_BYTES_LEN]) -> Self {
|
|
Self(array)
|
|
}
|
|
}
|
|
|
|
impl AsRef<[u8]> for ZeroizeHash {
|
|
fn as_ref(&self) -> &[u8] {
|
|
&self.0
|
|
}
|
|
}
|