diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-09-26 11:53:32 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2019-09-27 22:12:11 +0200 |
commit | 424ce126a56660168f8284fa34ae80cb93d74289 (patch) | |
tree | 2c0440c1f3b0d557def5e1a496ee4ede22045a9b /openpgp | |
parent | a69ec9f9c5097bb8acd1a4fe2144328c9dc4ade7 (diff) |
linting: Clear up bare trait object warnings
Newer Rust compilers requre `dyn` marking trait objects.
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'openpgp')
30 files changed, 140 insertions, 140 deletions
diff --git a/openpgp/examples/generate-encrypt-decrypt.rs b/openpgp/examples/generate-encrypt-decrypt.rs index 90640ba3..f24eba1f 100644 --- a/openpgp/examples/generate-encrypt-decrypt.rs +++ b/openpgp/examples/generate-encrypt-decrypt.rs @@ -38,7 +38,7 @@ fn generate() -> openpgp::Result<openpgp::TPK> { } /// Encrypts the given message. -fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK) +fn encrypt(sink: &mut dyn Write, plaintext: &str, recipient: &openpgp::TPK) -> openpgp::Result<()> { // Build a vector of recipients to hand to Encryptor. let recipients = @@ -72,7 +72,7 @@ fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK) } /// Decrypts the given message. -fn decrypt(sink: &mut Write, ciphertext: &[u8], recipient: &openpgp::TPK) +fn decrypt(sink: &mut dyn Write, ciphertext: &[u8], recipient: &openpgp::TPK) -> openpgp::Result<()> { // Make a helper that that feeds the recipient's secret key to the // decryptor. diff --git a/openpgp/examples/generate-sign-verify.rs b/openpgp/examples/generate-sign-verify.rs index 8625e4ea..8dae191c 100644 --- a/openpgp/examples/generate-sign-verify.rs +++ b/openpgp/examples/generate-sign-verify.rs @@ -37,7 +37,7 @@ fn generate() -> openpgp::Result<openpgp::TPK> { } /// Signs the given message. -fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::TPK) +fn sign(sink: &mut dyn Write, plaintext: &str, tsk: &openpgp::TPK) -> openpgp::Result<()> { // Get the keypair to do the signing from the TPK. let mut keypair = tsk.keys_valid().signing_capable().nth(0).unwrap().2 @@ -63,7 +63,7 @@ fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::TPK) } /// Verifies the given message. -fn verify(sink: &mut Write, signed_message: &[u8], sender: &openpgp::TPK) +fn verify(sink: &mut dyn Write, signed_message: &[u8], sender: &openpgp::TPK) -> openpgp::Result<()> { // Make a helper that that feeds the sender's public key to the // verifier. diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index 68d53176..dce28091 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -386,7 +386,7 @@ pub enum ReaderMode { /// A filter that strips ASCII Armor from a stream of data. pub struct Reader<'a> { - source: Box<'a + BufferedReader<()>>, + source: Box<dyn BufferedReader<()> + 'a>, kind: Option<Kind>, mode: ReaderMode, buffer: Vec<u8>, @@ -513,7 +513,7 @@ impl<'a> Reader<'a> { } pub(crate) fn from_buffered_reader<C: 'a, M>( - inner: Box<'a + BufferedReader<C>>, mode: M) -> Self + inner: Box<dyn BufferedReader<C> + 'a>, mode: M) -> Self where M: Into<Option<ReaderMode>> { let mode = mode.into().unwrap_or(Default::default()); diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs index 4bda0e41..5be5ebd0 100644 --- a/openpgp/src/crypto/aead.rs +++ b/openpgp/src/crypto/aead.rs @@ -41,7 +41,7 @@ impl AEADAlgorithm { /// Creates a nettle context. pub fn context(&self, sym_algo: SymmetricAlgorithm, key: &[u8], nonce: &[u8]) - -> Result<Box<aead::Aead>> { + -> Result<Box<dyn aead::Aead>> { match self { AEADAlgorithm::EAX => match sym_algo { SymmetricAlgorithm::AES128 => @@ -125,7 +125,7 @@ impl<R: io::Read> Decryptor<R> { }) } - fn hash_associated_data(&mut self, aead: &mut Box<aead::Aead>, + fn hash_associated_data(&mut self, aead: &mut Box<dyn aead::Aead>, final_digest: bool) { // Prepare the associated data. write_be_u64(&mut self.ad[AD_PREFIX_LEN..AD_PREFIX_LEN + 8], @@ -140,7 +140,7 @@ impl<R: io::Read> Decryptor<R> { } } - fn make_aead(&mut self) -> Result<Box<aead::Aead>> { + fn make_aead(&mut self) -> Result<Box<dyn aead::Aead>> { // The chunk index is XORed into the IV. let mut chunk_index_be64 = vec![0u8; 8]; write_be_u64(&mut chunk_index_be64, self.chunk_index); @@ -479,16 +479,16 @@ impl<R: BufferedReader<C>, C> BufferedReader<C> return self.reader.steal_eof(); } - fn get_mut(&mut self) -> Option<&mut BufferedReader<C>> { + fn get_mut(&mut self) -> Option<&mut dyn BufferedReader<C>> { Some(&mut self.reader.reader.source) } - fn get_ref(&self) -> Option<&BufferedReader<C>> { + fn get_ref(&self) -> Option<&dyn BufferedReader<C>> { Some(&self.reader.reader.source) } fn into_inner<'b>(self: Box<Self>) - -> Option<Box<BufferedReader<C> + 'b>> where Self: 'b { + -> Option<Box<dyn BufferedReader<C> + 'b>> where Self: 'b { Some(Box::new(self.reader.reader.source)) } @@ -558,7 +558,7 @@ impl<W: io::Write> Encryptor<W> { }) } - fn hash_associated_data(&mut self, aead: &mut Box<aead::Aead>, + fn hash_associated_data(&mut self, aead: &mut Box<dyn aead::Aead>, final_digest: bool) { // Prepare the associated data. write_be_u64(&mut self.ad[AD_PREFIX_LEN..AD_PREFIX_LEN + 8], @@ -573,7 +573,7 @@ impl<W: io::Write> Encryptor<W> { } } - fn make_aead(&mut self) -> Result<Box<aead::Aead>> { + fn make_aead(&mut self) -> Result<Box<dyn aead::Aead>> { // The chunk index is XORed into the IV. let mut chunk_index_be64 = vec![0u8; 8]; write_be_u64(&mut chunk_index_be64, self.chunk_index); diff --git a/openpgp/src/crypto/ecdh.rs b/openpgp/src/crypto/ecdh.rs index 9b8ad9e0..d16de842 100644 --- a/openpgp/src/crypto/ecdh.rs +++ b/openpgp/src/crypto/ecdh.rs @@ -458,7 +458,7 @@ pub fn aes_key_wrap(algo: SymmetricAlgorithm, key: &Protected, // nettle::Mode:ECB, and we need nettle::Mode for polymorphism (we // cannot have Box<nettle::Cipher>). To work around this, we use // CBC, and always use an all-zero IV. - let mut cipher: Box<Mode> = match algo { + let mut cipher: Box<dyn Mode> = match algo { AES128 => Box::new( mode::Cbc::<cipher::Aes128>::with_encrypt_key(key)?), AES192 => Box::new( @@ -544,7 +544,7 @@ pub fn aes_key_unwrap(algo: SymmetricAlgorithm, key: &Protected, // nettle::Mode:ECB, and we need nettle::Mode for polymorphism (we // cannot have Box<nettle::Cipher>). To work around this, we use // CBC, and always use an all-zero IV. - let mut cipher: Box<Mode> = match algo { + let mut cipher: Box<dyn Mode> = match algo { AES128 => Box::new( mode::Cbc::<cipher::Aes128>::with_decrypt_key(key)?), AES192 => Box::new( diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs index ba2e0545..cc5ea49d 100644 --- a/openpgp/src/crypto/hash.rs +++ b/openpgp/src/crypto/hash.rs @@ -25,7 +25,7 @@ const DUMP_HASHED_VALUES: Option<&str> = None; #[derive(Clone)] pub struct Context { algo: HashAlgorithm, - ctx: Box<nettle::Hash>, + ctx: Box<dyn nettle::Hash>, } impl Context { @@ -96,7 +96,7 @@ impl HashAlgorithm { use nettle::hash::*; use nettle::hash::insecure_do_not_use::Sha1; - let c: Result<Box<nettle::Hash>> = match self { + let c: Result<Box<dyn nettle::Hash>> = match self { HashAlgorithm::SHA1 => Ok(Box::new(Sha1::default())), HashAlgorithm::SHA224 => Ok(Box::new(Sha224::default())), HashAlgorithm::SHA256 => Ok(Box::new(Sha256::default())), @@ -109,7 +109,7 @@ impl HashAlgorithm { }; if let Some(prefix) = DUMP_HASHED_VALUES { - c.map(|c: Box<nettle::Hash>| { + c.map(|c: Box<dyn nettle::Hash>| { Context { algo: self, ctx: Box::new(HashDumper::new(c, prefix)), @@ -139,14 +139,14 @@ impl HashAlgorithm { } struct HashDumper { - h: Box<nettle::Hash>, + h: Box<dyn nettle::Hash>, sink: File, filename: String, written: usize, } impl HashDumper { - fn new(h: Box<nettle::Hash>, prefix: &str) -> Self { + fn new(h: Box<dyn nettle::Hash>, prefix: &str) -> Self { let mut n = 0; let mut filename; let sink = loop { @@ -187,7 +187,7 @@ impl nettle::Hash for HashDumper { fn digest(&mut self, digest: &mut [u8]) { self.h.digest(digest); } - fn box_clone(&self) -> Box<nettle::Hash> { + fn box_clone(&self) -> Box<dyn nettle::Hash> { Box::new(Self::new(self.h.box_clone(), &DUMP_HASHED_VALUES.unwrap())) } } diff --git a/openpgp/src/crypto/symmetric.rs b/openpgp/src/crypto/symmetric.rs index 4c352ad6..61c7dcd0 100644 --- a/openpgp/src/crypto/symmetric.rs +++ b/openpgp/src/crypto/symmetric.rs @@ -53,7 +53,7 @@ impl SymmetricAlgorithm { } /// Creates a Nettle context for encrypting in CFB mode. - pub fn make_encrypt_cfb(self, key: &[u8]) -> Result<Box<Mode>> { + pub fn make_encrypt_cfb(self, key: &[u8]) -> Result<Box<dyn Mode>> { use nettle::{mode, cipher}; match self { SymmetricAlgorithm::TripleDES => @@ -91,7 +91,7 @@ impl SymmetricAlgorithm { } /// Creates a Nettle context for decrypting in CFB mode. - pub fn make_decrypt_cfb(self, key: &[u8]) -> Result<Box<Mode>> { + pub fn make_decrypt_cfb(self, key: &[u8]) -> Result<Box<dyn Mode>> { use nettle::{mode, cipher}; match self { SymmetricAlgorithm::TripleDES => @@ -134,7 +134,7 @@ pub struct Decryptor<R: io::Read> { // The encrypted data. source: R, - dec: Box<Mode>, + dec: Box<dyn Mode>, block_size: usize, iv: Vec<u8>, // Up to a block of unread data. @@ -368,16 +368,16 @@ impl<R: BufferedReader<C>, C> BufferedReader<C> return self.reader.steal_eof(); } - fn get_mut(&mut self) -> Option<&mut BufferedReader<C>> { + fn get_mut(&mut self) -> Option<&mut dyn BufferedReader<C>> { Some(&mut self.reader.reader.source) } - fn get_ref(&self) -> Option<&BufferedReader<C>> { + fn get_ref(&self) -> Option<&dyn BufferedReader<C>> { Some(&self.reader.reader.source) } fn into_inner<'b>(self: Box<Self>) - -> Option<Box<BufferedReader<C> + 'b>> where Self: 'b { + -> Option<Box<dyn BufferedReader<C> + 'b>> where Self: 'b { Some(Box::new(self.reader.reader.source)) } @@ -398,7 +398,7 @@ impl<R: BufferedReader<C>, C> BufferedReader<C> pub struct Encryptor<W: io::Write> { inner: Option<W>, - cipher: Box<Mode>, + cipher: Box<dyn Mode>, block_size: usize, iv: Vec<u8>, // Up to a block of unencrypted data. diff --git a/openpgp/src/message/lexer.rs b/openpgp/src/message/lexer.rs index fc561d62..44483ccc 100644 --- a/openpgp/src/message/lexer.rs +++ b/openpgp/src/message/lexer.rs @@ -57,7 +57,7 @@ impl fmt::Display for LexicalError { } pub(crate) struct Lexer<'input> { - iter: Box<Iterator<Item=(usize, &'input Token)> + 'input>, + iter: Box<dyn Iterator<Item=(usize, &'input Token)> + 'input>, } impl<'input> Iterator for Lexer<'input> { diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index 1777aed4..3b3897a0 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -149,7 +149,7 @@ 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 Decryptor<R>) + pub fn decrypt<R>(&self, decryptor: &mut dyn Decryptor<R>) -> Result<(SymmetricAlgorithm, SessionKey)> where R: key::KeyRole { diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index 910c234c..094e2d0f 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -107,7 +107,7 @@ impl Builder { } /// Creates a standalone signature. - pub fn sign_standalone<R>(mut self, signer: &mut Signer<R>, + pub fn sign_standalone<R>(mut self, signer: &mut dyn Signer<R>, algo: HashAlgorithm) -> Result<Signature> where R: key::KeyRole @@ -119,7 +119,7 @@ impl Builder { } /// Creates a timestamp signature. - pub fn sign_timestamp<R>(mut self, signer: &mut Signer<R>, + pub fn sign_timestamp<R>(mut self, signer: &mut dyn Signer<R>, algo: HashAlgorithm) -> Result<Signature> where R: key::KeyRole @@ -135,7 +135,7 @@ impl Builder { /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`, the hash-algorithm field is set to /// `hash_algo`. - pub fn sign_primary_key_binding<R>(mut self, signer: &mut Signer<R>, + pub fn sign_primary_key_binding<R>(mut self, signer: &mut dyn Signer<R>, algo: HashAlgorithm) -> Result<Signature> where R: key::KeyRole @@ -155,7 +155,7 @@ impl Builder { /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`, the hash-algorithm field is set to /// `hash_algo`. - pub fn sign_userid_binding<R>(mut self, signer: &mut Signer<R>, + pub fn sign_userid_binding<R>(mut self, signer: &mut dyn Signer<R>, key: &key::PublicKey, userid: &UserID, algo: HashAlgorithm) @@ -174,7 +174,7 @@ impl Builder { /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`, the hash-algorithm field is set to /// `hash_algo`. - pub fn sign_subkey_binding<R>(mut self, signer: &mut Signer<R>, + pub fn sign_subkey_binding<R>(mut self, signer: &mut dyn Signer<R>, primary: &key::PublicKey, subkey: &key::PublicSubkey, algo: HashAlgorithm) @@ -193,7 +193,7 @@ impl Builder { /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`, the hash-algorithm field is set to /// `hash_algo`. - pub fn sign_user_attribute_binding<R>(mut self, signer: &mut Signer<R>, + pub fn sign_user_attribute_binding<R>(mut self, signer: &mut dyn Signer<R>, key: &key::PublicKey, ua: &UserAttribute, algo: HashAlgorithm) @@ -213,7 +213,7 @@ impl Builder { /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`, the hash-algorithm field is set to /// `hash_algo`. - pub fn sign_hash<R>(mut self, signer: &mut Signer<R>, + pub fn sign_hash<R>(mut self, signer: &mut dyn Signer<R>, hash_algo: HashAlgorithm, mut hash: hash::Context) -> Result<Signature> where R: key::KeyRole @@ -235,7 +235,7 @@ impl Builder { /// The Signature's public-key algorithm field is set to the /// algorithm used by `signer`, the hash-algorithm field is set to /// `hash_algo`. - pub fn sign_message<R>(mut self, signer: &mut Signer<R>, + pub fn sign_message<R>(mut self, signer: &mut dyn Signer<R>, hash_algo: HashAlgorithm, msg: &[u8]) -> Result<Signature> where R: key::KeyRole @@ -256,7 +256,7 @@ impl Builder { self.sign(signer, digest) } - fn sign<R>(self, signer: &mut Signer<R>, digest: Vec<u8>) + fn sign<R>(self, signer: &mut dyn Signer<R>, digest: Vec<u8>) -> Result<Signature> where R: key::KeyRole { diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 2db68ef3..72374aa8 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -280,7 +280,7 @@ impl PacketPile { } - pub(crate) fn from_buffered_reader<'a>(bio: Box<'a + BufferedReader<Cookie>>) + pub(crate) fn from_buffered_reader<'a>(bio: Box<dyn BufferedReader<Cookie> + 'a>) -> Result<PacketPile> { PacketParserBuilder::from_buffered_reader(bio)? .buffer_unread_content() diff --git a/openpgp/src/parse/hashed_reader.rs b/openpgp/src/parse/hashed_reader.rs index cbfc0330..ff1f77da 100644 --- a/openpgp/src/parse/hashed_reader.rs +++ b/openpgp/src/parse/hashed_reader.rs @@ -194,16 +194,16 @@ impl<R: BufferedReader<Cookie>> result } - fn get_mut(&mut self) -> Option<&mut BufferedReader<Cookie>> { + fn get_mut(&mut self) -> Option<&mut dyn BufferedReader<Cookie>> { Some(&mut self.reader) } - fn get_ref(&self) -> Option<&BufferedReader<Cookie>> { + fn get_ref(&self) -> Option<&dyn BufferedReader<Cookie>> { Some(&self.reader) } fn into_inner<'b>(self: Box<Self>) - -> Option<Box<BufferedReader<Cookie> + 'b>> + -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where Self: 'b { Some(Box::new(self.reader)) } diff --git a/openpgp/src/parse/packet_parser_builder.rs b/openpgp/src/parse/packet_parser_builder.rs index 5719ddc4..b331801a 100644 --- a/openpgp/src/parse/packet_parser_builder.rs +++ b/openpgp/src/parse/packet_parser_builder.rs @@ -36,7 +36,7 @@ pub enum Dearmor { /// for instance, `PacketParser::from_file` or /// `PacketParser::from_reader` to start parsing an OpenPGP message. pub struct PacketParserBuilder<'a> { - bio: Box<'a + BufferedReader<Cookie>>, + bio: Box<dyn BufferedReader<Cookie> + 'a>, dearmor: Dearmor, settings: PacketParserSettings, } @@ -72,7 +72,7 @@ impl<'a> PacketParserBuilder<'a> { // // Note: this clears the `level` field of the // `Cookie` cookie. - pub(crate) fn from_buffered_reader(mut bio: Box<'a + BufferedReader<Cookie>>) + pub(crate) fn from_buffered_reader(mut bio: Box<dyn BufferedReader<Cookie> + 'a>) -> Result<Self> { bio.cookie_mut().level = None; Ok(PacketParserBuilder { diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 815636df..9eca1b84 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -129,7 +129,7 @@ impl<'a> PacketPileParser<'a> { /// Creates a `PacketPileParser` to parse the OpenPGP message stored /// in the `BufferedReader` object. - pub(crate) fn from_buffered_reader(bio: Box<BufferedReader<Cookie> + 'a>) + pub(crate) fn from_buffered_reader(bio: Box<dyn BufferedReader<Cookie> + 'a>) -> Result<PacketPileParser<'a>> { Self::from_packet_parser(PacketParser::from_buffered_reader(bio)?) } diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index ba00ce47..f79e2027 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -227,7 +227,7 @@ impl<'a&g |