diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2021-04-06 21:24:59 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-04-09 13:13:58 +0200 |
commit | 5d029cbf42621452666bd084f7beecb7d3d885a4 (patch) | |
tree | 21219c5864beac97ff5c55c78b436918034adcd6 | |
parent | 9424cd350f32a97479a74d919c646f9e26c2ebce (diff) |
Lint: Remove unnecessary conversions.
- https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
29 files changed, 108 insertions, 105 deletions
diff --git a/autocrypt/src/lib.rs b/autocrypt/src/lib.rs index e460d41e..b6820289 100644 --- a/autocrypt/src/lib.rs +++ b/autocrypt/src/lib.rs @@ -619,8 +619,7 @@ impl AutocryptSetupMessage { Packet::SKESK(skesk) => skesk, p => return Err( Error::MalformedMessage( - format!("Expected a SKESK packet, found a {}", p.tag()) - .into()) + format!("Expected a SKESK packet, found a {}", p.tag())) .into()), }; @@ -636,8 +635,7 @@ impl AutocryptSetupMessage { ref p => return Err( Error::MalformedMessage( format!("Expected a SEIP packet, found a {}", - p.tag()) - .into()) + p.tag())) .into()), } @@ -733,7 +731,7 @@ impl<'a> AutocryptSetupMessageParser<'a> { p => return Err(Error::MalformedMessage( format!("SEIP container contains a {}, \ expected a Literal Data packet", - p.tag()).into()).into()), + p.tag())).into()), } // The inner message consists of an ASCII-armored encoded @@ -787,8 +785,7 @@ impl<'a> AutocryptSetupMessageParser<'a> { ref p => return Err(Error::MalformedMessage( format!("Expected an MDC packet, got a {}", - p.tag()) - .into()) + p.tag())) .into()), } @@ -802,8 +799,7 @@ impl<'a> AutocryptSetupMessageParser<'a> { // has the right sequence of packets, but we haven't // carefully checked the nesting. We do that now. if let Err(err) = pp.is_message() { - return Err(err.context( - "Invalid OpenPGP Message").into()); + return Err(err.context("Invalid OpenPGP Message")); } } PacketParserResult::Some(pp) => diff --git a/ffi-macros/src/lib.rs b/ffi-macros/src/lib.rs index 6eebc9a3..6f0ca859 100644 --- a/ffi-macros/src/lib.rs +++ b/ffi-macros/src/lib.rs @@ -428,7 +428,7 @@ fn derive_conversion_functions(mut st: syn::ItemStruct, return syn::Error::new(argument_span, "expected a single field") - .to_compile_error().into(); + .to_compile_error(); } fields.unnamed.pop(); fields.unnamed.push( @@ -463,7 +463,7 @@ fn derive_conversion_functions(mut st: syn::ItemStruct, syn::Error::new(argument_span, format!("expected tuple struct, try: {}(...)", wrapper)) - .to_compile_error().into(), + .to_compile_error(), }; quote! { diff --git a/ipc/src/assuan/mod.rs b/ipc/src/assuan/mod.rs index 55be0d66..0e503308 100644 --- a/ipc/src/assuan/mod.rs +++ b/ipc/src/assuan/mod.rs @@ -409,7 +409,7 @@ impl Response { } } Err(anyhow::anyhow!( - String::from_utf8_lossy(&msg).to_string()).into()) + String::from_utf8_lossy(&msg).to_string())) }, } } diff --git a/openpgp-ffi/src/packet/literal.rs b/openpgp-ffi/src/packet/literal.rs index 2efea3c6..7bb25844 100644 --- a/openpgp-ffi/src/packet/literal.rs +++ b/openpgp-ffi/src/packet/literal.rs @@ -51,7 +51,7 @@ fn pgp_literal_into_packet(l: *mut Literal) -> *mut Packet { /// returns NULL in such cases. #[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" fn pgp_literal_filename(l: *const Literal) -> *mut c_char { - let l : &openpgp::packet::Literal = l.ref_raw().into(); + let l : &openpgp::packet::Literal = l.ref_raw(); if let Some(filename) = l.filename() { ffi_return_maybe_string!(filename) } else { diff --git a/openpgp-ffi/src/parse/stream.rs b/openpgp-ffi/src/parse/stream.rs index 16fb1829..f5f6a206 100644 --- a/openpgp-ffi/src/parse/stream.rs +++ b/openpgp-ffi/src/parse/stream.rs @@ -465,7 +465,7 @@ impl VerificationHelper for VHelper { Status::Success => Ok(()), // XXX: Convert the status to an error better. status => Err(anyhow::anyhow!( - "Inspect Callback returned an error: {:?}", status).into()), + "Inspect Callback returned an error: {:?}", status)), } } else { Ok(()) diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index dbe007c8..13d5afa2 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -134,7 +134,7 @@ impl TryFrom<Label> for Kind { Label::Signature => Ok(Kind::Signature), Label::File => Ok(Kind::File), Label::CleartextSignature => Err(crate::Error::InvalidOperation( - "armor::Kind cannot express cleartext signatures".into()).into()), + "armor::Kind cannot express cleartext signatures".into())), } } } diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs index 093c0480..1c23987d 100644 --- a/openpgp/src/cert.rs +++ b/openpgp/src/cert.rs @@ -2161,7 +2161,7 @@ impl Cert { Tag::SecretKey | Tag::PublicKey => Ok(()), _ => Err(Error::MalformedCert( format!("A certificate does not start with a {}", - tag).into()).into()), + tag)).into()), } } @@ -2191,7 +2191,7 @@ impl Cert { { Err(Error::MalformedCert( format!("A certificate cannot not include a {}", - tag).into()).into()) + tag)).into()) } // The rest either definitely belong in a certificate or // are unknown (and conservatively accepted for future diff --git a/openpgp/src/cert/amalgamation/key/iter.rs b/openpgp/src/cert/amalgamation/key/iter.rs index 53a72f79..f21df0d9 100644 --- a/openpgp/src/cert/amalgamation/key/iter.rs +++ b/openpgp/src/cert/amalgamation/key/iter.rs @@ -779,7 +779,7 @@ impl<'a, P, R> ValidKeyAmalgamationIter<'a, P, R> } else { let ka : ErasedKeyAmalgamation<'a, key::PublicParts> = SubordinateKeyAmalgamation::new( - cert.into(), self.subkey_iter.next()?).into(); + cert, self.subkey_iter.next()?).into(); match ka.with_policy(self.policy, self.time) { Ok(ka) => ka, Err(err) => { @@ -885,7 +885,7 @@ impl<'a, P, R> ValidKeyAmalgamationIter<'a, P, R> } } - return Some(ka.into()); + return Some(ka); } } } diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 84e7810e..e62bd5d0 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -1119,7 +1119,7 @@ impl CertBuilder<'_> { .expect("key generated above has a secret"); let sig = sig.sign_direct_key(&mut signer, key.parts_as_public())?; - Ok((key, sig.into())) + Ok((key, sig)) } } diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs index 2d62dc58..6b7369a9 100644 --- a/openpgp/src/cert/parser/mod.rs +++ b/openpgp/src/cert/parser/mod.rs @@ -174,7 +174,7 @@ impl KeyringValidator { self.error = Some(CertParserError::OpenPGP( Error::MalformedMessage( format!("Invalid Cert: {:?} packet (at {}) not expected", - tag, self.n_packets).into()))); + tag, self.n_packets)))); self.tokens.clear(); return; } @@ -921,15 +921,15 @@ pub(crate) fn split_sigs<C>(primary: &KeyHandle, primary_keyid: &KeyHandle, || typ == CertificationRevocation { if is_selfsig { - self_revs.push(sig.into()); + self_revs.push(sig); } else { - other_revs.push(sig.into()); + other_revs.push(sig); } } else { if is_selfsig { - self_signatures.push(sig.into()); + self_signatures.push(sig); } else { - certifications.push(sig.into()); + certifications.push(sig); } } } @@ -1206,8 +1206,8 @@ mod test { let userid : Packet = cert.clone() .into_iter() .filter(|p| p.tag() == Tag::UserID) - .nth(0).unwrap() - .into(); + .nth(0) + .unwrap(); // An unknown packet. let tag = Tag::Private(61); diff --git a/openpgp/src/crypto/backend/nettle/asymmetric.rs b/openpgp/src/crypto/backend/nettle/asymmetric.rs index d7ec16cf..b272ff36 100644 --- a/openpgp/src/crypto/backend/nettle/asymmetric.rs +++ b/openpgp/src/crypto/backend/nettle/asymmetric.rs @@ -450,8 +450,8 @@ impl<R> Key4<SecretParts, R> let (public, private) = rsa::generate_keypair(&mut rng, bits as u32)?; let (p, q, u) = private.as_rfc4880(); let public_mpis = PublicKey::RSA { - e: MPI::new(&*public.e()).into(), - n: MPI::new(&*public.n()).into(), + e: MPI::new(&*public.e()), + n: MPI::new(&*public.n()), }; let private_mpis = mpi::SecretKeyMaterial::RSA { d: MPI::new(&*private.d()).into(), diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index bee24f0a..3a2903d6 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -229,7 +229,7 @@ impl MessageValidator { Error::MalformedMessage( format!("Invalid OpenPGP message: \ {:?} packet (at {:?}) not expected", - tag, path).into()))); + tag, path)))); self.tokens.clear(); return; } @@ -454,7 +454,7 @@ impl TryFrom<PacketPile> for Message { Error::MalformedMessage( format!("Invalid OpenPGP message: \ {:?} packet (at {:?}) not expected: {}", - u.tag(), path, u.error()).into())) + u.tag(), path, u.error()))) .into()), _ => v.push(packet.tag(), &path), } @@ -481,7 +481,7 @@ impl TryFrom<PacketPile> for Message { // We really want to squash the lexer's error: it is an // internal detail that may change, and meaningless even // to an immediate user of this crate. - MessageValidity::Error(e) => Err(e.into()), + MessageValidity::Error(e) => Err(e), } } } diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 40f22a23..084ec50c 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -595,13 +595,13 @@ impl KeyParts for UnspecifiedParts { fn convert_key_amalgamation<'a, R: KeyRole>( ka: ComponentAmalgamation<'a, Key<UnspecifiedParts, R>>) -> Result<ComponentAmalgamation<'a, Key<UnspecifiedParts, R>>> { - Ok(ka.into()) + Ok(ka) } fn convert_key_amalgamation_ref<'a, R: KeyRole>( ka: &'a ComponentAmalgamation<'a, Key<UnspecifiedParts, R>>) -> Result<&'a ComponentAmalgamation<'a, Key<Self, R>>> { - Ok(ka.into()) + Ok(ka) } fn significant_secrets() -> bool { @@ -1367,7 +1367,7 @@ impl SecretKeyMaterial { match self { SecretKeyMaterial::Unencrypted(ref u) => { *self = SecretKeyMaterial::Encrypted( - u.encrypt(password)?.into()); + u.encrypt(password)?); Ok(()) } SecretKeyMaterial::Encrypted(_) => diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index da4c621c..ae92462a 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -1516,28 +1516,28 @@ impl<P: key::KeyParts, R: key::KeyRole> Key<P, R> { impl From<Key<key::PublicParts, key::PrimaryRole>> for Packet { /// Convert the `Key` struct to a `Packet`. fn from(k: Key<key::PublicParts, key::PrimaryRole>) -> Self { - Packet::PublicKey(k.into()) + Packet::PublicKey(k) } } impl From<Key<key::PublicParts, key::SubordinateRole>> for Packet { /// Convert the `Key` struct to a `Packet`. fn from(k: Key<key::PublicParts, key::SubordinateRole>) -> Self { - Packet::PublicSubkey(k.into()) + Packet::PublicSubkey(k) } } impl From<Key<key::SecretParts, key::PrimaryRole>> for Packet { /// Convert the `Key` struct to a `Packet`. fn from(k: Key<key::SecretParts, key::PrimaryRole>) -> Self { - Packet::SecretKey(k.into()) + Packet::SecretKey(k) } } impl From<Key<key::SecretParts, key::SubordinateRole>> for Packet { /// Convert the `Key` struct to a `Packet`. fn from(k: Key<key::SecretParts, key::SubordinateRole>) -> Self { - Packet::SecretSubkey(k.into()) + Packet::SecretSubkey(k) } } diff --git a/openpgp/src/packet/signature.rs b/openpgp/src/packet/signature.rs index 14fadbe9..eaa0c4a4 100644 --- a/openpgp/src/packet/signature.rs +++ b/openpgp/src/packet/signature.rs @@ -3410,8 +3410,8 @@ mod test { let embedded_sig = SignatureBuilder::new(SignatureType::PrimaryKeyBinding) .sign_hash(&mut pair, hash.clone()).unwrap(); builder.unhashed_area_mut().add(Subpacket::new( - SubpacketValue::EmbeddedSignature(embedded_sig.into()), false) - .unwrap()).unwrap(); + SubpacketValue::EmbeddedSignature(embedded_sig), false).unwrap()) + .unwrap(); let sig = builder.sign_hash(&mut pair, hash.clone()).unwrap().normalize(); assert_eq!(sig.unhashed_area().iter().count(), 3); diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 3885375c..fc619848 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -7089,8 +7089,8 @@ fn accessors() { sig = sig.set_signature_target(pk_algo, hash_algo, &digest).unwrap(); let sig_ = sig.clone().sign_hash(&mut keypair, hash.clone()).unwrap(); - assert_eq!(sig_.signature_target(), Some((pk_algo.into(), - hash_algo.into(), + assert_eq!(sig_.signature_target(), Some((pk_algo, + hash_algo, &digest[..]))); let embedded_sig = sig_.clone(); diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs index 4037f078..f9f3c1a4 100644 --- a/openpgp/src/packet/userid.rs +++ b/openpgp/src/packet/userid.rs @@ -595,14 +595,13 @@ impl UserID { Err(err) => return Err(err.context(format!( "Validating name ({:?})", - name)).into()), + name))), Ok(p) => { if !(p.name().is_some() && p.comment().is_none() && p.email().is_none()) { return Err(Error::InvalidArgument( - format!("Invalid name ({:?})", name) - .into()).into()); + format!("Invalid name ({:?})", name)).into()); } } } @@ -617,14 +616,13 @@ impl UserID { Err(err) => return Err(err.context(format!( "Validating comment ({:?})", - comment)).into()), + comment))), Ok(p) => { if !(p.name().is_none() && p.comment().is_some() && p.email().is_none()) { return Err(Error::InvalidArgument( - format!("Invalid comment ({:?})", comment) - .into()).into()); + format!("Invalid comment ({:?})", comment)).into()); } } } @@ -644,14 +642,14 @@ impl UserID { Err(err) => return Err(err.context(format!( "Validating address ({:?})", - address)).into()), + address))), Ok(p) => { if !(p.name().is_none() && p.comment().is_none() && p.email().is_some()) { return Err(Error::InvalidArgument( - format!("Invalid address address ({:?})", address) - .into()).into()); + format!("Invalid address address ({:?})", address)) + .into()); } } } @@ -673,14 +671,13 @@ impl UserID { Err(err) => return Err(err.context(format!( "Validating User ID ({:?})", - value)).into()), + value))), Ok(p) => { if !(p.name().is_none() == name.is_none() && p.comment().is_none() == comment.is_none() && p.email().is_some()) { return Err(Error::InvalidArgument( - format!("Invalid User ID ({:?})", value) - .into()).into()); + format!("Invalid User ID ({:?})", value)).into()); } } } @@ -857,7 +854,6 @@ impl UserID { Ok(puid) => puid, Err(err) => { // Return the error from the NameAddrOrOther parser. - let err : anyhow::Error = err.into(); return Err(err).context(format!( "Failed to parse User ID: {:?}", s))?; } diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index c077e81d..30593e82 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -1352,7 +1352,7 @@ impl Signature4 { let typ = typ.into(); let need_hash = HashingMode::for_signature(hash_algo, typ); let mut pp = php.ok(Packet::Signature(Signature4::new( - typ, pk_algo.into(), hash_algo, + typ, pk_algo, hash_algo, hashed_area, unhashed_area, [digest_prefix1, digest_prefix2], @@ -1455,8 +1455,7 @@ impl Signature4 { return Err( Error::MalformedPacket( format!("Unexpected body length encoding: {:?}", - header.length()) - .into()).into()); + header.length())).into()); } // Make sure we have a minimum header. @@ -2256,14 +2255,13 @@ impl Key4<key::UnspecifiedParts, key::UnspecifiedRole> if len < 6 { // Much too short. return Err(Error::MalformedPacket( - format!("Packet too short ({} bytes)", len).into()).into()); + format!("Packet too short ({} bytes)", len)).into()); } } else { |