From d7e5aa101dee8af3bade7b96b1bb8a51b9f2463e Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 10 Apr 2020 03:04:28 +0200 Subject: openpgp: Silence redundant imports for newer Rust toolchains --- openpgp/src/crypto/backend/nettle/asymmetric.rs | 33 ++++++------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'openpgp') diff --git a/openpgp/src/crypto/backend/nettle/asymmetric.rs b/openpgp/src/crypto/backend/nettle/asymmetric.rs index 18bb3f02..e6f6eb72 100644 --- a/openpgp/src/crypto/backend/nettle/asymmetric.rs +++ b/openpgp/src/crypto/backend/nettle/asymmetric.rs @@ -4,13 +4,13 @@ //! [`Decryptor`]: ../../asymmetric/trait.Decryptor.html //! [`KeyPair`]: ../../asymmetric/struct.KeyPair.html -use nettle::{ecc, ecdsa, ed25519, dsa, rsa, random::Yarrow}; +use nettle::{curve25519, ecc, ecdh, ecdsa, ed25519, dsa, rsa, random::Yarrow}; use crate::{Error, Result}; use crate::packet::{self, key, Key}; use crate::crypto::asymmetric::{KeyPair, Decryptor, Signer}; -use crate::crypto::mpi::{self, MPI}; +use crate::crypto::mpi::{self, MPI, PublicKey}; use crate::crypto::SessionKey; use crate::types::{Curve, HashAlgorithm}; @@ -23,7 +23,6 @@ impl Signer for KeyPair { -> Result { use crate::PublicKeyAlgorithm::*; - use crate::crypto::mpi::PublicKey; let mut rng = Yarrow::default(); @@ -153,7 +152,6 @@ impl Decryptor for KeyPair { -> Result { use crate::PublicKeyAlgorithm::*; - use crate::crypto::mpi::PublicKey; self.secret().map( |secret| Ok(match (self.public().mpis(), secret, ciphertext) @@ -256,7 +254,7 @@ impl Key { pub fn verify(&self, sig: &packet::Signature, digest: &[u8]) -> Result<()> { use crate::PublicKeyAlgorithm::*; - use crate::crypto::mpi::{PublicKey, Signature}; + use crate::crypto::mpi::Signature; #[allow(deprecated)] let ok = match (sig.pk_algo(), self.mpis(), sig.mpis()) { @@ -372,9 +370,7 @@ impl Key4 S: Into>, T: Into> { - use nettle::curve25519::{self, CURVE25519_SIZE}; - - let mut public_key = [0x40u8; CURVE25519_SIZE + 1]; + let mut public_key = [0x40u8; curve25519::CURVE25519_SIZE + 1]; curve25519::mul_g(&mut public_key[1..], private_key).unwrap(); let mut private_key = Vec::from(private_key); @@ -403,9 +399,7 @@ impl Key4 pub fn import_secret_ed25519(private_key: &[u8], ctime: T) -> Result where T: Into> { - use nettle::ed25519::{self, ED25519_KEY_SIZE}; - - let mut public_key = [0x40u8; ED25519_KEY_SIZE + 1]; + let mut public_key = [0x40u8; ed25519::ED25519_KEY_SIZE + 1]; ed25519::public_key(&mut public_key[1..], private_key).unwrap(); Self::with_secret( @@ -428,8 +422,6 @@ impl Key4 pub fn import_secret_rsa(d: &[u8], p: &[u8], q: &[u8], ctime: T) -> Result where T: Into> { - use nettle::rsa; - let sec = rsa::PrivateKey::new(d, p, q, None)?; let key = sec.public_key()?; let (a, b, c) = sec.as_rfc4880(); @@ -451,10 +443,8 @@ impl Key4 /// Generates a new RSA key with a public modulos of size `bits`. pub fn generate_rsa(bits: usize) -> Result { - use nettle::{rsa, random::Yarrow}; - use crate::crypto::mpi::{MPI, PublicKey}; - let mut rng = Yarrow::default(); + let (public, private) = rsa::generate_keypair(&mut rng, bits as u32)?; let (p, q, u) = private.as_rfc4880(); let public_mpis = PublicKey::RSA { @@ -482,20 +472,13 @@ impl Key4 /// `curve == Cv25519` will produce an error. Likewise /// `for_signing == false` and `curve == Ed25519` will produce an error. pub fn generate_ecc(for_signing: bool, curve: Curve) -> Result { - use nettle::{ - random::Yarrow, - ed25519, ed25519::ED25519_KEY_SIZE, - curve25519, curve25519::CURVE25519_SIZE, - ecc, ecdh, ecdsa, - }; - use crate::crypto::mpi::{MPI, PublicKey}; use crate::PublicKeyAlgorithm::*; let mut rng = Yarrow::default(); let (mpis, secret, pk_algo) = match (curve.clone(), for_signing) { (Curve::Ed25519, true) => { - let mut public = [0u8; ED25519_KEY_SIZE + 1]; + let mut public = [0u8; ed25519::ED25519_KEY_SIZE + 1]; let private: Protected = ed25519::private_key(&mut rng).into(); @@ -515,7 +498,7 @@ impl Key4 } (Curve::Cv25519, false) => { - let mut public = [0u8; CURVE25519_SIZE + 1]; + let mut public = [0u8; curve25519::CURVE25519_SIZE + 1]; let mut private: Protected = curve25519::private_key(&mut rng).into(); -- cgit v1.2.3