nettext/src/crypto/ed25519.rs

35 lines
701 B
Rust
Raw Normal View History

2022-11-17 22:58:44 +00:00
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())
}
}