From fdc558da0f109f8a9b51664e19c1e26a691a7ea8 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Thu, 13 Jun 2019 08:40:58 -1000 Subject: [PATCH] `cargo +nightly fix && cargo fmt`. --- src/agreement.rs | 2 +- src/debug.rs | 2 +- src/ec.rs | 3 ++- src/ec/curve25519/ed25519/signing.rs | 4 +++- src/ec/curve25519/x25519.rs | 2 +- src/ec/keys.rs | 2 +- src/ec/suite_b/curve.rs | 2 +- src/ec/suite_b/ecdsa/signing.rs | 6 +++--- src/ec/suite_b/private_key.rs | 4 ++-- src/error.rs | 4 ++-- src/hmac.rs | 2 +- src/io/der_writer.rs | 8 ++++---- src/io/writer.rs | 2 +- src/rsa.rs | 2 +- src/rsa/padding.rs | 6 +++--- src/rsa/signing.rs | 4 ++-- src/signature.rs | 6 +++--- src/test.rs | 2 +- 18 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/agreement.rs b/src/agreement.rs index 7a7d1f07e..ee3f81bef 100644 --- a/src/agreement.rs +++ b/src/agreement.rs @@ -101,7 +101,7 @@ impl EphemeralPrivateKey { /// Generate a new ephemeral private key for the given algorithm. pub fn generate( alg: &'static Algorithm, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, ) -> Result { let cpu_features = cpu::features(); diff --git a/src/debug.rs b/src/debug.rs index bcc82f057..e6e7f29c0 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -55,7 +55,7 @@ macro_rules! derive_debug_self_as_ref_hex_bytes { pub(crate) fn write_hex_tuple( fmt: &mut core::fmt::Formatter, type_name: &str, - value: &AsRef<[u8]>, + value: &dyn AsRef<[u8]>, ) -> Result<(), ::core::fmt::Error> { fmt.debug_tuple(type_name) .field(&HexStr(value.as_ref())) diff --git a/src/ec.rs b/src/ec.rs index 15a749f4d..576d4911a 100644 --- a/src/ec.rs +++ b/src/ec.rs @@ -25,7 +25,8 @@ pub struct Curve { // Precondition: `bytes` is the correct length. check_private_key_bytes: fn(bytes: &[u8]) -> Result<(), error::Unspecified>, - generate_private_key: fn(rng: &rand::SecureRandom, &mut [u8]) -> Result<(), error::Unspecified>, + generate_private_key: + fn(rng: &dyn rand::SecureRandom, &mut [u8]) -> Result<(), error::Unspecified>, public_from_private: fn(public_out: &mut [u8], private_key: &Seed) -> Result<(), error::Unspecified>, diff --git a/src/ec/curve25519/ed25519/signing.rs b/src/ec/curve25519/ed25519/signing.rs index 0889c2364..d47284ce5 100644 --- a/src/ec/curve25519/ed25519/signing.rs +++ b/src/ec/curve25519/ed25519/signing.rs @@ -51,7 +51,9 @@ impl Ed25519KeyPair { /// https://tools.ietf.org/html/draft-ietf-curdle-pkix-04. /// /// [RFC 5958 Section 2]: https://tools.ietf.org/html/rfc5958#section-2 - pub fn generate_pkcs8(rng: &rand::SecureRandom) -> Result { + pub fn generate_pkcs8( + rng: &dyn rand::SecureRandom, + ) -> Result { let mut seed = [0u8; SEED_LEN]; rng.fill(&mut seed)?; let key_pair = Self::from_seed_(&seed); diff --git a/src/ec/curve25519/x25519.rs b/src/ec/curve25519/x25519.rs index faff582a4..14c99f65b 100644 --- a/src/ec/curve25519/x25519.rs +++ b/src/ec/curve25519/x25519.rs @@ -46,7 +46,7 @@ fn x25519_check_private_key_bytes(bytes: &[u8]) -> Result<(), error::Unspecified } fn x25519_generate_private_key( - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, out: &mut [u8], ) -> Result<(), error::Unspecified> { rng.fill(out) diff --git a/src/ec/keys.rs b/src/ec/keys.rs index ce3385491..abf33882a 100644 --- a/src/ec/keys.rs +++ b/src/ec/keys.rs @@ -29,7 +29,7 @@ pub struct Seed { impl Seed { pub(crate) fn generate( curve: &'static Curve, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, cpu_features: cpu::Features, ) -> Result { let mut r = Self { diff --git a/src/ec/suite_b/curve.rs b/src/ec/suite_b/curve.rs index 05794dddd..0788e1071 100644 --- a/src/ec/suite_b/curve.rs +++ b/src/ec/suite_b/curve.rs @@ -47,7 +47,7 @@ macro_rules! suite_b_curve { } fn $generate_private_key( - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, out: &mut [u8], ) -> Result<(), error::Unspecified> { ec::suite_b::private_key::generate_private_scalar_bytes($private_key_ops, rng, out) diff --git a/src/ec/suite_b/ecdsa/signing.rs b/src/ec/suite_b/ecdsa/signing.rs index b1c536037..2f92bb332 100644 --- a/src/ec/suite_b/ecdsa/signing.rs +++ b/src/ec/suite_b/ecdsa/signing.rs @@ -83,7 +83,7 @@ impl EcdsaKeyPair { /// [RFC 5958 Section 2]: https://tools.ietf.org/html/rfc5958#section-2 pub fn generate_pkcs8( alg: &'static EcdsaSigningAlgorithm, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, ) -> Result { let private_key = ec::Seed::generate(alg.curve, rng, cpu::features())?; let public_key = private_key.compute_public_key()?; @@ -156,7 +156,7 @@ impl EcdsaKeyPair { /// generated by `rng`. pub fn sign( &self, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, message: &[u8], ) -> Result { // Step 4 (out of order). @@ -168,7 +168,7 @@ impl EcdsaKeyPair { /// generated by `rng`. fn sign_( &self, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, h: digest::Digest, ) -> Result { // NSA Suite B Implementer's Guide to ECDSA Section 3.4.1: ECDSA diff --git a/src/ec/suite_b/private_key.rs b/src/ec/suite_b/private_key.rs index 5c0f9a86e..fb16b245e 100644 --- a/src/ec/suite_b/private_key.rs +++ b/src/ec/suite_b/private_key.rs @@ -27,7 +27,7 @@ use untrusted; /// Generates a random scalar in the range [1, n). pub fn random_scalar( ops: &PrivateKeyOps, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, ) -> Result { let num_limbs = ops.common.num_limbs; let mut bytes = [0; ec::SCALAR_MAX_BYTES]; @@ -38,7 +38,7 @@ pub fn random_scalar( pub fn generate_private_scalar_bytes( ops: &PrivateKeyOps, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, out: &mut [u8], ) -> Result<(), error::Unspecified> { // [NSA Suite B Implementer's Guide to ECDSA] Appendix A.1.2, and diff --git a/src/error.rs b/src/error.rs index 35cdee450..2f4bb04de 100644 --- a/src/error.rs +++ b/src/error.rs @@ -96,7 +96,7 @@ impl core::fmt::Display for Unspecified { #[cfg(feature = "use_heap")] impl std::error::Error for Unspecified { #[inline] - fn cause(&self) -> Option<&std::error::Error> { + fn cause(&self) -> Option<&dyn std::error::Error> { None } @@ -203,7 +203,7 @@ impl KeyRejected { #[cfg(feature = "use_heap")] impl std::error::Error for KeyRejected { - fn cause(&self) -> Option<&std::error::Error> { + fn cause(&self) -> Option<&dyn std::error::Error> { None } diff --git a/src/hmac.rs b/src/hmac.rs index c4ad0c795..c3b8d038d 100644 --- a/src/hmac.rs +++ b/src/hmac.rs @@ -173,7 +173,7 @@ impl Key { /// recommendation in https://tools.ietf.org/html/rfc2104#section-3. pub fn generate( digest_alg: &'static digest::Algorithm, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, ) -> Result { let mut key_bytes = [0; digest::MAX_OUTPUT_LEN]; let key_bytes = &mut key_bytes[..digest_alg.output_len]; diff --git a/src/io/der_writer.rs b/src/io/der_writer.rs index 10e817a88..18c778dab 100644 --- a/src/io/der_writer.rs +++ b/src/io/der_writer.rs @@ -14,7 +14,7 @@ use super::{der::*, writer::*, *}; -pub(crate) fn write_positive_integer(output: &mut Accumulator, value: &Positive) { +pub(crate) fn write_positive_integer(output: &mut dyn Accumulator, value: &Positive) { let first_byte = value.first_byte(); let value = value.big_endian_without_leading_zero_as_input(); write_tlv(output, Tag::Integer, |output| { @@ -25,7 +25,7 @@ pub(crate) fn write_positive_integer(output: &mut Accumulator, value: &Positive) }) } -pub(crate) fn write_all(tag: Tag, write_value: &Fn(&mut Accumulator)) -> Box<[u8]> { +pub(crate) fn write_all(tag: Tag, write_value: &dyn Fn(&mut dyn Accumulator)) -> Box<[u8]> { let length = { let mut length = LengthMeasurement::zero(); write_tlv(&mut length, tag, write_value); @@ -38,9 +38,9 @@ pub(crate) fn write_all(tag: Tag, write_value: &Fn(&mut Accumulator)) -> Box<[u8 output.into() } -fn write_tlv(output: &mut Accumulator, tag: Tag, write_value: F) +fn write_tlv(output: &mut dyn Accumulator, tag: Tag, write_value: F) where - F: Fn(&mut Accumulator), + F: Fn(&mut dyn Accumulator), { let length: usize = { let mut length = LengthMeasurement::zero(); diff --git a/src/io/writer.rs b/src/io/writer.rs index e8f9bcb78..69fdb08c0 100644 --- a/src/io/writer.rs +++ b/src/io/writer.rs @@ -72,6 +72,6 @@ impl Accumulator for Writer { } } -pub fn write_copy(accumulator: &mut Accumulator, to_copy: untrusted::Input) { +pub fn write_copy(accumulator: &mut dyn Accumulator, to_copy: untrusted::Input) { accumulator.write_bytes(to_copy.as_slice_less_safe()) } diff --git a/src/rsa.rs b/src/rsa.rs index fa2c6eb59..18f4618a9 100644 --- a/src/rsa.rs +++ b/src/rsa.rs @@ -42,7 +42,7 @@ const PRIVATE_KEY_PUBLIC_MODULUS_MAX_BITS: bits::BitLength = bits::BitLength::fr /// Parameters for RSA verification. #[derive(Debug)] pub struct RsaParameters { - padding_alg: &'static padding::Verification, + padding_alg: &'static dyn padding::Verification, min_bits: bits::BitLength, } diff --git a/src/rsa/padding.rs b/src/rsa/padding.rs index f733cbbd8..2725d0221 100644 --- a/src/rsa/padding.rs +++ b/src/rsa/padding.rs @@ -37,7 +37,7 @@ pub trait RsaEncoding: Padding { m_hash: &digest::Digest, m_out: &mut [u8], mod_bits: bits::BitLength, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, ) -> Result<(), error::Unspecified>; } @@ -81,7 +81,7 @@ impl RsaEncoding for PKCS1 { m_hash: &digest::Digest, m_out: &mut [u8], _mod_bits: bits::BitLength, - _rng: &rand::SecureRandom, + _rng: &dyn rand::SecureRandom, ) -> Result<(), error::Unspecified> { pkcs1_encode(&self, m_hash, m_out); Ok(()) @@ -240,7 +240,7 @@ impl RsaEncoding for PSS { m_hash: &digest::Digest, m_out: &mut [u8], mod_bits: bits::BitLength, - rng: &rand::SecureRandom, + rng: &dyn rand::SecureRandom, ) -> Result<(), error::Unspecified> { let metrics = PSSMetrics::new(self.digest_alg, mod_bits)?; diff --git a/src/rsa/signing.rs b/src/rsa/signing.rs index c7fdc3005..d8a09ee8f 100644 --- a/src/rsa/signing.rs +++ b/src/rsa/signing.rs @@ -533,8 +533,8 @@ impl RsaKeyPair { /// platforms, it is done less perfectly. pub fn sign( &self, - padding_alg: &'static RsaEncoding, - rng: &rand::SecureRandom, + padding_alg: &'static dyn RsaEncoding, + rng: &dyn rand::SecureRandom, msg: &[u8], signature: &mut [u8], ) -> Result<(), error::Unspecified> { diff --git a/src/signature.rs b/src/signature.rs index 358ac8c36..2fbbd34e3 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -365,7 +365,7 @@ pub trait VerificationAlgorithm: core::fmt::Debug + Sync + sealed::Sealed { /// An unparsed, possibly malformed, public key for signature verification. pub struct UnparsedPublicKey> { - algorithm: &'static VerificationAlgorithm, + algorithm: &'static dyn VerificationAlgorithm, bytes: B, } @@ -388,7 +388,7 @@ impl> UnparsedPublicKey { /// /// No validation of `bytes` is done until `verify()` is called. #[inline] - pub fn new(algorithm: &'static VerificationAlgorithm, bytes: B) -> Self { + pub fn new(algorithm: &'static dyn VerificationAlgorithm, bytes: B) -> Self { Self { algorithm, bytes } } @@ -411,7 +411,7 @@ impl> UnparsedPublicKey { /// [UnparsedPublicKey::verify()]: UnparsedPublicKey::verify #[deprecated(note = "Use UnparsedPublicKey::verify")] pub fn verify( - algorithm: &'static VerificationAlgorithm, + algorithm: &'static dyn VerificationAlgorithm, public_key: untrusted::Input, msg: untrusted::Input, signature: untrusted::Input, diff --git a/src/test.rs b/src/test.rs index 24e4675b6..780b0956e 100644 --- a/src/test.rs +++ b/src/test.rs @@ -378,7 +378,7 @@ fn from_hex_digit(d: u8) -> Result { fn parse_test_case( current_section: &mut String, - lines: &mut Iterator, + lines: &mut dyn Iterator, ) -> Option { let mut attributes = Vec::new();