pub enum Key {
Public(PublicKey),
Private(PrivateKey),
}Expand description
A key that is either public or private.
Variants§
Public(PublicKey)
Private(PrivateKey)
Implementations§
Source§impl Key
impl Key
Sourcepub fn as_public(&self) -> Option<&PublicKey>
pub fn as_public(&self) -> Option<&PublicKey>
Returns a reference to the inner PublicKey if this is a public key.
Sourcepub fn as_private(&self) -> Option<&PrivateKey>
pub fn as_private(&self) -> Option<&PrivateKey>
Returns a reference to the inner PrivateKey if this is a private key.
Sourcepub fn into_public(self) -> Option<PublicKey>
pub fn into_public(self) -> Option<PublicKey>
Consumes self and returns the inner PublicKey if this is a public key.
Sourcepub fn into_private(self) -> Option<PrivateKey>
pub fn into_private(self) -> Option<PrivateKey>
Consumes self and returns the inner PrivateKey if this is a private key.
Sourcepub fn from_der(der: &[u8]) -> Result<Self>
pub fn from_der(der: &[u8]) -> Result<Self>
Decode a DER-encoded key (auto-detecting SPKI or PKCS8).
Sourcepub fn to_der(&self) -> Vec<u8> ⓘ
pub fn to_der(&self) -> Vec<u8> ⓘ
Encode this key as DER, returning a new Vec<u8>.
Note: For private keys, prefer using PrivateKey::to_der() directly
to get a Zeroizing<Vec<u8>> wrapper that auto-zeroizes on drop.
Sourcepub fn encode_der_to(&self, out: &mut Vec<u8>)
pub fn encode_der_to(&self, out: &mut Vec<u8>)
Encode this key as DER into the given buffer.
Trait Implementations§
Source§impl From<PrivateKey> for Key
impl From<PrivateKey> for Key
Source§fn from(key: PrivateKey) -> Self
fn from(key: PrivateKey) -> Self
Converts to this type from the input type.
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnsafeUnpin for Key
impl UnwindSafe for Key
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