nettext/src/crypto/ed25519.rs

36 lines
770 B
Rust

use rand::prelude::*;
use crate::enc;
pub use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer, Verifier};
/// Generate a public/secret Ed25519 keypair
pub fn generate_keypair() -> Keypair {
let mut csprng = thread_rng();
Keypair::generate(&mut csprng)
}
impl enc::Encode for Keypair {
fn term(&self) -> enc::Result<'_> {
Ok(enc::bytes(&self.to_bytes()))
}
}
impl enc::Encode for PublicKey {
fn term(&self) -> enc::Result<'_> {
Ok(enc::bytes(self.as_bytes()))
}
}
impl enc::Encode for SecretKey {
fn term(&self) -> enc::Result<'_> {
Ok(enc::bytes(self.as_bytes()))
}
}
impl enc::Encode for Signature {
fn term(&self) -> enc::Result<'_> {
Ok(enc::bytes(&self.to_bytes()))
}
}