pub struct PublicKey { /* private fields */ }Expand description
A public key the caller trusts.
Experimental: may change in a 0.x minor release.
Accepted encodings, recognised by exact length and fixed header bytes rather than by a general ASN.1 parser:
- a PEM
PUBLIC KEYblock (asopenssl pkey -puboutwrites it) holding one of the DER forms below; - DER
SubjectPublicKeyInfoof an Ed25519 key (44 bytes) or a P-256 key with an uncompressed point (91 bytes); - the raw 32-byte Ed25519 key, or the raw 65-byte uncompressed P-256 point.
Self::fingerprint is the SHA-256 of the DER SubjectPublicKeyInfo,
the same value as openssl pkey -pubin -outform DER | sha256sum.
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn parse(bytes: &[u8]) -> Result<Self, KeyError>
pub fn parse(bytes: &[u8]) -> Result<Self, KeyError>
Parse a public key in one of the accepted encodings.
use libtea_client::signature::{KeyAlgorithm, PublicKey};
let key = PublicKey::parse(&[7; 32]).unwrap();
assert_eq!(key.algorithm(), KeyAlgorithm::Ed25519);
assert!(key.fingerprint().starts_with("sha256:"));
assert!(PublicKey::parse(b"not a key").is_err());§Errors
KeyError when the bytes are not an accepted encoding. A P-256 point
that is not on the curve is not detected here; no signature verifies
under it.
Sourcepub fn algorithm(&self) -> KeyAlgorithm
pub fn algorithm(&self) -> KeyAlgorithm
The algorithm.
Sourcepub fn fingerprint(&self) -> &str
pub fn fingerprint(&self) -> &str
sha256: and the lowercase hex SHA-256 of the DER SubjectPublicKeyInfo.
Trait Implementations§
impl Eq for PublicKey
impl StructuralPartialEq for PublicKey
Auto Trait Implementations§
impl Forget for PublicKey
impl Freeze for PublicKey
impl Move for PublicKey
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnsafeUnpin for PublicKey
impl UnwindSafe for PublicKey
Blanket Implementations§
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