From bd7d80765cd363bd8a8908a3bd5d32f87fb527b4 Mon Sep 17 00:00:00 2001 From: Aaron Kaiser Date: Mon, 6 May 2024 17:19:59 +0200 Subject: [PATCH] feat: add Deref trait to X25519 types --- src/lib.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ab18a36..d6cb973 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,8 +6,7 @@ pub use shared_memory_heap::sharedptr::SharedPtr; use agent::Agent; use std::{ - path::Path, - sync::{LazyLock, Mutex}, + ops::Deref, path::Path, sync::{LazyLock, Mutex} }; static AGENT: LazyLock> = 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>) { let sk = X25519PrivKey(SharedPtr::<8>::new().unwrap()); let pk = X25519PubKey(SharedPtr::<32>::new().unwrap());