X25519Key

Struct X25519Key 

Source
pub struct X25519Key { /* private fields */ }
Expand description

X25519 key pair for ECDH encryption.

X25519 is the Diffie-Hellman function over Curve25519. It is used for key exchange and encryption, not for signing. X25519 keys are 32 bytes for both private and public keys.

§Example

use rust_bottle::keys::X25519Key;
use rand::rngs::OsRng;

let rng = &mut OsRng;
let key = X25519Key::generate(rng);
let pub_key = key.public_key_bytes();
let priv_key = key.private_key_bytes();

Implementations§

Source§

impl X25519Key

Source

pub fn generate<R: RngCore>(rng: &mut R) -> Self

Generate a new X25519 key pair.

This function generates a cryptographically secure key pair using the provided random number generator.

§Arguments
  • rng - A random number generator
§Returns

A new X25519Key instance with a randomly generated key pair

§Example
use rust_bottle::keys::X25519Key;
use rand::rngs::OsRng;

let rng = &mut OsRng;
let key = X25519Key::generate(rng);
Source

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

Get the public key bytes.

X25519 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.

X25519 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 X25519 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(X25519Key) - Reconstructed key pair
  • Err(BottleError::InvalidKeyType) - If the key format is invalid
§Example
use rust_bottle::keys::X25519Key;
use rand::rngs::OsRng;

let rng = &mut OsRng;
let original = X25519Key::generate(rng);
let priv_bytes = original.private_key_bytes();

let restored = X25519Key::from_private_key_bytes(&priv_bytes).unwrap();
assert_eq!(original.public_key_bytes(), restored.public_key_bytes());

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> 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, 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