From 41fd3f08adff856ec558f8b06214e0f392893a26 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 5 Dec 2019 16:13:54 +0100 Subject: openpgp: Make crypto::{Signer,Decryptor} non-polymorphic. - These are low-level cryptographic traits that are not concerned with the role of a key. - Fixes #382. --- openpgp/src/crypto/asymmetric.rs | 48 ++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) (limited to 'openpgp/src/crypto') diff --git a/openpgp/src/crypto/asymmetric.rs b/openpgp/src/crypto/asymmetric.rs index e67461ce..7185a471 100644 --- a/openpgp/src/crypto/asymmetric.rs +++ b/openpgp/src/crypto/asymmetric.rs @@ -16,19 +16,17 @@ use crate::Result; /// signature. Using this trait allows Sequoia to perform all /// operations involving signing to use a variety of secret key /// storage mechanisms (e.g. smart cards). -pub trait Signer - where R: key::KeyRole -{ +pub trait Signer { /// Returns a reference to the public key. - fn public(&self) -> &Key; + fn public(&self) -> &Key; /// Creates a signature over the `digest` produced by `hash_algo`. fn sign(&mut self, hash_algo: HashAlgorithm, digest: &[u8]) -> Result; } -impl Signer for Box> { - fn public(&self) -> &Key { +impl Signer for Box { + fn public(&self) -> &Key { self.as_ref().public() } @@ -44,11 +42,9 @@ impl Signer for Box> { /// ciphertext. Using this trait allows Sequoia to perform all /// operations involving decryption to use a variety of secret key /// storage mechanisms (e.g. smart cards). -pub trait Decryptor - where R: key::KeyRole -{ +pub trait Decryptor { /// Returns a reference to the public key. - fn public(&self) -> &Key; + fn public(&self) -> &Key; /// Decrypts `ciphertext`, returning the plain session key. fn decrypt(&mut self, ciphertext: &mpis::Ciphertext) @@ -64,18 +60,14 @@ pub trait Decryptor /// [`Signer`]: trait.Signer.html /// [`Decryptor`]: trait.Decryptor.html #[derive(Clone)] -pub struct KeyPair - where R: key::KeyRole -{ - public: Key, +pub struct KeyPair { + public: Key, secret: packet::key::Unencrypted, } -impl KeyPair - where R: key::KeyRole -{ +impl KeyPair { /// Creates a new key pair. - pub fn new(public: Key, + pub fn new(public: Key, secret: packet::key::Unencrypted) -> Result { @@ -86,7 +78,7 @@ impl KeyPair } /// Returns a reference to the public key. - pub fn public(&self) -> &Key { + pub fn public(&self) -> &Key { &self.public } @@ -96,10 +88,8 @@ impl KeyPair } } -impl Signer for KeyPair - where R: key::KeyRole -{ - fn public(&self) -> &Key { +impl Signer for KeyPair { + fn public(&self) -> &Key { &self.public } @@ -226,10 +216,8 @@ impl Signer for KeyPair } } -impl Decryptor for KeyPair - where R: key::KeyRole -{ - fn public(&self) -> &Key { +impl Decryptor for KeyPair { + fn public(&self) -> &Key { &self.public } @@ -274,10 +262,8 @@ impl Decryptor for KeyPair } } -impl From> for Key - where R: key::KeyRole -{ - fn from(p: KeyPair) -> Self { +impl From for Key { + fn from(p: KeyPair) -> Self { let (mut key, secret) = (p.public, p.secret); key.set_secret(Some(secret.into())); key.mark_parts_secret().expect("XXX") -- cgit v1.2.3