pub struct PublicKey { /* private fields */ }Expand description
Public key for verifying Chio signatures.
Internally this is a sum over the supported SigningAlgorithms. The
common case (Ed25519) preserves the bare 32-byte encoding and bare
hex serialization. Non-Ed25519 variants use a self-describing hex prefix
(p256:<hex> / p384:<hex> / hybrid:<classical>:<pq>:<alg_set>) so the
wire format unambiguously identifies the algorithm without a separate
envelope field.
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn from_bytes(bytes: &[u8; 32]) -> Result<PublicKey, Error>
pub fn from_bytes(bytes: &[u8; 32]) -> Result<PublicKey, Error>
Create from raw bytes (32 bytes). Produces an Ed25519 key.
Sourcepub fn from_p256_sec1(bytes: &[u8]) -> Result<PublicKey, Error>
pub fn from_p256_sec1(bytes: &[u8]) -> Result<PublicKey, Error>
Create a P-256 public key from uncompressed SEC1-encoded bytes
(65 bytes beginning with 0x04).
The bytes are validated only for length and leading-byte format; full curve-point validation is delegated to the verifier at first use.
Sourcepub fn from_p384_sec1(bytes: &[u8]) -> Result<PublicKey, Error>
pub fn from_p384_sec1(bytes: &[u8]) -> Result<PublicKey, Error>
Create a P-384 public key from uncompressed SEC1-encoded bytes
(97 bytes beginning with 0x04).
Sourcepub fn from_hybrid_parts(
classical: PublicKey,
pq: &[u8],
alg_set: &str,
) -> Result<PublicKey, Error>
pub fn from_hybrid_parts( classical: PublicKey, pq: &[u8], alg_set: &str, ) -> Result<PublicKey, Error>
Create a hybrid public key from a classical public key and ML-DSA-65 public-key bytes.
Sourcepub fn from_hex(hex_str: &str) -> Result<PublicKey, Error>
pub fn from_hex(hex_str: &str) -> Result<PublicKey, Error>
Create from hex-encoded bytes (with optional 0x prefix).
The string may carry a p256: or p384: prefix to select an ECDSA
key. Bare hex strings are interpreted as Ed25519 (the default algorithm).
Sourcepub fn algorithm(&self) -> SigningAlgorithm
pub fn algorithm(&self) -> SigningAlgorithm
Which algorithm this public key belongs to.
Sourcepub fn verify(&self, message: &[u8], signature: &Signature) -> bool
pub fn verify(&self, message: &[u8], signature: &Signature) -> bool
Verify a signature against a message.
Returns false when algorithms differ between key and signature, or
when the cryptographic check fails. Never panics.
Sourcepub fn verify_canonical<T>(
&self,
value: &T,
signature: &Signature,
) -> Result<bool, Error>where
T: Serialize,
pub fn verify_canonical<T>(
&self,
value: &T,
signature: &Signature,
) -> Result<bool, Error>where
T: Serialize,
Verify a signature over the canonical JSON form of a serializable value.
Verify a signature over shared canonical JSON bytes.
Sourcepub fn verify_canonical_bytes(
&self,
canonical: &CanonicalBytes,
signature: &Signature,
) -> bool
pub fn verify_canonical_bytes( &self, canonical: &CanonicalBytes, signature: &Signature, ) -> bool
Verify a signature over canonical JSON bytes without reserializing.
Sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Hex encoding, with algorithm prefix for non-Ed25519 keys.
Ed25519 keys render as a bare 64-character lowercase hex string. P-256 keys render as
p256:<130-char hex> (uncompressed SEC1). P-384 keys render as
p384:<194-char hex>.
Sourcepub fn as_bytes(&self) -> &[u8; 32]
pub fn as_bytes(&self) -> &[u8; 32]
Raw 32-byte Ed25519 representation.
This accessor is intentionally Ed25519-only. Non-Ed25519 callers must
use Self::to_hex or another algorithm-aware representation instead
of coercing P-256 / P-384 material into a lossy 32-byte placeholder.
§Panics
Panics when called on a non-Ed25519 key so Ed25519-only consumers fail closed instead of silently collapsing distinct keys onto the same bytes.