pub struct Ed25519Key { /* private fields */ }Expand description
Ed25519 key pair for digital signatures.
Ed25519 is a modern elliptic curve signature scheme based on Curve25519. It provides 128-bit security with fast signing and verification, and deterministic signatures. Ed25519 keys are 32 bytes for both private and public keys.
§Example
use rust_bottle::keys::Ed25519Key;
use rand::rngs::OsRng;
let rng = &mut OsRng;
let key = Ed25519Key::generate(rng);
let pub_key = key.public_key_bytes();
let priv_key = key.private_key_bytes();Implementations§
Source§impl Ed25519Key
impl Ed25519Key
Sourcepub fn generate<R: RngCore + CryptoRng>(rng: &mut R) -> Self
pub fn generate<R: RngCore + CryptoRng>(rng: &mut R) -> Self
Generate a new Ed25519 key pair.
This function generates a cryptographically secure key pair using the provided random number generator.
§Arguments
rng- A cryptographically secure random number generator
§Returns
A new Ed25519Key instance with a randomly generated key pair
§Example
use rust_bottle::keys::Ed25519Key;
use rand::rngs::OsRng;
let rng = &mut OsRng;
let key = Ed25519Key::generate(rng);Sourcepub fn public_key_bytes(&self) -> Vec<u8> ⓘ
pub fn public_key_bytes(&self) -> Vec<u8> ⓘ
Sourcepub fn private_key_bytes(&self) -> Vec<u8> ⓘ
pub fn private_key_bytes(&self) -> Vec<u8> ⓘ
Get the private key bytes.
Ed25519 private keys are 32 bytes. This is sensitive data and should be handled securely.
§Returns
Private key bytes (32 bytes)
§Security Warning
Private keys are sensitive cryptographic material. They should be stored securely and cleared from memory when no longer needed.
Sourcepub fn from_private_key_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_private_key_bytes(bytes: &[u8]) -> Result<Self>
Create an Ed25519 key pair from private key bytes.
This function reconstructs a key pair from a previously saved private key. The public key is automatically derived from the private key.
§Arguments
bytes- Private key bytes (32 bytes)
§Returns
Ok(Ed25519Key)- Reconstructed key pairErr(BottleError::InvalidKeyType)- If the key format is invalid
§Example
use rust_bottle::keys::Ed25519Key;
use rand::rngs::OsRng;
let rng = &mut OsRng;
let original = Ed25519Key::generate(rng);
let priv_bytes = original.private_key_bytes();
let restored = Ed25519Key::from_private_key_bytes(&priv_bytes).unwrap();
assert_eq!(original.public_key_bytes(), restored.public_key_bytes());Trait Implementations§
Source§impl Clone for Ed25519Key
impl Clone for Ed25519Key
Source§fn clone(&self) -> Ed25519Key
fn clone(&self) -> Ed25519Key
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Sign for Ed25519Key
impl Sign for Ed25519Key
Source§fn sign(&self, _rng: &mut dyn RngCore, message: &[u8]) -> Result<Vec<u8>>
fn sign(&self, _rng: &mut dyn RngCore, message: &[u8]) -> Result<Vec<u8>>
Sign a message using Ed25519.
Ed25519 signs messages directly without pre-hashing. The signature is deterministic and always 64 bytes.
§Arguments
_rng- Random number generator (not used for deterministic signing)message- The message to sign
§Returns
Ok(Vec<u8>)- Signature bytes (64 bytes)Err(BottleError::VerifyFailed)- If signing fails
Source§impl SignerKey for Ed25519Key
impl SignerKey for Ed25519Key
Source§impl Verify for Ed25519Key
impl Verify for Ed25519Key
Source§fn verify(&self, message: &[u8], signature: &[u8]) -> Result<()>
fn verify(&self, message: &[u8], signature: &[u8]) -> Result<()>
Verify an Ed25519 signature.
The message is verified directly without pre-hashing. The signature must be 64 bytes.
§Arguments
message- The original messagesignature- The signature to verify (64 bytes)
§Returns
Ok(())- Signature is validErr(BottleError::VerifyFailed)- If signature verification fails
§Example
use rust_bottle::keys::Ed25519Key;
use rust_bottle::signing::{Sign, Verify};
use rand::rngs::OsRng;
let rng = &mut OsRng;
let key = Ed25519Key::generate(rng);
let message = b"Test message";
let signature = key.sign(rng, message).unwrap();
assert!(key.verify(message, &signature).is_ok());