Ed25519Key

Struct Ed25519Key 

Source
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

Source

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);
Source

pub fn public_key_bytes(&self) -> Vec<u8>

Get the public key bytes.

Ed25519 public keys are 32 bytes.

§Returns

Public key bytes (32 bytes)

Source

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.

Source

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 pair
  • Err(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

Source§

fn clone(&self) -> Ed25519Key

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Sign for Ed25519Key

Source§

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

Source§

fn fingerprint(&self) -> Vec<u8>

Get the public key fingerprint (SHA-256 hash).

The fingerprint is used to identify keys in keychains and IDCards.

§Returns

SHA-256 hash of the public key bytes

Source§

fn public_key(&self) -> Vec<u8>

Get the public key bytes.

§Returns

Public key bytes (32 bytes)

Source§

impl Verify for Ed25519Key

Source§

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 message
  • signature - The signature to verify (64 bytes)
§Returns
  • Ok(()) - Signature is valid
  • Err(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());

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V