nettext/src/crypto/ed25519.rs
2022-11-17 23:58:44 +01:00

35 lines
701 B
Rust

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