cargo +nightly fix && cargo fmt.

This commit is contained in:
Brian Smith 2019-06-13 08:40:58 -10:00
parent 1097eb9c02
commit fdc558da0f
18 changed files with 33 additions and 30 deletions

View File

@ -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<Self, error::Unspecified> {
let cpu_features = cpu::features();

View File

@ -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()))

View File

@ -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>,

View File

@ -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<pkcs8::Document, error::Unspecified> {
pub fn generate_pkcs8(
rng: &dyn rand::SecureRandom,
) -> Result<pkcs8::Document, error::Unspecified> {
let mut seed = [0u8; SEED_LEN];
rng.fill(&mut seed)?;
let key_pair = Self::from_seed_(&seed);

View File

@ -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)

View File

@ -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<Self, error::Unspecified> {
let mut r = Self {

View File

@ -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)

View File

@ -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<pkcs8::Document, error::Unspecified> {
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<signature::Signature, error::Unspecified> {
// 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<signature::Signature, error::Unspecified> {
// NSA Suite B Implementer's Guide to ECDSA Section 3.4.1: ECDSA

View File

@ -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<Scalar, error::Unspecified> {
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

View File

@ -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
}

View File

@ -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<Self, error::Unspecified> {
let mut key_bytes = [0; digest::MAX_OUTPUT_LEN];
let key_bytes = &mut key_bytes[..digest_alg.output_len];

View File

@ -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<F>(output: &mut Accumulator, tag: Tag, write_value: F)
fn write_tlv<F>(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();

View File

@ -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())
}

View File

@ -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,
}

View File

@ -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)?;

View File

@ -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> {

View File

@ -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<B: AsRef<[u8]>> {
algorithm: &'static VerificationAlgorithm,
algorithm: &'static dyn VerificationAlgorithm,
bytes: B,
}
@ -388,7 +388,7 @@ impl<B: AsRef<[u8]>> UnparsedPublicKey<B> {
///
/// 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<B: AsRef<[u8]>> UnparsedPublicKey<B> {
/// [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,

View File

@ -378,7 +378,7 @@ fn from_hex_digit(d: u8) -> Result<u8, String> {
fn parse_test_case(
current_section: &mut String,
lines: &mut Iterator<Item = &str>,
lines: &mut dyn Iterator<Item = &str>,
) -> Option<TestCase> {
let mut attributes = Vec::new();