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

A cryptographic key pair.

A KeyPair is a combination of public and secret key. This particular implementation does not have the secret key, but diverges the cryptographic operations to gpg-agent.

This provides a convenient, synchronous interface for use with the low-level Sequoia crate.

Implementations§

source§

impl KeyPair

source

pub fn new_for_gnupg_context<R>( ctx: &Context, key: &Key<PublicParts, R> ) -> Result<KeyPair>
where R: KeyRole,

Returns a KeyPair for key with the secret bits managed by the agent.

This provides a convenient, synchronous interface for use with the low-level Sequoia crate.

source

pub fn new_for_socket<P, R>( agent_socket: P, key: &Key<PublicParts, R> ) -> Result<KeyPair>
where P: AsRef<Path>, R: KeyRole,

Returns a KeyPair for key with the secret bits managed by the agent.

If you have a Agent, then you should create a KeyPair using Agent::keypair.

source

pub fn with_cert(self, cert: &ValidCert<'_>) -> Self

Changes the password prompt to include information about the cert.

Use this function to give more context to the user when she is prompted for a password. This function will generate a prompt that is very similar to the prompts that GnuPG generates.

To set an arbitrary password prompt, use KeyPair::with_password_prompt.

source

pub fn with_password(self, password: Password) -> Self

Supplies a password to unlock the secret key.

This will be used when the secret key operation is performed, e.g. when signing or decrypting a message.

Note: This is the equivalent of GnuPG’s --pinentry-mode=loopback and requires explicit opt-in in the gpg-agent configuration using the allow-loopback-pinentry option. If this is not enabled in the agent, the secret key operation will fail. It is likely only useful during testing.

source

pub fn set_pinentry_mode(self, mode: PinentryMode) -> Self

Overrides the pinentry mode.

source

pub fn suppress_pinentry(self) -> Self

Disables gpg’s pinentry.

Changes the pinentry mode to PinEntryMode::Error, which configures the agent to not ask for a password.

source

pub fn with_password_prompt(self, prompt: String) -> Self

Changes the password prompt.

Use this function to give more context to the user when she is prompted for a password.

To set an password prompt that uses information from the OpenPGP certificate, use KeyPair::with_cert.

source§

impl KeyPair

source

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

Signs a message.

An async implementation of sequoia_openpgp::crypto::Signer::sign.

source§

impl KeyPair

source

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

Decrypts a message.

An async implementation of sequoia_openpgp::crypto::Decryptor::decrypt.

Trait Implementations§

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 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more