pub enum VerifyingKey {
Ed25519(Box<VerifyingKey>),
MlDsa44((Box<MLDSA44VerificationKey>, Hash)),
MlDsa65((Box<MLDSA65VerificationKey>, Hash)),
MlDsa87((Box<MLDSA87VerificationKey>, Hash)),
}Expand description
Public key for signature verification supporting multiple algorithms.
This enum provides a unified interface for verifying signatures across different cryptographic algorithms, supporting both classical and post-quantum schemes.
§Algorithm Selection
- Ed25519: Use for legacy compatibility and smaller key sizes
- ML-DSA-44: Use for TLS certificates requiring post-quantum security
- ML-DSA-65: Use for message signatures with strong post-quantum security
- ML-DSA-87: Use for high-security applications requiring maximum protection
§Examples
use zoe_wire_protocol::{VerifyingKey, SigningKey, KeyPair};
use rand::rngs::OsRng;
// Generate a keypair
let keypair = KeyPair::generate(&mut OsRng);
let verifying_key = keypair.public_key();
// Sign and verify a message
let message = b"Hello, world!";
let signature = keypair.sign(message);
let is_valid = verifying_key.verify(message, &signature)?;
assert!(is_valid);Variants§
Ed25519(Box<VerifyingKey>)
Ed25519 public key (32 bytes)
MlDsa44((Box<MLDSA44VerificationKey>, Hash))
ML-DSA-44 public key (1,312 bytes) - for TLS certificates
MlDsa65((Box<MLDSA65VerificationKey>, Hash))
ML-DSA-65 public key (1,952 bytes) - for message signatures
MlDsa87((Box<MLDSA87VerificationKey>, Hash))
ML-DSA-87 public key (2,592 bytes) - for high security
Implementations§
Source§impl VerifyingKey
flutter_rust_bridge:opaque
impl VerifyingKey
flutter_rust_bridge:opaque
Sourcepub fn verify(
&self,
message: &[u8],
signature: &Signature,
) -> Result<(), VerifyError>
pub fn verify( &self, message: &[u8], signature: &Signature, ) -> Result<(), VerifyError>
Verify a signature against a message using the appropriate algorithm.
This method automatically matches the signature type with the key type
and returns Ok(false) if they don’t match (rather than an error).
§Arguments
message- The message bytes that were signedsignature- The signature to verify
§Returns
Ok(true)- Signature is valid for this key and messageOk(false)- Signature is invalid or key/signature types don’t matchErr(_)- Verification error (malformed signature, etc.)
§Examples
use zoe_wire_protocol::{KeyPair, VerifyingKey, SigningKey};
use rand::rngs::OsRng;
let keypair = KeyPair::generate_ed25519(&mut OsRng);
let message = b"Hello, world!";
let signature = keypair.sign(message);
let verifying_key = keypair.public_key();
let is_valid = verifying_key.verify(message, &signature)?;
assert!(is_valid);Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Encode the VerifyingKey to bytes for serialization.
This method serializes the key using postcard format for efficient storage
and transmission. The resulting bytes can be deserialized back to a
VerifyingKey using postcard::from_bytes().
§Returns
A Vec<u8> containing the serialized key data.
§Examples
use zoe_wire_protocol::{KeyPair, VerifyingKey};
use rand::rngs::OsRng;
let keypair = KeyPair::generate_ed25519(&mut OsRng);
let verifying_key = keypair.public_key();
// Serialize the key
let key_bytes = verifying_key.encode();
// Deserialize it back
let restored_key: VerifyingKey = postcard::from_bytes(&key_bytes).unwrap();
assert_eq!(&verifying_key, &restored_key);pub fn id(&self) -> KeyId
pub fn to_bytes(&self) -> Result<Vec<u8>, Error>
pub fn from_hex(hex: String) -> Result<Self, String>
Sourcepub fn to_pem(&self) -> Result<String, VerifyingKeyError>
pub fn to_pem(&self) -> Result<String, VerifyingKeyError>
Export the VerifyingKey to PEM format.
This method serializes the key using postcard format and then encodes it as a PEM block with the label “ZOE PUBLIC KEY”. This provides a standardized text format that’s compatible with many cryptographic tools and libraries.
§Returns
A Result<String, VerifyingKeyError> containing the PEM-encoded key or an error.
§Examples
use zoe_wire_protocol::{KeyPair, VerifyingKey};
use rand::rngs::OsRng;
let keypair = KeyPair::generate_ed25519(&mut OsRng);
let verifying_key = keypair.public_key();
let pem_string = verifying_key.to_pem().unwrap();
println!("Public key PEM:\n{}", pem_string);Sourcepub fn from_pem(pem_string: &str) -> Result<VerifyingKey, VerifyingKeyError>
pub fn from_pem(pem_string: &str) -> Result<VerifyingKey, VerifyingKeyError>
Import a VerifyingKey from PEM format.
This method parses a PEM-encoded string and deserializes it back to a
VerifyingKey. The PEM block should have the label “ZOE PUBLIC KEY”.
§Arguments
pem_string- A string containing the PEM-encoded public key
§Returns
A Result<VerifyingKey, VerifyingKeyError> containing the decoded key or an error.
§Examples
use zoe_wire_protocol::{KeyPair, VerifyingKey};
use rand::rngs::OsRng;
let original_keypair = KeyPair::generate_ed25519(&mut OsRng);
let original_key = original_keypair.public_key();
let pem_string = original_key.to_pem().unwrap();
let restored_key = VerifyingKey::from_pem(&pem_string).unwrap();
assert_eq!(original_key.encode(), restored_key.encode());Trait Implementations§
Source§impl Clone for VerifyingKey
impl Clone for VerifyingKey
Source§fn clone(&self) -> VerifyingKey
fn clone(&self) -> VerifyingKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VerifyingKey
impl Debug for VerifyingKey
Source§impl<'de> Deserialize<'de> for VerifyingKey
impl<'de> Deserialize<'de> for VerifyingKey
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for VerifyingKey
impl Display for VerifyingKey
Source§impl From<&KeyPair> for VerifyingKey
impl From<&KeyPair> for VerifyingKey
Source§impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_44::MLDSA44VerificationKey::{constant#0}>> for VerifyingKey
impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_44::MLDSA44VerificationKey::{constant#0}>> for VerifyingKey
Source§impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_65::MLDSA65VerificationKey::{constant#0}>> for VerifyingKey
impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_65::MLDSA65VerificationKey::{constant#0}>> for VerifyingKey
Source§impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_87::MLDSA87VerificationKey::{constant#0}>> for VerifyingKey
impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_87::MLDSA87VerificationKey::{constant#0}>> for VerifyingKey
Source§impl Hash for VerifyingKey
impl Hash for VerifyingKey
Source§impl Ord for VerifyingKey
impl Ord for VerifyingKey
Source§impl PartialEq for VerifyingKey
impl PartialEq for VerifyingKey
Source§impl PartialOrd for VerifyingKey
impl PartialOrd for VerifyingKey
Source§impl Serialize for VerifyingKey
impl Serialize for VerifyingKey
Source§impl TryFrom<&[u8]> for VerifyingKey
impl TryFrom<&[u8]> for VerifyingKey
impl Eq for VerifyingKey
Auto Trait Implementations§
impl Freeze for VerifyingKey
impl RefUnwindSafe for VerifyingKey
impl Send for VerifyingKey
impl Sync for VerifyingKey
impl Unpin for VerifyingKey
impl UnwindSafe for VerifyingKey
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
§impl<T> Classify for T
impl<T> Classify for T
type Classified = T
fn classify(self) -> T
§impl<T> Classify for T
impl<T> Classify for T
type Classified = T
fn classify(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.