export secret

This commit is contained in:
kilic
2024-08-02 14:01:59 +03:00
parent 6988f0bfaa
commit 27f3058df3

View File

@@ -38,8 +38,8 @@ impl SecretKey {
self.0
}
pub fn from_bytes(bytes: [u8; 32]) -> Self {
Self(bytes)
pub fn from_bytes(bytes: &[u8; 32]) -> Self {
Self(bytes.clone())
}
}
@@ -91,11 +91,15 @@ where
Ok(signing_key)
}
pub fn from_bytes<D: Digest>(bytes: [u8; 32]) -> Result<Self, Error> {
pub fn from_bytes<D: Digest>(bytes: &[u8; 32]) -> Result<Self, Error> {
let secret_key = SecretKey::from_bytes(bytes);
Self::new::<D>(&secret_key)
}
pub fn to_bytes(&self) -> [u8; 32] {
self.secret_key.to_bytes()
}
pub fn generate<D: Digest>(rng: &mut impl CryptoRngCore) -> Result<Self, Error> {
let mut secret_key = SecretKey([0; 32]);
rng.fill_bytes(&mut secret_key.0);