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
impl KeyPair
pub fn id(&self) -> KeyId
pub fn public_key(&self) -> VerifyingKey
Source§impl KeyPair
impl KeyPair
pub fn sign(&self, message: &[u8]) -> Signature
pub fn generate_ml_dsa44<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair
pub fn generate_ml_dsa65<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair
pub fn generate_ml_dsa87<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair
pub fn generate<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair
pub fn generate_for_algorithm<R: CryptoRng + RngCore>( algorithm: Algorithm, rng: &mut R, ) -> KeyPair
pub fn generate_ed25519<R: CryptoRng + RngCore>(rng: &mut R) -> KeyPair
Sourcepub fn to_pem(&self) -> Result<String, KeyPairError>
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);Sourcepub fn from_pem(pem_string: &str) -> Result<KeyPair, KeyPairError>
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 From<&KeyPair> for VerifyingKey
impl From<&KeyPair> for VerifyingKey
Auto Trait Implementations§
impl Freeze for KeyPair
impl RefUnwindSafe for KeyPair
impl Send for KeyPair
impl Sync for KeyPair
impl Unpin for KeyPair
impl UnwindSafe for KeyPair
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more