pub struct PublicKeyDer(/* private fields */);Expand description
A public key in SubjectPublicKeyInfo (SPKI) DER form.
The one encoding a public key travels in inside Rite. PEM belongs at the edges, where a key is read from a file or written to one.
Implementations§
Source§impl PublicKeyDer
impl PublicKeyDer
Sourcepub fn new(der: Vec<u8>) -> Result<Self, BackendError>
pub fn new(der: Vec<u8>) -> Result<Self, BackendError>
Wrap SPKI DER bytes after checking they parse.
Takes ownership because callers hold the bytes a backend or a parser just produced, and the type keeps them.
§Errors
Returns BackendError::InvalidKeyFormat when the bytes are not a
SubjectPublicKeyInfo, which is what a certificate or a PEM armouring
arriving here looks like.
Sourcepub fn from_key_material(bytes: &[u8]) -> Result<Self, BackendError>
pub fn from_key_material(bytes: &[u8]) -> Result<Self, BackendError>
Read a public key out of whatever a ceremony hands over.
Accepts the four shapes a signer’s key arrives in: SPKI DER, SPKI PEM, certificate DER, and certificate PEM. A key loaded from a file is PEM more often than not, and a counterparty usually sends a certificate rather than a bare key, so refusing either would push the conversion onto the ceremony author.
Use PublicKeyDer::new where the encoding is already known; this is
for the boundary where it is not.
§Errors
Returns BackendError::InvalidKeyFormat when the bytes are none of
the four, naming what was accepted.
Sourcepub fn algorithm(&self) -> Result<KeyAlgorithm, BackendError>
pub fn algorithm(&self) -> Result<KeyAlgorithm, BackendError>
The key algorithm, read from the key’s own structure.
Key bytes carry no ceremony metadata, so a caller that must know what it
is holding, to pick a signature algorithm for instance, recovers it from
the AlgorithmIdentifier. RSA is the one case the identifier does not
settle: it names rsaEncryption without a size, so the modulus decides.
§Errors
Returns BackendError::UnsupportedAlgorithm for a key type or size
Rite has no KeyAlgorithm for, and BackendError::InvalidKeyFormat
when an RSA key’s modulus cannot be read.
Trait Implementations§
Source§impl Clone for PublicKeyDer
impl Clone for PublicKeyDer
Source§fn clone(&self) -> PublicKeyDer
fn clone(&self) -> PublicKeyDer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more