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
impl KeyPair
sourcepub fn new(
public: Key<PublicParts, UnspecifiedRole>,
secret: Unencrypted,
) -> Result<Self>
pub fn new( public: Key<PublicParts, UnspecifiedRole>, secret: Unencrypted, ) -> Result<Self>
Creates a new key pair.
sourcepub fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
pub fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
Returns a reference to the public key.
sourcepub fn secret(&self) -> &Unencrypted
pub fn secret(&self) -> &Unencrypted
Returns a reference to the secret key.
Trait Implementations§
source§impl Decryptor for KeyPair
impl Decryptor for KeyPair
source§fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
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>
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>
impl From<KeyPair> for Key<SecretParts, UnspecifiedRole>
source§impl Signer for KeyPair
impl Signer for KeyPair
source§fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
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>
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]
fn acceptable_hashes(&self) -> &[HashAlgorithm]
Returns a list of hashes that this signer accepts. Read more
Auto Trait Implementations§
impl !Freeze for KeyPair
impl RefUnwindSafe for KeyPair
impl Send for KeyPair
impl Sync for KeyPair
impl Unpin for KeyPair
impl UnwindSafe for KeyPair
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)