nettext/src/crypto/ed25519.rs

35 lines
725 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 {
2022-11-18 11:49:13 +00:00
fn term(&self) -> enc::Result<'_> {
Ok(enc::bytes(&self.to_bytes()))
2022-11-17 22:58:44 +00:00
}
}
impl enc::Encode for PublicKey {
2022-11-18 11:49:13 +00:00
fn term(&self) -> enc::Result<'_> {
Ok(enc::bytes(self.as_bytes()))
2022-11-17 22:58:44 +00:00
}
}
impl enc::Encode for SecretKey {
2022-11-18 11:49:13 +00:00
fn term(&self) -> enc::Result<'_> {
Ok(enc::bytes(self.as_bytes()))
2022-11-17 22:58:44 +00:00
}
}
impl enc::Encode for Signature {
2022-11-18 11:49:13 +00:00
fn term(&self) -> enc::Result<'_> {
Ok(enc::bytes(&self.to_bytes()))
2022-11-17 22:58:44 +00:00
}
}