feat: add trait to convert slice into X25519PublicKey

This commit is contained in:
2024-05-06 10:44:04 +02:00
parent 0edc34a236
commit bd19c3639a

View File

@@ -23,6 +23,14 @@ pub struct X25519PubKey<'a>(SharedPtr<'a, 32>);
#[derive(Debug)] #[derive(Debug)]
pub struct X25519SharedKey<'a>(SharedPtr<'a, 32>); pub struct X25519SharedKey<'a>(SharedPtr<'a, 32>);
impl From<&[u8; 32]> for X25519PubKey<'_> {
fn from(value: &[u8; 32]) -> Self {
let mut pk = SharedPtr::<32>::new().unwrap();
pk.copy_from_slice(value);
X25519PubKey(pk)
}
}
pub fn x25519_keygen<'a>() -> (X25519PrivKey<'a>, X25519PubKey<'a>) { pub fn x25519_keygen<'a>() -> (X25519PrivKey<'a>, X25519PubKey<'a>) {
let sk = X25519PrivKey(SharedPtr::<8>::new().unwrap()); let sk = X25519PrivKey(SharedPtr::<8>::new().unwrap());
let pk = X25519PubKey(SharedPtr::<32>::new().unwrap()); let pk = X25519PubKey(SharedPtr::<32>::new().unwrap());