feat: add Deref trait to X25519 types

This commit is contained in:
2024-05-06 17:19:59 +02:00
parent 6ec9735709
commit bd7d80765c

View File

@@ -6,8 +6,7 @@ pub use shared_memory_heap::sharedptr::SharedPtr;
use agent::Agent; use agent::Agent;
use std::{ use std::{
path::Path, ops::Deref, path::Path, sync::{LazyLock, Mutex}
sync::{LazyLock, Mutex},
}; };
static AGENT: LazyLock<Mutex<Agent>> = LazyLock::new(|| { static AGENT: LazyLock<Mutex<Agent>> = LazyLock::new(|| {
@@ -39,6 +38,30 @@ impl From<&[u8; 8]> for X25519PrivKey<'_> {
} }
} }
impl Deref for X25519PrivKey<'_> {
type Target = [u8; 8];
fn deref(&self) -> &Self::Target {
self.0.deref()
}
}
impl Deref for X25519PubKey<'_> {
type Target = [u8; 32];
fn deref(&self) -> &Self::Target {
self.0.deref()
}
}
impl Deref for X25519SharedKey<'_> {
type Target = [u8; 32];
fn deref(&self) -> &Self::Target {
self.0.deref()
}
}
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());