Struct sequoia_openpgp::crypto::KeyPair

source ·
pub struct KeyPair { /* private fields */ }
Expand description

A cryptographic key pair.

A KeyPair is a combination of public and secret key. If both are available in memory, a KeyPair is a convenient implementation of Signer and Decryptor.

§Examples

use sequoia_openpgp as openpgp;
use openpgp::types::Curve;
use openpgp::cert::prelude::*;
use openpgp::packet::prelude::*;

// Conveniently create a KeyPair from a bare key:
let keypair =
    Key4::<_, key::UnspecifiedRole>::generate_ecc(false, Curve::Cv25519)?
        .into_keypair()?;

// Or from a query over a certificate:
let (cert, _) =
    CertBuilder::general_purpose(None, Some("alice@example.org"))
        .generate()?;
let keypair =
    cert.keys().unencrypted_secret().nth(0).unwrap().key().clone()
        .into_keypair()?;

Implementations§

source§

impl KeyPair

source

pub fn new( public: Key<PublicParts, UnspecifiedRole>, secret: Unencrypted, ) -> Result<Self>

Creates a new key pair.

source

pub fn public(&self) -> &Key<PublicParts, UnspecifiedRole>

Returns a reference to the public key.

source

pub fn secret(&self) -> &Unencrypted

Returns a reference to the secret key.

Trait Implementations§

source§

impl Clone for KeyPair

source§

fn clone(&self) -> KeyPair

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Decryptor for KeyPair

source§

fn public(&self) -> &Key<PublicParts, UnspecifiedRole>

Returns a reference to the public key.
source§

fn decrypt( &mut self, ciphertext: &Ciphertext, plaintext_len: Option<usize>, ) -> Result<SessionKey>

Decrypts ciphertext, returning the plain session key.
source§

impl From<KeyPair> for Key<SecretParts, UnspecifiedRole>

source§

fn from(p: KeyPair) -> Self

Converts to this type from the input type.
source§

impl Signer for KeyPair

source§

fn public(&self) -> &Key<PublicParts, UnspecifiedRole>

Returns a reference to the public key.
source§

fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) -> Result<Signature>

Creates a signature over the digest produced by hash_algo.
source§

fn acceptable_hashes(&self) -> &[HashAlgorithm]

Returns a list of hashes that this signer accepts. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T