From a23eea3df204e29d6effe37a40b8bc560339ed78 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 21 Apr 2022 14:00:08 +0200 Subject: ipc: Make KeyPair own the public key. - This way we get rid of the lifetime and make the KeyPair much more ergonomic. --- ipc/src/gnupg.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'ipc') diff --git a/ipc/src/gnupg.rs b/ipc/src/gnupg.rs index d105ccb9..86fe4f85 100644 --- a/ipc/src/gnupg.rs +++ b/ipc/src/gnupg.rs @@ -344,7 +344,7 @@ impl Agent { /// Creates a signature over the `digest` produced by `algo` using /// `key` with the secret bits managed by the agent. pub async fn sign<'a>(&'a mut self, - key: &'a KeyPair<'a>, + key: &'a KeyPair, algo: HashAlgorithm, digest: &'a [u8]) -> Result { @@ -354,7 +354,7 @@ impl Agent { /// Decrypts `ciphertext` using `key` with the secret bits managed /// by the agent. pub async fn decrypt<'a>(&'a mut self, - key: &'a KeyPair<'a>, + key: &'a KeyPair, ciphertext: &'a crypto::mpi::Ciphertext) -> Result { @@ -409,7 +409,7 @@ impl Agent { struct SigningRequest<'a, 'b, 'c> { c: &'a mut assuan::Client, - key: &'b KeyPair<'b>, + key: &'b KeyPair, algo: HashAlgorithm, digest: &'c [u8], options: Vec, @@ -419,7 +419,7 @@ struct SigningRequest<'a, 'b, 'c> impl<'a, 'b, 'c> SigningRequest<'a, 'b, 'c> { fn new(c: &'a mut assuan::Client, - key: &'b KeyPair<'b>, + key: &'b KeyPair, algo: HashAlgorithm, digest: &'c [u8]) -> Self { @@ -593,7 +593,7 @@ impl<'a, 'b, 'c> Future for SigningRequest<'a, 'b, 'c> struct DecryptionRequest<'a, 'b, 'c> { c: &'a mut assuan::Client, - key: &'b KeyPair<'b>, + key: &'b KeyPair, ciphertext: &'c crypto::mpi::Ciphertext, options: Vec, state: DecryptionRequestState, @@ -602,7 +602,7 @@ struct DecryptionRequest<'a, 'b, 'c> impl<'a, 'b, 'c> DecryptionRequest<'a, 'b, 'c> { fn new(c: &'a mut assuan::Client, - key: &'b KeyPair<'b>, + key: &'b KeyPair, ciphertext: &'c crypto::mpi::Ciphertext) -> Self { Self { @@ -779,20 +779,20 @@ impl<'a, 'b, 'c> Future for DecryptionRequest<'a, 'b, 'c> /// 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`. -pub struct KeyPair<'a> { - public: &'a Key, +pub struct KeyPair { + public: Key, agent_socket: PathBuf, password_prompt: String, } -impl<'a> KeyPair<'a> { +impl KeyPair { /// 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. - pub fn new(ctx: &Context, key: &'a Key) - -> Result> + pub fn new(ctx: &Context, key: &Key) + -> Result where R: key::KeyRole { Ok(KeyPair { @@ -801,7 +801,7 @@ impl<'a> KeyPair<'a> { unlock the OpenPGP secret key:\n\ ID {:X}, created {}.", key.keyid(), Timestamp::try_from(key.creation_time()).unwrap()), - public: key.role_as_unspecified(), + public: key.role_as_unspecified().clone(), agent_socket: ctx.socket("agent")?.into(), }) } @@ -878,9 +878,9 @@ impl<'a> KeyPair<'a> { } } -impl<'a> crypto::Signer for KeyPair<'a> { +impl crypto::Signer for KeyPair { fn public(&self) -> &Key { - self.public + &self.public } fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) @@ -913,9 +913,9 @@ impl<'a> crypto::Signer for KeyPair<'a> { } } -impl<'a> crypto::Decryptor for KeyPair<'a> { +impl crypto::Decryptor for KeyPair { fn public(&self) -> &Key { - self.public + &self.public } fn decrypt(&mut self, ciphertext: &crypto::mpi::Ciphertext, -- cgit v1.2.3