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 historical 32-byte encoding and bare
hex serialization. Non-Ed25519 variants use a self-describing hex prefix
(p256:<hex> / p384:<hex>) 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_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. A bare hex string is interpreted as Ed25519 for backward
compatibility with existing artifacts.
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.
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,
byte-identical to the historical format. 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.