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
sourceimpl 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
sourceimpl Decryptor for KeyPair
impl Decryptor for KeyPair
sourcefn public(&self) -> &Key<PublicParts, UnspecifiedRole>
fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
Returns a reference to the public key.
sourcefn 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.
sourceimpl From<KeyPair> for Key<SecretParts, UnspecifiedRole>
impl From<KeyPair> for Key<SecretParts, UnspecifiedRole>
sourceimpl Signer for KeyPair
impl Signer for KeyPair
sourcefn public(&self) -> &Key<PublicParts, UnspecifiedRole>
fn public(&self) -> &Key<PublicParts, UnspecifiedRole>
Returns a reference to the public key.
sourcefn 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
.
sourcefn acceptable_hashes(&self) -> &[HashAlgorithm]
fn acceptable_hashes(&self) -> &[HashAlgorithm]
Returns a list of hashes that this signer accepts. Read more
Auto Trait Implementations
impl RefUnwindSafe for KeyPair
impl Send for KeyPair
impl Sync for KeyPair
impl Unpin for KeyPair
impl UnwindSafe for KeyPair
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more