KeyPair

Enum KeyPair 

Source
pub enum KeyPair {
    Ed25519(Box<SigningKey>),
    MlDsa44(Box<MLDSA44KeyPair>, Hash),
    MlDsa65(Box<MLDSA65KeyPair>, Hash),
    MlDsa87(Box<MLDSA87KeyPair>, Hash),
}

Variants§

§

Ed25519(Box<SigningKey>)

§

MlDsa44(Box<MLDSA44KeyPair>, Hash)

§

MlDsa65(Box<MLDSA65KeyPair>, Hash)

§

MlDsa87(Box<MLDSA87KeyPair>, Hash)

Implementations§

Source§

impl KeyPair

Source

pub fn id(&self) -> KeyId

Source

pub fn public_key(&self) -> VerifyingKey

Source

pub fn algorithm(&self) -> Algorithm

Get the algorithm for this key type

Source§

impl KeyPair

Source

pub fn sign(&self, message: &[u8]) -> Signature

Source

pub fn generate_ml_dsa44<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair

Source

pub fn generate_ml_dsa65<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair

Source

pub fn generate_ml_dsa87<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair

Source

pub fn generate<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair

Source

pub fn generate_for_algorithm<R: CryptoRng + RngCore>( algorithm: Algorithm, rng: &mut R, ) -> KeyPair

Source

pub fn generate_ed25519<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair

Source

pub fn to_pem(&self) -> Result<String, KeyPairError>

Encode the KeyPair to a PEM string suitable for environment variables or file storage.

This method creates PEM blocks containing:

  • For Ed25519: Only the private key (public key can be derived)
  • For ML-DSA: Both private and public keys in separate PEM blocks (hash is derived from public key)

All PEM blocks are prefixed with “ZOE” to identify them as Zoe-specific formats.

§Returns

A PEM-formatted string containing the key data.

§Examples
use zoe_wire_protocol::KeyPair;
use rand::rngs::OsRng;

let keypair = KeyPair::generate_ed25519(&mut OsRng);
let pem_string = keypair.to_pem().unwrap();

// Store in environment variable or file
std::env::set_var("MY_PRIVATE_KEY", &pem_string);
Source

pub fn from_pem(pem_string: &str) -> Result<KeyPair, KeyPairError>

Decode a KeyPair from a PEM string.

This method can parse PEM files created by to_pem(), using parse_many to read multiple PEM blocks and automatically detecting the key type from the PEM labels to reconstruct the appropriate KeyPair.

§Arguments
  • pem_string - The PEM-formatted string containing key data
§Returns

A KeyPair instance reconstructed from the PEM data.

§Examples
use zoe_wire_protocol::KeyPair;
use rand::rngs::OsRng;

let original = KeyPair::generate_ed25519(&mut OsRng);
let pem_string = original.to_pem().unwrap();
let restored = KeyPair::from_pem(&pem_string).unwrap();

assert_eq!(original.public_key(), restored.public_key());

Trait Implementations§

Source§

impl Debug for KeyPair

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for KeyPair

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&KeyPair> for VerifyingKey

Source§

fn from(val: &KeyPair) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for KeyPair

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<T> Classify for T

§

type Classified = T

§

fn classify(self) -> T

§

impl<T> Classify for T

§

type Classified = T

§

fn classify(self) -> T

§

impl<T> Declassify for T

§

type Declassified = T

§

fn declassify(self) -> T

§

impl<T> Declassify for T

§

type Declassified = T

§

fn declassify(self) -> T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DartSafe for T

§

impl<T> TaskRetFutTrait for T
where T: Send,