use crate::bytes::ByteArray;
#[cfg(feature = "rand_core")]
use crate::error::Error;
#[cfg(feature = "rand_core")]
use crate::{TryCryptoRng, TryRngCore};
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
pub type ParentKeyId = ByteArray<16>;
pub type ParentKeySecret = ByteArray<32>;
#[derive(Default)]
pub struct ParentKey {
id: ParentKeyId,
secret: ParentKeySecret,
}
impl ParentKey {
pub fn new(id: ParentKeyId, secret: ParentKeySecret) -> Self {
Self { id, secret }
}
pub fn id(&self) -> &ParentKeyId {
&self.id
}
pub fn secret(&self) -> &ParentKeySecret {
&self.secret
}
#[cfg(feature = "rand_core")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand_core")))]
pub fn try_from_crypto_rand<R>(rand_source: &mut R) -> Result<Self, Error>
where
R: TryCryptoRng + TryRngCore,
{
let id = ParentKeyId::try_from_crypto_rand(rand_source)?;
let secret = ParentKeySecret::try_from_crypto_rand(rand_source)?;
Ok(Self { id, secret })
}
}
#[cfg(feature = "zeroize")]
impl Drop for ParentKey {
fn drop(&mut self) {
self.secret.zeroize();
}
}