diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-12-05 16:13:54 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-12-05 16:21:52 +0100 |
commit | 41fd3f08adff856ec558f8b06214e0f392893a26 (patch) | |
tree | e7894d4e77074109692503fab3b3b46d343f70b6 /openpgp/src/packet | |
parent | 71a3a540bda400f52a841c04b8d33a51959fa8f0 (diff) |
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.
Diffstat (limited to 'openpgp/src/packet')
-rw-r--r-- | openpgp/src/packet/mod.rs | 9 | ||||
-rw-r--r-- | openpgp/src/packet/pkesk.rs | 3 | ||||
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 47 |
3 files changed, 25 insertions, 34 deletions
diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index fe756298..ca9a39de 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -744,7 +744,7 @@ impl<R: key::KeyRole> Key<key::SecretParts, R> { /// # Errors /// /// Fails if the secret key is missing, or encrypted. - pub fn into_keypair(mut self) -> Result<KeyPair<R>> { + pub fn into_keypair(mut self) -> Result<KeyPair> { use crate::packet::key::SecretKeyMaterial; let secret = match self.set_secret(None) { Some(SecretKeyMaterial::Unencrypted(secret)) => secret, @@ -756,7 +756,7 @@ impl<R: key::KeyRole> Key<key::SecretParts, R> { "no secret key".into()).into()), }; - KeyPair::new(self.into(), secret) + KeyPair::new(self.mark_role_unspecified().into(), secret) } } @@ -767,7 +767,7 @@ impl<R: key::KeyRole> key::Key4<key::SecretParts, R> { /// # Errors /// /// Fails if the secret key is missing, or encrypted. - pub fn into_keypair(mut self) -> Result<KeyPair<R>> { + pub fn into_keypair(mut self) -> Result<KeyPair> { use crate::packet::key::SecretKeyMaterial; let secret = match self.set_secret(None) { Some(SecretKeyMaterial::Unencrypted(secret)) => secret, @@ -779,7 +779,8 @@ impl<R: key::KeyRole> key::Key4<key::SecretParts, R> { "no secret key".into()).into()), }; - KeyPair::new(self.mark_parts_public().into(), secret) + KeyPair::new(self.mark_role_unspecified().mark_parts_public().into(), + secret) } } diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index f307dd9c..db88c215 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -149,9 +149,8 @@ impl PKESK3 { /// Decrypts the ESK and returns the session key and symmetric algorithm /// used to encrypt the following payload. - pub fn decrypt<R>(&self, decryptor: &mut dyn Decryptor<R>) + pub fn decrypt(&self, decryptor: &mut dyn Decryptor) -> Result<(SymmetricAlgorithm, SessionKey)> - where R: key::KeyRole { let plain = decryptor.decrypt(&self.esk)?; let key_rgn = 1..(plain.len() - 2); diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index 199f7a88..1740e727 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -138,9 +138,8 @@ impl Builder { /// /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`. - pub fn sign_standalone<R>(mut self, signer: &mut dyn Signer<R>) - -> Result<Signature> - where R: key::KeyRole + pub fn sign_standalone(mut self, signer: &mut dyn Signer) + -> Result<Signature> { self.pk_algo = signer.public().pk_algo(); let digest = Signature::standalone_hash(&self)?; @@ -151,9 +150,8 @@ impl Builder { /// /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`. - pub fn sign_timestamp<R>(mut self, signer: &mut dyn Signer<R>) - -> Result<Signature> - where R: key::KeyRole + pub fn sign_timestamp(mut self, signer: &mut dyn Signer) + -> Result<Signature> { self.pk_algo = signer.public().pk_algo(); let digest = Signature::timestamp_hash(&self)?; @@ -164,9 +162,8 @@ impl Builder { /// /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`. - pub fn sign_primary_key_binding<R>(mut self, signer: &mut dyn Signer<R>) + pub fn sign_primary_key_binding(mut self, signer: &mut dyn Signer) -> Result<Signature> - where R: key::KeyRole { self.pk_algo = signer.public().pk_algo(); let digest = @@ -181,11 +178,10 @@ impl Builder { /// /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`. - pub fn sign_userid_binding<R>(mut self, signer: &mut dyn Signer<R>, - key: &key::PublicKey, - userid: &UserID) + pub fn sign_userid_binding(mut self, signer: &mut dyn Signer, + key: &key::PublicKey, + userid: &UserID) -> Result<Signature> - where R: key::KeyRole { self.pk_algo = signer.public().pk_algo(); let digest = Signature::userid_binding_hash(&self, key, userid)?; @@ -197,12 +193,11 @@ impl Builder { /// /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`. - pub fn sign_subkey_binding<P, R>(mut self, signer: &mut dyn Signer<R>, - primary: &key::PublicKey, - subkey: &Key<P, key::SubordinateRole>) + pub fn sign_subkey_binding<P>(mut self, signer: &mut dyn Signer, + primary: &key::PublicKey, + subkey: &Key<P, key::SubordinateRole>) -> Result<Signature> - where P: key:: KeyParts, - R: key::KeyRole + where P: key:: KeyParts { self.pk_algo = signer.public().pk_algo(); let digest = Signature::subkey_binding_hash(&self, primary, subkey)?; @@ -214,11 +209,10 @@ impl Builder { /// /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`. - pub fn sign_user_attribute_binding<R>(mut self, signer: &mut dyn Signer<R>, - key: &key::PublicKey, - ua: &UserAttribute) + pub fn sign_user_attribute_binding(mut self, signer: &mut dyn Signer, + key: &key::PublicKey, + ua: &UserAttribute) -> Result<Signature> - where R: key::KeyRole { self.pk_algo = signer.public().pk_algo(); let digest = @@ -231,10 +225,9 @@ impl Builder { /// /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`. - pub fn sign_hash<R>(mut self, signer: &mut dyn Signer<R>, - mut hash: hash::Context) + pub fn sign_hash(mut self, signer: &mut dyn Signer, + mut hash: hash::Context) -> Result<Signature> - where R: key::KeyRole { // Fill out some fields, then hash the packet. self.pk_algo = signer.public().pk_algo(); @@ -252,9 +245,8 @@ impl Builder { /// /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`. - pub fn sign_message<R>(mut self, signer: &mut dyn Signer<R>, msg: &[u8]) + pub fn sign_message(mut self, signer: &mut dyn Signer, msg: &[u8]) -> Result<Signature> - where R: key::KeyRole { // Hash the message let mut hash = self.hash_algo.context()?; @@ -271,9 +263,8 @@ impl Builder { self.sign(signer, digest) } - fn sign<R>(self, signer: &mut dyn Signer<R>, digest: Vec<u8>) + fn sign(self, signer: &mut dyn Signer, digest: Vec<u8>) -> Result<Signature> - where R: key::KeyRole { let algo = self.hash_algo; let mpis = signer.sign(algo, &digest)?; |