use x25519_dalek::{PublicKey as DalekPublicKey, StaticSecret};
use crate::{PrivateKey, PublicKey};
impl PublicKey for DalekPublicKey {
fn to_bytes(&self) -> [u8; 32] {
self.to_bytes()
}
}
impl PrivateKey for StaticSecret {
type PublicKey = DalekPublicKey;
fn dh(&self, theirs: &Self::PublicKey) -> [u8; 32] {
self.diffie_hellman(theirs).to_bytes()
}
fn public_key(&self) -> Self::PublicKey {
self.into()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::{run_vector_1, run_vector_2};
fn keypair(b: [u8; 32]) -> (StaticSecret, DalekPublicKey) {
let secret: StaticSecret = b.into();
let public: DalekPublicKey = (&secret).into();
(secret, public)
}
#[test]
fn test_vector_1() {
run_vector_1(&keypair)
}
#[test]
fn test_vector_2() {
run_vector_2(&keypair)
}
}