From 7febc9e2722f7ca97be91dc4a68c9f6a0502dc27 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 20 Sep 2021 19:26:48 +0300 Subject: Avoid matching on &Foo, when a plain Foo pattern works The extra & in a pattern (match arm or if let) is unnecessary and only makes the code harder to read. In most places it's enough to just remove the & from the pattern, but in a few places a dereference (*) needs to be added where the value captured in the pattern is used, as removing the & changes the type of the captured value to be a reference. Overall, the changes are almost mechanical. Although the diff is huge, it should be easy to read. The clippy lint match_ref_pats warns about this. See: https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats --- ffi-macros/src/rust2c.rs | 2 +- ffi/src/error.rs | 56 +++--- ipc/src/core.rs | 6 +- net/src/lib.rs | 16 +- openpgp-ffi/src/error.rs | 56 +++--- openpgp-ffi/src/packet/skesk.rs | 2 +- openpgp-ffi/src/packet/user_attribute.rs | 2 +- openpgp-ffi/src/packet/userid.rs | 12 +- openpgp/src/armor.rs | 10 +- openpgp/src/cert/parser/low_level/lexer.rs | 18 +- openpgp/src/crypto/backend/nettle/ecdh.rs | 2 +- openpgp/src/crypto/ecdh.rs | 2 +- openpgp/src/crypto/mpi.rs | 64 +++---- openpgp/src/fingerprint.rs | 8 +- openpgp/src/keyid.rs | 8 +- openpgp/src/message/mod.rs | 2 +- openpgp/src/packet/mod.rs | 122 ++++++------ openpgp/src/packet/skesk.rs | 4 +- openpgp/src/packet/tag.rs | 42 ++--- openpgp/src/parse.rs | 15 +- openpgp/src/serialize.rs | 286 +++++++++++++++-------------- openpgp/src/types/mod.rs | 32 ++-- store/src/backend/mod.rs | 40 ++-- 23 files changed, 406 insertions(+), 401 deletions(-) diff --git a/ffi-macros/src/rust2c.rs b/ffi-macros/src/rust2c.rs index f4595813..97ad2b53 100644 --- a/ffi-macros/src/rust2c.rs +++ b/ffi-macros/src/rust2c.rs @@ -152,7 +152,7 @@ pub fn rust2c(fun: &syn::ItemFn) -> String { } match arg { - &syn::FnArg::Typed(ref cap) => { + syn::FnArg::Typed(ref cap) => { let pat_ident = match *cap.pat { syn::Pat::Ident(ref i) => i, _ => unimplemented!(), diff --git a/ffi/src/error.rs b/ffi/src/error.rs index dc4ab474..003477dd 100644 --- a/ffi/src/error.rs +++ b/ffi/src/error.rs @@ -28,63 +28,63 @@ impl<'a> FromSequoiaError<'a> for Status { if let Some(e) = e.downcast_ref::() { return match e { - &openpgp::Error::InvalidArgument(_) => + openpgp::Error::InvalidArgument(_) => Status::InvalidArgument, - &openpgp::Error::InvalidOperation(_) => + openpgp::Error::InvalidOperation(_) => Status::InvalidOperation, - &openpgp::Error::MalformedPacket(_) => + openpgp::Error::MalformedPacket(_) => Status::MalformedPacket, - &openpgp::Error::PacketTooLarge(_, _, _) => + openpgp::Error::PacketTooLarge(_, _, _) => Status::PacketTooLarge, - &openpgp::Error::UnsupportedPacketType(_) => + openpgp::Error::UnsupportedPacketType(_) => Status::UnsupportedPacketType, - &openpgp::Error::UnsupportedHashAlgorithm(_) => + openpgp::Error::UnsupportedHashAlgorithm(_) => Status::UnsupportedHashAlgorithm, - &openpgp::Error::UnsupportedPublicKeyAlgorithm(_) => + openpgp::Error::UnsupportedPublicKeyAlgorithm(_) => Status::UnsupportedPublicKeyAlgorithm, - &openpgp::Error::UnsupportedEllipticCurve(_) => + openpgp::Error::UnsupportedEllipticCurve(_) => Status::UnsupportedEllipticCurve, - &openpgp::Error::UnsupportedSymmetricAlgorithm(_) => + openpgp::Error::UnsupportedSymmetricAlgorithm(_) => Status::UnsupportedSymmetricAlgorithm, - &openpgp::Error::UnsupportedAEADAlgorithm(_) => + openpgp::Error::UnsupportedAEADAlgorithm(_) => Status::UnsupportedAEADAlgorithm, - &openpgp::Error::UnsupportedCompressionAlgorithm(_) => + openpgp::Error::UnsupportedCompressionAlgorithm(_) => Status::UnsupportedCompressionAlgorithm, - &openpgp::Error::UnsupportedSignatureType(_) => + openpgp::Error::UnsupportedSignatureType(_) => Status::UnsupportedSignatureType, - &openpgp::Error::InvalidPassword => + openpgp::Error::InvalidPassword => Status::InvalidPassword, - &openpgp::Error::InvalidSessionKey(_) => + openpgp::Error::InvalidSessionKey(_) => Status::InvalidSessionKey, - &openpgp::Error::MissingSessionKey(_) => + openpgp::Error::MissingSessionKey(_) => Status::MissingSessionKey, - &openpgp::Error::MalformedMPI(_) => + openpgp::Error::MalformedMPI(_) => Status::MalformedMPI, - &openpgp::Error::BadSignature(_) => + openpgp::Error::BadSignature(_) => Status::BadSignature, - &openpgp::Error::ManipulatedMessage => + openpgp::Error::ManipulatedMessage => Status::ManipulatedMessage, - &openpgp::Error::MalformedMessage(_) => + openpgp::Error::MalformedMessage(_) => Status::MalformedMessage, - &openpgp::Error::MalformedCert(_) => + openpgp::Error::MalformedCert(_) => Status::MalformedCert, - &openpgp::Error::IndexOutOfRange => + openpgp::Error::IndexOutOfRange => Status::IndexOutOfRange, - &openpgp::Error::UnsupportedCert(_) => + openpgp::Error::UnsupportedCert(_) => Status::UnsupportedCert, - &openpgp::Error::Expired(_) => + openpgp::Error::Expired(_) => Status::Expired, - &openpgp::Error::NotYetLive(_) => + openpgp::Error::NotYetLive(_) => Status::NotYetLive, - &openpgp::Error::NoBindingSignature(_) => + openpgp::Error::NoBindingSignature(_) => Status::NoBindingSignature, - &openpgp::Error::InvalidKey(_) => + openpgp::Error::InvalidKey(_) => Status::InvalidKey, - &openpgp::Error::PolicyViolation(_, _) => + openpgp::Error::PolicyViolation(_, _) => Status::PolicyViolation, // openpgp::Error is non_exhaustive, match on &_ to handle // future additions. - &_ => Status::UnknownError + _ => Status::UnknownError } } diff --git a/ipc/src/core.rs b/ipc/src/core.rs index d6895e01..b4dd928a 100644 --- a/ipc/src/core.rs +++ b/ipc/src/core.rs @@ -291,9 +291,9 @@ pub enum IPCPolicy { impl<'a> From<&'a IPCPolicy> for u8 { fn from(policy: &IPCPolicy) -> Self { match policy { - &IPCPolicy::External => 0, - &IPCPolicy::Internal => 1, - &IPCPolicy::Robust => 2, + IPCPolicy::External => 0, + IPCPolicy::Internal => 1, + IPCPolicy::Robust => 2, } } } diff --git a/net/src/lib.rs b/net/src/lib.rs index c6eaf0a3..74f0ecfb 100644 --- a/net/src/lib.rs +++ b/net/src/lib.rs @@ -92,10 +92,10 @@ pub enum Policy { impl fmt::Display for Policy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", match self { - &Policy::Offline => "Offline", - &Policy::Anonymized => "Anonymized", - &Policy::Encrypted => "Encrypted", - &Policy::Insecure => "Insecure", + Policy::Offline => "Offline", + Policy::Anonymized => "Anonymized", + Policy::Encrypted => "Encrypted", + Policy::Insecure => "Insecure", }) } } @@ -115,10 +115,10 @@ impl Policy { impl<'a> From<&'a Policy> for u8 { fn from(policy: &Policy) -> Self { match policy { - &Policy::Offline => 0, - &Policy::Anonymized => 1, - &Policy::Encrypted => 2, - &Policy::Insecure => 3, + Policy::Offline => 0, + Policy::Anonymized => 1, + Policy::Encrypted => 2, + Policy::Insecure => 3, } } } diff --git a/openpgp-ffi/src/error.rs b/openpgp-ffi/src/error.rs index 04bb05c0..1709e1c9 100644 --- a/openpgp-ffi/src/error.rs +++ b/openpgp-ffi/src/error.rs @@ -211,63 +211,63 @@ impl<'a> From<&'a anyhow::Error> for Status { fn from(e: &'a anyhow::Error) -> Self { if let Some(e) = e.downcast_ref::() { return match e { - &openpgp::Error::InvalidArgument(_) => + openpgp::Error::InvalidArgument(_) => Status::InvalidArgument, - &openpgp::Error::InvalidOperation(_) => + openpgp::Error::InvalidOperation(_) => Status::InvalidOperation, - &openpgp::Error::MalformedPacket(_) => + openpgp::Error::MalformedPacket(_) => Status::MalformedPacket, - &openpgp::Error::PacketTooLarge(_, _, _) => + openpgp::Error::PacketTooLarge(_, _, _) => Status::PacketTooLarge, - &openpgp::Error::UnsupportedPacketType(_) => + openpgp::Error::UnsupportedPacketType(_) => Status::UnsupportedPacketType, - &openpgp::Error::UnsupportedHashAlgorithm(_) => + openpgp::Error::UnsupportedHashAlgorithm(_) => Status::UnsupportedHashAlgorithm, - &openpgp::Error::UnsupportedPublicKeyAlgorithm(_) => + openpgp::Error::UnsupportedPublicKeyAlgorithm(_) => Status::UnsupportedPublicKeyAlgorithm, - &openpgp::Error::UnsupportedEllipticCurve(_) => + openpgp::Error::UnsupportedEllipticCurve(_) => Status::UnsupportedEllipticCurve, - &openpgp::Error::UnsupportedSymmetricAlgorithm(_) => + openpgp::Error::UnsupportedSymmetricAlgorithm(_) => Status::UnsupportedSymmetricAlgorithm, - &openpgp::Error::UnsupportedAEADAlgorithm(_) => + openpgp::Error::UnsupportedAEADAlgorithm(_) => Status::UnsupportedAEADAlgorithm, - &openpgp::Error::UnsupportedCompressionAlgorithm(_) => + openpgp::Error::UnsupportedCompressionAlgorithm(_) => Status::UnsupportedCompressionAlgorithm, - &openpgp::Error::UnsupportedSignatureType(_) => + openpgp::Error::UnsupportedSignatureType(_) => Status::UnsupportedSignatureType, - &openpgp::Error::InvalidPassword => + openpgp::Error::InvalidPassword => Status::InvalidPassword, - &openpgp::Error::InvalidSessionKey(_) => + openpgp::Error::InvalidSessionKey(_) => Status::InvalidSessionKey, - &openpgp::Error::MissingSessionKey(_) => + openpgp::Error::MissingSessionKey(_) => Status::MissingSessionKey, - &openpgp::Error::MalformedMPI(_) => + openpgp::Error::MalformedMPI(_) => Status::MalformedMPI, - &openpgp::Error::BadSignature(_) => + openpgp::Error::BadSignature(_) => Status::BadSignature, - &openpgp::Error::ManipulatedMessage => + openpgp::Error::ManipulatedMessage => Status::ManipulatedMessage, - &openpgp::Error::MalformedMessage(_) => + openpgp::Error::MalformedMessage(_) => Status::MalformedMessage, - &openpgp::Error::MalformedCert(_) => + openpgp::Error::MalformedCert(_) => Status::MalformedCert, - &openpgp::Error::IndexOutOfRange => + openpgp::Error::IndexOutOfRange => Status::IndexOutOfRange, - &openpgp::Error::UnsupportedCert(_) => + openpgp::Error::UnsupportedCert(_) => Status::UnsupportedCert, - &openpgp::Error::Expired(_) => + openpgp::Error::Expired(_) => Status::Expired, - &openpgp::Error::NotYetLive(_) => + openpgp::Error::NotYetLive(_) => Status::NotYetLive, - &openpgp::Error::NoBindingSignature(_) => + openpgp::Error::NoBindingSignature(_) => Status::NoBindingSignature, - &openpgp::Error::InvalidKey(_) => + openpgp::Error::InvalidKey(_) => Status::InvalidKey, - &openpgp::Error::PolicyViolation(_, _) => + openpgp::Error::PolicyViolation(_, _) => Status::PolicyViolation, // openpgp::Error is non_exhaustive, match on &_ to handle // future additions. - &_ => Status::UnknownError + _ => Status::UnknownError } } diff --git a/openpgp-ffi/src/packet/skesk.rs b/openpgp-ffi/src/packet/skesk.rs index ddc41e1c..a6e9bdfb 100644 --- a/openpgp-ffi/src/packet/skesk.rs +++ b/openpgp-ffi/src/packet/skesk.rs @@ -32,7 +32,7 @@ pub extern "C" fn pgp_skesk_decrypt(errp: Option<&mut *mut crate::error::Error>, let algo = ffi_param_ref_mut!(algo); let key_len = ffi_param_ref_mut!(key_len); - if let &openpgp::Packet::SKESK(ref skesk) = skesk.ref_raw() { + if let openpgp::Packet::SKESK(ref skesk) = skesk.ref_raw() { match skesk.decrypt(&password.to_owned().into()) { Ok((a, k)) => { *algo = a.into(); diff --git a/openpgp-ffi/src/packet/user_attribute.rs b/openpgp-ffi/src/packet/user_attribute.rs index 42e7d156..ad141056 100644 --- a/openpgp-ffi/src/packet/user_attribute.rs +++ b/openpgp-ffi/src/packet/user_attribute.rs @@ -18,7 +18,7 @@ use crate::RefRaw; pub extern "C" fn pgp_user_attribute_value(ua: *const Packet, value_len: Option<&mut size_t>) -> *const u8 { - if let &openpgp::Packet::UserAttribute(ref ua) = ua.ref_raw() { + if let openpgp::Packet::UserAttribute(ref ua) = ua.ref_raw() { if let Some(p) = value_len { *p = ua.value().len(); } diff --git a/openpgp-ffi/src/packet/userid.rs b/openpgp-ffi/src/packet/userid.rs index 89febc06..db0f731b 100644 --- a/openpgp-ffi/src/packet/userid.rs +++ b/openpgp-ffi/src/packet/userid.rs @@ -129,7 +129,7 @@ pub extern "C" fn pgp_user_id_value(uid: *const Packet, value_len: Option<&mut size_t>) -> *const u8 { - if let &openpgp::Packet::UserID(ref uid) = uid.ref_raw() { + if let openpgp::Packet::UserID(ref uid) = uid.ref_raw() { if let Some(p) = value_len { *p = uid.value().len(); } @@ -158,7 +158,7 @@ fn pgp_user_id_name( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.name() { Ok(Some(name)) => *namep = ffi_return_string!(name), @@ -199,7 +199,7 @@ fn pgp_user_id_comment( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.comment() { Ok(Some(comment)) => *commentp = ffi_return_string!(comment), @@ -240,7 +240,7 @@ fn pgp_user_id_email( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.email() { Ok(Some(address)) => *addressp = ffi_return_string!(address), @@ -280,7 +280,7 @@ fn pgp_user_id_uri( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.uri() { Ok(Some(uri)) => *urip = ffi_return_string!(uri), @@ -330,7 +330,7 @@ fn pgp_user_id_email_normalized( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.email_normalized() { Ok(Some(email)) => *emailp = ffi_return_string!(email), diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index 7f35a804..851408a2 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -211,11 +211,11 @@ impl Kind { fn blurb(&self) -> &str { match self { - &Kind::Message => "MESSAGE", - &Kind::PublicKey => "PUBLIC KEY BLOCK", - &Kind::SecretKey => "PRIVATE KEY BLOCK", - &Kind::Signature => "SIGNATURE", - &Kind::File => "ARMORED FILE", + Kind::Message => "MESSAGE", + Kind::PublicKey => "PUBLIC KEY BLOCK", + Kind::SecretKey => "PRIVATE KEY BLOCK", + Kind::Signature => "SIGNATURE", + Kind::File => "ARMORED FILE", } } diff --git a/openpgp/src/cert/parser/low_level/lexer.rs b/openpgp/src/cert/parser/low_level/lexer.rs index a8fad2e8..1a698579 100644 --- a/openpgp/src/cert/parser/low_level/lexer.rs +++ b/openpgp/src/cert/parser/low_level/lexer.rs @@ -64,15 +64,15 @@ assert_send_and_sync!(Component); impl<'a> From<&'a Token> for Tag { fn from(token: &'a Token) -> Self { match token { - &Token::PublicKey(_) => Tag::PublicKey, - &Token::SecretKey(_) => Tag::SecretKey, - &Token::PublicSubkey(_) => Tag::PublicSubkey, - &Token::SecretSubkey(_) => Tag::SecretSubkey, - &Token::UserID(_) => Tag::UserID, - &Token::UserAttribute(_) => Tag::UserAttribute, - &Token::Signature(_) => Tag::Signature, - &Token::Trust(_) => Tag::Trust, - &Token::Unknown(tag, _) => tag, + Token::PublicKey(_) => Tag::PublicKey, + Token::SecretKey(_) => Tag::SecretKey, + Token::PublicSubkey(_) => Tag::PublicSubkey, + Token::SecretSubkey(_) => Tag::SecretSubkey, + Token::UserID(_) => Tag::UserID, + Token::UserAttribute(_) => Tag::UserAttribute, + Token::Signature(_) => Tag::Signature, + Token::Trust(_) => Tag::Trust, + Token::Unknown(tag, _) => *tag, } } } diff --git a/openpgp/src/crypto/backend/nettle/ecdh.rs b/openpgp/src/crypto/backend/nettle/ecdh.rs index c26a843b..af1a7220 100644 --- a/openpgp/src/crypto/backend/nettle/ecdh.rs +++ b/openpgp/src/crypto/backend/nettle/ecdh.rs @@ -19,7 +19,7 @@ pub fn encrypt(recipient: &Key, { let mut rng = Yarrow::default(); - if let &PublicKey::ECDH { + if let PublicKey::ECDH { ref curve, ref q,.. } = recipient.mpis() { match curve { diff --git a/openpgp/src/crypto/ecdh.rs b/openpgp/src/crypto/ecdh.rs index c49807f5..3407e8a3 100644 --- a/openpgp/src/crypto/ecdh.rs +++ b/openpgp/src/crypto/ecdh.rs @@ -40,7 +40,7 @@ pub(crate) fn encrypt_wrap(recipient: &Key, where R: key::KeyRole { match recipient.mpis() { - &mpi::PublicKey::ECDH { ref curve, ref hash, ref sym,.. } => { + mpi::PublicKey::ECDH { ref curve, ref hash, ref sym,.. } => { // m = sym_alg_ID || session key || checksum || pkcs5_padding; let mut m = Vec::with_capacity(40); m.extend_from_slice(session_key); diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs index ae7e9b1b..0bda2b52 100644 --- a/openpgp/src/crypto/mpi.rs +++ b/openpgp/src/crypto/mpi.rs @@ -521,13 +521,13 @@ impl PublicKey { pub fn bits(&self) -> Option { use self::PublicKey::*; match self { - &RSA { ref n,.. } => Some(n.bits()), - &DSA { ref p,.. } => Some(p.bits()), - &ElGamal { ref p,.. } => Some(p.bits()), - &EdDSA { ref curve,.. } => curve.bits(), - &ECDSA { ref curve,.. } => curve.bits(), - &ECDH { ref curve,.. } => curve.bits(), - &Unknown { .. } => None, + RSA { ref n,.. } => Some(n.bits()), + DSA { ref p,.. } => Some(p.bits()), + ElGamal { ref p,.. } => Some(p.bits()), + EdDSA { ref curve,.. } => curve.bits(), + ECDSA { ref curve,.. } => curve.bits(), + ECDH { ref curve,.. } => curve.bits(), + Unknown { .. } => None, } } @@ -671,36 +671,36 @@ impl fmt::Debug for SecretKeyMaterial { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if cfg!(debug_assertions) { match self { - &SecretKeyMaterial::RSA{ ref d, ref p, ref q, ref u } => + SecretKeyMaterial::RSA{ ref d, ref p, ref q, ref u } => write!(f, "RSA {{ d: {:?}, p: {:?}, q: {:?}, u: {:?} }}", d, p, q, u), - &SecretKeyMaterial::DSA{ ref x } => + SecretKeyMaterial::DSA{ ref x } => write!(f, "DSA {{ x: {:?} }}", x), - &SecretKeyMaterial::ElGamal{ ref x } => + SecretKeyMaterial::ElGamal{ ref x } => write!(f, "ElGamal {{ x: {:?} }}", x), - &SecretKeyMaterial::EdDSA{ ref scalar } => + SecretKeyMaterial::EdDSA{ ref scalar } => write!(f, "EdDSA {{ scalar: {:?} }}", scalar), - &SecretKeyMaterial::ECDSA{ ref scalar } => + SecretKeyMaterial::ECDSA{ ref scalar } => write!(f, "ECDSA {{ scalar: {:?} }}", scalar), - &SecretKeyMaterial::ECDH{ ref scalar } => + SecretKeyMaterial::ECDH{ ref scalar } => write!(f, "ECDH {{ scalar: {:?} }}", scalar), - &SecretKeyMaterial::Unknown{ ref mpis, ref rest } => + SecretKeyMaterial::Unknown{ ref mpis, ref rest } => write!(f, "Unknown {{ mips: {:?}, rest: {:?} }}", mpis, rest), } } else { match self { - &SecretKeyMaterial::RSA{ .. } => + SecretKeyMaterial::RSA{ .. } => f.write_str("RSA { }"), - &SecretKeyMaterial::DSA{ .. } => + SecretKeyMaterial::DSA{ .. } => f.write_str("DSA { }"), - &SecretKeyMaterial::ElGamal{ .. } => + SecretKeyMaterial::ElGamal{ .. } => f.write_str("ElGamal { }"), - &SecretKeyMaterial::EdDSA{ .. } => + SecretKeyMaterial::EdDSA{ .. } => f.write_str("EdDSA { }"), - &SecretKeyMaterial::ECDSA{ .. } => + SecretKeyMaterial::ECDSA{ .. } => f.write_str("ECDSA { }"), - &SecretKeyMaterial::ECDH{ .. } => + SecretKeyMaterial::ECDH{ .. } => f.write_str("ECDH { }"), - &SecretKeyMaterial::Unknown{ .. } => + SecretKeyMaterial::Unknown{ .. } => f.write_str("Unknown { }"), } } @@ -713,13 +713,13 @@ impl PartialOrd for SecretKeyMaterial { fn discriminant(sk: &SecretKeyMaterial) -> usize { match sk { - &SecretKeyMaterial::RSA{ .. } => 0, - &SecretKeyMaterial::DSA{ .. } => 1, - &SecretKeyMaterial::ElGamal{ .. } => 2, - &SecretKeyMaterial::EdDSA{ .. } => 3, - &SecretKeyMaterial::ECDSA{ .. } => 4, - &SecretKeyMaterial::ECDH{ .. } => 5, - &SecretKeyMaterial::Unknown{ .. } => 6, + SecretKeyMaterial::RSA{ .. } => 0, + SecretKeyMaterial::DSA{ .. } => 1, + SecretKeyMaterial::ElGamal{ .. } => 2, + SecretKeyMaterial::EdDSA{ .. } => 3, + SecretKeyMaterial::ECDSA{ .. } => 4, + SecretKeyMaterial::ECDH{ .. } => 5, + SecretKeyMaterial::Unknown{ .. } => 6, } } @@ -928,10 +928,10 @@ impl Ciphertext { // plus the big endian value itself. All other field types are // commented. match self { - &RSA { .. } => Some(PublicKeyAlgorithm::RSAEncryptSign), - &ElGamal { .. } => Some(PublicKeyAlgorithm::ElGamalEncrypt), - &ECDH { .. } => Some(PublicKeyAlgorithm::ECDH), - &Unknown { .. } => None, + RSA { .. } => Some(PublicKeyAlgorithm::RSAEncryptSign), + ElGamal { .. } => Some(PublicKeyAlgorithm::ElGamalEncrypt), + ECDH { .. } => Some(PublicKeyAlgorithm::ECDH), + Unknown { .. } => None, } } } diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs index b7fbc3af..d60f3faa 100644 --- a/openpgp/src/fingerprint.rs +++ b/openpgp/src/fingerprint.rs @@ -141,8 +141,8 @@ impl Fingerprint { /// ``` pub fn as_bytes(&self) -> &[u8] { match self { - &Fingerprint::V4(ref fp) => fp, - &Fingerprint::Invalid(ref fp) => fp, + Fingerprint::V4(ref fp) => fp, + Fingerprint::Invalid(ref fp) => fp, } } @@ -233,8 +233,8 @@ impl Fingerprint { /// Common code for the above functions. fn convert_to_string(&self, pretty: bool) -> String { let raw = match self { - &Fingerprint::V4(ref fp) => &fp[..], - &Fingerprint::Invalid(ref fp) => &fp[..], + Fingerprint::V4(ref fp) => &fp[..], + Fingerprint::Invalid(ref fp) => &fp[..], }; // We currently only handle V4 fingerprints, which look like: diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs index 632b9439..6186d208 100644 --- a/openpgp/src/keyid.rs +++ b/openpgp/src/keyid.rs @@ -240,8 +240,8 @@ impl KeyID { /// ``` pub fn as_bytes(&self) -> &[u8] { match self { - &KeyID::V4(ref id) => id, - &KeyID::Invalid(ref id) => id, + KeyID::V4(ref id) => id, + KeyID::Invalid(ref id) => id, } } @@ -353,8 +353,8 @@ impl KeyID { /// Common code for the above functions. fn convert_to_string(&self, pretty: bool) -> String { let raw = match self { - &KeyID::V4(ref fp) => &fp[..], - &KeyID::Invalid(ref fp) => &fp[..], + KeyID::V4(ref fp) => &fp[..], + KeyID::Invalid(ref fp) => &fp[..], }; // We currently only handle V4 Key IDs, which look like: diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index 2d92f44d..662e4e02 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -408,7 +408,7 @@ impl Message { /// ``` pub fn body(&self) -> Option<&Literal> { for packet in self.pile.descendants() { - if let &Packet::Literal(ref l) = packet { + if let Packet::Literal(ref l) = packet { return Some(l); } } diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index e3e1ffc5..7de9b603 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -330,24 +330,24 @@ impl Packet { /// [Section 4.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-4.3 pub fn tag(&self) -> Tag { match self { - &Packet::Unknown(ref packet) => packet.tag(), - &Packet::Signature(_) => Tag::Signature, - &Packet::OnePassSig(_) => Tag::OnePassSig, - &Packet::PublicKey(_) => Tag::PublicKey, - &Packet::PublicSubkey(_) => Tag::PublicSubkey, - &Packet::SecretKey(_) => Tag::SecretKey, - &Packet::SecretSubkey(_) => Tag::SecretSubkey, - &Packet::Marker(_) => Tag::Marker, - &Packet::Trust(_) => Tag::Trust, - &Packet::UserID(_) => Tag::UserID, - &Packet::UserAttribute(_) => Tag::UserAttribute, - &Packet::Literal(_) => Tag::Literal, - &Packet::CompressedData(_) => Tag::CompressedData, - &Packet::PKESK(_) => Tag::PKESK, - &Packet::SKESK(_) => Tag::SKESK, - &Packet::SEIP(_) => Tag::SEIP, - &Packet::MDC(_) => Tag::MDC, - &Packet::AED(_) => Tag::AED, + Packet::Unknown(ref packet) => packet.tag(), + Packet::Signature(_) => Tag::Signature, + Packet::OnePassSig(_) => Tag::OnePassSig, + Packet::PublicKey(_) => Tag::PublicKey, + Packet::PublicSubkey(_) => Tag::PublicSubkey, + Packet::SecretKey(_) => Tag::SecretKey, + Packet::SecretSubkey(_) => Tag::SecretSubkey, + Packet::Marker(_) => Tag::Marker, + Packet::Trust(_) => Tag::Trust, + Packet::UserID(_) => Tag::UserID, + Packet::UserAttribute(_) => Tag::UserAttribute, + Packet::Literal(_) => Tag::Literal, + Packet::CompressedData(_) => Tag::CompressedData, + Packet::PKESK(_) => Tag::PKESK, + Packet::SKESK(_) => Tag::SKESK, + Packet::SEIP(_) => Tag::SEIP, + Packet::MDC(_) => Tag::MDC, + Packet::AED(_) => Tag::AED, } } @@ -360,7 +360,7 @@ impl Packet { /// whereas `kind()` returns `None`. pub fn kind(&self) -> Option { match self { - &Packet::Unknown(_) => None, + Packet::Unknown(_) => None, _ => Some(self.tag()), } } @@ -413,25 +413,25 @@ impl Deref for Packet { fn deref(&self) -> &Self::Target { match self { - &Packet::Unknown(ref packet) => &packet.common, - &Packet::Signature(ref packet) => &packet.common, - &Packet::OnePassSig(ref packet) => &packet.common, - &Packet::PublicKey(ref packet) => &packet.common, - &Packet::PublicSubkey(ref packet) => &packet.common, - &Packet::SecretKey(ref packet) => &packet.common, - &Packet::SecretSubkey(ref packet) => &packet.common, - &Packet::Marker(ref packet) => &packet.common, - &Packet::Trust(ref packet) => &packet.common, - &Packet::UserID(ref packet) => &packet.common, - &Packet::UserAttribute(ref packet) => &packet.common, - &Packet::Literal(ref packet) => &packet.common, - &Packet::CompressedData(ref packet) => &packet.common, - &Packet::PKESK(ref packet) => &packet.common, - &Packet::SKESK(SKESK::V4(ref packet)) => &packet.common, - &Packet::SKESK(SKESK::V5(ref packet)) => &packet.skesk4.common, - &Packet::SEIP(ref packet) => &packet.common, - &Packet::MDC(ref packet) => &packet.common, - &Packet::AED(ref packet) => &packet.common, + Packet::Unknown(ref packet) => &packet.common, + Packet::Signature(ref packet) => &packet.common, + Packet::OnePassSig(ref packet) => &packet.common, + Packet::PublicKey(ref packet) => &packet.common, + Packet::PublicSubkey(ref packet) => &packet.common, + Packet::SecretKey(ref packet) => &packet.common, + Packet::SecretSubkey(ref packet) => &packet.common, + Packet::Marker(ref packet) => &packet.common, + Packet::Trust(ref packet) => &packet.common, + Packet::UserID(ref packet) => &packet.common, + Packet::UserAttribute(ref packet) => &packet.common, + Packet::Literal(ref packet) => &packet.common, + Packet::CompressedData(ref packet) => &packet.common, + Packet::PKESK(ref packet) => &packet.common, + Packet::SKESK(SKESK::V4(ref packet)) => &packet.common, + Packet::SKESK(SKESK::V5(ref packet)) => &packet.skesk4.common, + Packet::SEIP(ref packet) => &packet.common, + Packet::MDC(ref packet) => &packet.common, + Packet::AED(ref packet) => &packet.common, } } } @@ -439,25 +439,25 @@ impl Deref for Packet { impl DerefMut for Packet { fn deref_mut(&mut self) -> &mut Common { match self { - &mut Packet::Unknown(ref mut packet) => &mut packet.common, - &mut Packet::Signature(ref mut packet) => &mut packet.common, - &mut Packet::OnePassSig(ref mut packet) => &mut packet.common, - &mut Packet::PublicKey(ref mut packet) => &mut packet.common, - &mut Packet::PublicSubkey(ref mut packet) => &mut packet.common, - &mut Packet::SecretKey(ref mut packet) => &mut packet.common, - &mut Packet::SecretSubkey(ref mut packet) => &mut packet.common, - &mut Packet::Marker(ref mut packet) => &mut packet.common, - &mut Packet::Trust(ref mut packet) => &mut packet.common, - &mut Packet::UserID(ref mut packet) => &mut packet.common, - &mut Packet::UserAttribute(ref mut packet) => &mut packet.common, - &mut Packet::Literal(ref mut packet) => &mut packet.common, - &mut Packet::CompressedData(ref mut packet) => &mut packet.common, - &mut Packet::PKESK(ref mut packet) => &mut packet.common, - &mut Packet::SKESK(SKESK::V4(ref mut packet)) => &mut packet.common, - &mut Packet::SKESK(SKESK::V5(ref mut packet)) => &mut packet.skesk4.common, - &mut Packet::SEIP(ref mut packet) => &mut packet.common, - &mut Packet::MDC(ref mut packet) => &mut packet.common, - &mut Packet::AED(ref mut packet) => &mut packet.common, + Packet::Unknown(ref mut packet) => &mut packet.common, + Packet::Signature(ref mut packet) => &mut packet.common, + Packet::OnePassSig(ref mut packet) => &mut packet.common, + Packet::PublicKey(ref mut packet) => &mut packet.common, + Packet::PublicSubkey(ref mut packet) => &mut packet.common, + Packet::SecretKey(ref mut packet) => &mut packet.common, + Packet::SecretSubkey(ref mut packet) => &mut packet.common, + Packet::Marker(ref mut packet) => &mut packet.common, + Packet::Trust(ref mut packet) => &mut packet.common, + Packet::UserID(ref mut packet) => &mut packet.common, + Packet::UserAttribute(ref mut packet) => &mut packet.common, + Packet::Literal(ref mut packet) => &mut packet.common, + Packet::CompressedData(ref mut packet) => &mut packet.common, + Packet::PKESK(ref mut packet) => &mut packet.common, + Packet::SKESK(SKESK::V4(ref mut packet)) => &mut packet.common, + Packet::SKESK(SKESK::V5(ref mut packet)) => &mut packet.skesk4.common, + Packet::SEIP(ref mut packet) => &mut packet.common, + Packet::MDC(ref mut packet) => &mut packet.common, + Packet::AED(ref mut packet) => &mut packet.common, } } } @@ -972,7 +972,7 @@ impl Signature { /// Gets the version. pub fn version(&self) -> u8 { match self { - &Signature::V4(_) => 4, + Signature::V4(_) => 4, } } } @@ -1030,7 +1030,7 @@ impl OnePassSig { /// Gets the version. pub fn version(&self) -> u8 { match self { - &OnePassSig::V3(_) => 3, + OnePassSig::V3(_) => 3, } } } @@ -1154,8 +1154,8 @@ impl SKESK { /// Gets the version. pub fn version(&self) -> u8 { match self { - &SKESK::V4(_) => 4, - &SKESK::V5(_) => 5, + SKESK::V4(_) => 4, + SKESK::V5(_) => 5, } } } diff --git a/openpgp/src/packet/skesk.rs b/openpgp/src/packet/skesk.rs index 65ecdc11..026c3c1a 100644 --- a/openpgp/src/packet/skesk.rs +++ b/openpgp/src/packet/skesk.rs @@ -30,8 +30,8 @@ impl SKESK { -> Result<(SymmetricAlgorithm, SessionKey)> { match self { - &SKESK::V4(ref s) => s.decrypt(password), - &SKESK::V5(ref s) => s.decrypt(password), + SKESK::V4(ref s) => s.decrypt(password), + SKESK::V5(ref s) => s.decrypt(password), } } } diff --git a/openpgp/src/packet/tag.rs b/openpgp/src/packet/tag.rs index 5b10f437..c15c51c4 100644 --- a/openpgp/src/packet/tag.rs +++ b/openpgp/src/packet/tag.rs @@ -131,27 +131,27 @@ impl From for u8 { impl From<&Tag> for u8 { fn from(t: &Tag) -> u8 { match t { - &Tag::Reserved => 0, - &Tag::PKESK => 1, - &Tag::Signature => 2, - &Tag::SKESK => 3, - &Tag::OnePassSig => 4, - &Tag::SecretKey => 5, - &Tag::PublicKey => 6, - &Tag::SecretSubkey => 7, - &Tag::CompressedData => 8, - &Tag::SED => 9, - &Tag::Marker => 10, - &Tag::Literal => 11, - &Tag::Trust => 12, - &Tag::UserID => 13, - &Tag::PublicSubkey => 14, - &Tag::UserAttribute => 17, - &Tag::SEIP => 18, - &Tag::MDC => 19, - &Tag::AED => 20, - &Tag::Private(x) => x, - &Tag::Unknown(x) => x, + Tag::Reserved => 0, + Tag::PKESK => 1, + Tag::Signature => 2, + Tag::SKESK => 3, + Tag::OnePassSig => 4, + Tag::SecretKey => 5, + Tag::PublicKey => 6, + Tag::SecretSubkey => 7, + Tag::CompressedData => 8, + Tag::SED => 9, + Tag::Marker => 10, + Tag::Literal => 11, + Tag::Trust => 12, + Tag::UserID => 13, + Tag::PublicSubkey => 14, + Tag::UserAttribute => 17, + Tag::SEIP => 18, + Tag::MDC => 19, + Tag::AED => 20, + Tag::Private(x) => *x, + Tag::Unknown(x) => *x, } } } diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index fbb5cfff..803813e8 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -1447,8 +1447,8 @@ impl Signature4 { // The absolute minimum size for the header is 11 bytes (this // doesn't include the signature MPIs). - if let &BodyLength::Full(len) = header.length() { - if len < 11 { + if let BodyLength::Full(len) = header.length() { + if *len < 11 { // Much too short. return Err( Error::MalformedPacket("Packet too short".into()).into()); @@ -2290,8 +2290,8 @@ impl Key4 bio: &mut buffered_reader::Dup, header: &Header) -> Result<()> { // The packet's header is 6 bytes. - if let &BodyLength::Full(len) = header.length() { - if len < 6 { + if let BodyLength::Full(len) = header.length() { + if *len < 6 { // Much too short. return Err(Error::MalformedPacket( format!("Packet too short ({} bytes)", len)).into()); @@ -2402,7 +2402,8 @@ impl Marker { -> Result<()> where T: BufferedReader, { - if let &BodyLength::Full(len) = header.length() { + if let BodyLength::Full(len) = header.length() { + let len = *len; if len as usize != Marker::BODY.len() { return Err(Error::MalformedPacket( format!("Unexpected packet length {}", len)).into()); @@ -4342,9 +4343,9 @@ impl <'a> PacketParser<'a> { Tag::Literal | Tag::CompressedData | Tag::SED | Tag::SEIP | Tag::AED => (), _ => match header.length() { - &BodyLength::Full(l) => if l > max_size { + BodyLength::Full(l) => if *l > max_size { header_syntax_error = Some( - Error::PacketTooLarge(tag, l, max_size).into()); + Error::PacketTooLarge(tag, *l, max_size).into()); }, _ => unreachable!("non-data packets have full length, \ syntax check above"), diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs index 64c13b86..e0034018 100644 --- a/openpgp/src/serialize.rs +++ b/openpgp/src/serialize.rs @@ -648,7 +648,8 @@ impl Marshal for BodyLength { /// [`serialize_old(..)`]: BodyLength::serialize_old() fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> { match self { - &BodyLength::Full(l) => { + BodyLength::Full(l) => { + let l = *l; if l <= 191 { write_byte(o, l as u8)?; } else if l <= 8383 { @@ -660,7 +661,8 @@ impl Marshal for BodyLength { write_be_u32(o, l)?; } }, - &BodyLength::Partial(l) => { + BodyLength::Partial(l) => { + let l = *l; if l > 1 << 30 { return Err(Error::InvalidArgument( format!("Partial length too large: {}", l)).into()); @@ -678,7 +680,7 @@ impl Marshal for BodyLength { assert!(size_byte < 255); write_byte(o, size_byte as u8)?; }, - &BodyLength::Indeterminate => + BodyLength::Indeterminate => return Err(Error::InvalidArgument( "Indeterminate lengths are not support for new format packets". into()).into()), @@ -691,7 +693,8 @@ impl Marshal for BodyLength { impl MarshalInto for BodyLength { fn serialized_len(&self) -> usize { match self { - &BodyLength::Full(l) => { + BodyLength::Full(l) => { + let l = *l; if l <= 191 { 1 } else if l <= 8383 { @@ -700,8 +703,8 @@ impl MarshalInto for BodyLength { 5 } }, - &BodyLength::Partial(_) => 1, - &BodyLength::Indeterminate => 0, + BodyLength::Partial(_) => 1, + BodyLength::Indeterminate => 0, } } @@ -727,7 +730,8 @@ impl BodyLength { // Assume an optimal encoding is desired. let mut buffer = Vec::with_capacity(4); match self { - &BodyLength::Full(l) => { + BodyLength::Full(l) => { + let l = *l; match l { // One octet length. // write_byte can't fail for a Vec. @@ -741,8 +745,8 @@ impl BodyLength { write_be_u32(&mut buffer, l as u32).unwrap(), } }, - &BodyLength::Indeterminate => {}, - &BodyLength::Partial(_) => + BodyLength::Indeterminate => {}, + BodyLength::Partial(_) => return Err(Error::InvalidArgument( "Partial body lengths are not support for old format packets". into()).into()), @@ -792,8 +796,8 @@ impl seal::Sealed for CTB {} impl Marshal for CTB { fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> { match self { - &CTB::New(ref c) => c.serialize(o), - &CTB::Old(ref c) => c.serialize(o), + CTB::New(ref c) => c.serialize(o), + CTB::Old(ref c) => c.serialize(o), }?; Ok(()) } @@ -831,8 +835,8 @@ impl seal::Sealed for KeyID {} impl Marshal for KeyID { fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> { let raw = match self { - &KeyID::V4(ref fp) => &fp[..], - &KeyID::Invalid(ref fp) => &fp[..], + KeyID::V4(ref fp) => &fp[..], + KeyID::Invalid(ref fp) => &fp[..], }; o.write_all(raw)?; Ok(()) @@ -843,8 +847,8 @@ impl SerializeInto for KeyID {} impl MarshalInto for KeyID { fn serialized_len(&self) -> usize { match self { - &KeyID::V4(_) => 8, - &KeyID::Invalid(ref fp) => fp.len(), + KeyID::V4(_) => 8, + KeyID::Invalid(ref fp) => fp.len(), } } @@ -933,41 +937,41 @@ impl Marshal for crypto::mpi::PublicKey { use crate::crypto::mpi::PublicKey::*; match self { - &RSA { ref e, ref n } => { + RSA { ref e, ref n } => { n.serialize(w)?; e.serialize(w)?; } - &DSA { ref p, ref q, ref g, ref y } => { + DSA { ref p, ref q, ref g, ref y } => { p.serialize(w)?; q.serialize(w)?; g.serialize(w)?; y.serialize(w)?; } - &ElGamal { ref p, ref g, ref y } => { + ElGamal { ref p, ref g, ref y } => { p.serialize(w)?; g.serialize(w)?; y.serialize(w)?; } - &EdDSA { ref curve, ref q } => { + EdDSA { ref curve, ref q } => { write_field_with_u8_size(w, "Curve's OID", curve.oid())?; q.serialize(w)?; } - &ECDSA { ref curve, ref q } => { + ECDSA { ref curve, ref q } => { write_field_with_u8_size(w, "Curve's OID", curve.oid())?; q.serialize(w)?; } - &ECDH { ref curve, ref q, hash, sym } => { + ECDH { ref curve, ref q, hash, sym } => { write_field_with_u8_size(w, "Curve's OID", curve.oid())?; q.serialize(w)?; - w.write_all(&[3u8, 1u8, u8::from(hash), u8::from(sym)])?; + w.write_all(&[3u8, 1u8, u8::from(*hash), u8::from(*sym)])?; } - &Unknown { ref mpis, ref rest } => { + Unknown { ref mpis, ref rest } => { for mpi in mpis.iter() { mpi.serialize(w)?; } @@ -983,32 +987,32 @@ impl MarshalInto for crypto::mpi::PublicKey { fn serialized_len(&self) -> usize { use crate::crypto::mpi::PublicKey::*; match self { - &RSA { ref e, ref n } => { + RSA { ref e, ref n } => { n.serialized_len() + e.serialized_len() } - &DSA { ref p, ref q, ref g, ref y } => { + DSA { ref p, ref q, ref g, ref y } => { p.serialized_len() + q.serialized_len() + g.serialized_len() + y.serialized_len() } - &ElGamal { ref p, ref g, ref y } => { + ElGamal { ref p, ref g, ref y } => { p.serialized_len() + g.serialized_len() + y.serialized_len() } - &EdDSA { ref curve, ref q } => { + EdDSA { ref curve, ref q } => { 1 + curve.oid().len() + q.serialized_len() } - &ECDSA { ref curve, ref q } => { + ECDSA { ref curve, ref q } => { 1 + curve.oid().len() + q.serialized_len() } - &ECDH { ref curve, ref q, hash: _, sym: _ } => { + ECDH { ref curve, ref q, hash: _, sym: _ } => { 1 + curve.oid().len() + q.serialized_len() + 4 } - &Unknown { ref mpis, ref rest } => { + Unknown { ref mpis, ref rest } => { mpis.iter().map(|mpi| mpi.serialized_len()).sum::() + rest.len() } @@ -1026,34 +1030,34 @@ impl Marshal for crypto::mpi::SecretKeyMaterial { use crate::crypto::mpi::SecretKeyMaterial::*; match self { - &RSA{ ref d, ref p, ref q, ref u } => { + RSA{ ref d, ref p, ref q, ref u } => { d.serialize(w)?; p.serialize(w)?; q.serialize(w)?; u.serialize(w)?; } - &DSA{ ref x } => { + DSA{ ref x } => { x.serialize(w)?; } - &ElGamal{ ref x } => { + ElGamal{ ref x } => { x.serialize(w)?; } - &EdDSA{ ref scalar } => { + EdDSA{ ref scalar } => { scalar.serialize(w)?; } - &ECDSA{ ref scalar } => { + ECDSA{ ref scalar } => { scalar.serialize(w)?; } - &ECDH{ ref scalar } => { + ECDH{ ref scalar } => { scalar.serialize(w)?; } - &Unknown { ref mpis, ref rest } => { + Unknown { ref mpis, ref rest } => { for mpi in mpis.iter() { mpi.serialize(w)?; } @@ -1069,32 +1073,32 @@ impl MarshalInto for crypto::mpi::SecretKeyMaterial { fn serialized_len(&self) -> usize { use crate::crypto::mpi::SecretKeyMaterial::*; match self { - &RSA{ ref d, ref p, ref q, ref u } => { + RSA{ ref d, ref p, ref q, ref u } => { d.serialized_len() + p.serialized_len() + q.serialized_len() + u.serialized_len() } - &DSA{ ref x } => { + DSA{ ref x } => { x.serialized_len() } - &ElGamal{ ref x } => { + ElGamal{ ref x } => { x.serialized_len() } - &EdDSA{ ref scalar } => { + EdDSA{ ref scalar } => { scalar.serialized_len() } - &ECDSA{ ref scalar } => { + ECDSA{ ref scalar } => { scalar.serialized_len() } - &ECDH{ ref scalar } => { + ECDH{ ref scalar } => { scalar.serialized_len() } - &Unknown { ref mpis, ref rest } => { + Unknown { ref mpis, ref rest } => { mpis.iter().map(|mpi| mpi.serialized_len()).sum::() + rest.len() } @@ -1142,21 +1146,21 @@ impl Marshal for crypto::mpi::Ciphertext { use crate::crypto::mpi::Ciphertext::*; match self { - &RSA{ ref c } => { + RSA{ ref c } => { c.serialize(w)?; } - &ElGamal{ ref e, ref c } => { + ElGamal{ ref e, ref c } => { e.serialize(w)?; c.serialize(w)?; } - &ECDH{ ref e, ref key } => { + ECDH{ ref e, ref key } => { e.serialize(w)?; write_field_with_u8_size(w, "Key", key)?; } - &Unknown { ref mpis, ref rest } => { + Unknown { ref mpis, ref rest } => { for mpi in mpis.iter() { mpi.serialize(w)?; } @@ -1172,19 +1176,19 @@ impl MarshalInto for crypto::mpi::Ciphertext { fn serialized_len(&self) -> usize { use crate::crypto::mpi::Ciphertext::*; match self { - &RSA{ ref c } => { + RSA{ ref c } => { c.serialized_len() } - &ElGamal{ ref e, ref c } => { + ElGamal{ ref e, ref c } => { e.serialized_len() + c.serialized_len() } - &ECDH{ ref e, ref key } => { + ECDH{ ref e, ref key } => { e.serialized_len() + 1 + key.len() } - &Unknown { ref mpis, ref rest } => { + Unknown { ref mpis, ref rest } => { mpis.iter().map(|mpi| mpi.serialized_len()).sum::() + rest.len() } @@ -1202,27 +1206,27 @@ impl Marshal for crypto::mpi::Signature { use crate::crypto::mpi::Signature::*; match self { - &RSA { ref s } => { + RSA { ref s } => { s.serialize(w)?; } - &DSA { ref r, ref s } => { + DSA { ref r, ref s } => { r.serialize(w)?; s.serialize(w)?; } - &ElGamal { ref r, ref s } => { + ElGamal { ref r, ref s } => { r.serialize(w)?; s.serialize(w)?; } - &EdDSA { ref r, ref s } => { + EdDSA { ref r, ref s } => { r.serialize(w)?; s.serialize(w)?; } - &ECDSA { ref r, ref s } => { + ECDSA { ref r, ref s } => { r.serialize(w)?; s.serialize(w)?; } - &Unknown { ref mpis, ref rest } => { + Unknown { ref mpis, ref rest } => { for mpi in mpis.iter() { mpi.serialize(w)?; } @@ -1238,23 +1242,23 @@ impl MarshalInto for crypto::mpi::Signature { fn serialized_len(&self) -> usize { use crate::crypto::mpi::Signature::*; match self { - &RSA { ref s } => { + RSA { ref s } => { s.serialized_len() } - &DSA { ref r, ref s } => { + DSA { ref r, ref s } => { r.serialized_len() + s.serialized_len() } - &ElGamal { ref r, ref s } => { + ElGamal { ref r, ref s } => { r.serialized_len() + s.serialized_len() } - &EdDSA { ref r, ref s } => { + EdDSA { ref r, ref s } => { r.serialized_len() + s.serialized_len() } - &ECDSA { ref r, ref s } => { + ECDSA { ref r, ref s } => { r.serialized_len() + s.serialized_len() } - &Unknown { ref mpis, ref rest } => { + Unknown { ref mpis, ref rest } => { mpis.iter().map(|mpi| mpi.serialized_len()).sum::() + rest.len() } @@ -1590,13 +1594,13 @@ impl seal::Sealed for Signature {} impl Marshal for Signature { fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> { match self { - &Signature::V4(ref s) => s.serialize(o), + Signature::V4(ref s) => s.serialize(o), } } fn export(&self, o: &mut dyn std::io::Write) -> Result<()> { match self { - &Signature::V4(ref s) => s.export(o), + Signature::V4(ref s) => s.export(o), } } } @@ -1604,25 +1608,25 @@ impl Marshal for Signature { impl MarshalInto for Signature { fn serialized_len(&self) -> usize { match self { - &Signature::V4(ref s) => s.serialized_len(), + Signature::V4(ref s) => s.serialized_len(), } } fn serialize_into(&self, buf: &mut [u8]) -> Result { match self { - &Signature::V4(ref s) => s.serialize_into(buf), + Signature::V4(ref s) => s.serialize_into(buf), } } fn export_into(&self, buf: &mut [u8]) -> Result { match self { - &Signature::V4(ref s) => s.export_into(buf), + Signature::V4(ref s) => s.export_into(buf), } } fn export_to_vec(&self) -> Result> { match self { - &Signature::V4(ref s) => s.export_to_vec(), + Signature::V4(ref s) => s.export_to_vec(), } } } @@ -1714,7 +1718,7 @@ impl seal::Sealed for OnePassSig {} impl Marshal for OnePassSig { fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> { match self { - &OnePassSig::V3(ref s) => s.serialize(o), + OnePassSig::V3(ref s) => s.serialize(o), } } } @@ -1722,13 +1726,13 @@ impl Marshal for OnePassSig { impl MarshalInto for OnePassSig { fn serialized_len(&self) -> usize { match self { - &OnePassSig::V3(ref s) => s.serialized_len(), + OnePassSig::V3(ref s) => s.serialized_len(), } } fn serialize_into(&self, buf: &mut [u8]) -> Result { match self { - &OnePassSig::V3(ref s) => s.serialize_into(buf), + OnePassSig::V3(ref s) => s.serialize_into(buf), } } } @@ -1772,7 +1776,7 @@ impl seal::Sealed for Key {} impl Marshal for Key { fn serialize(&self, o: &mut dyn io::Write) -> Result<()> { match self { - &Key::V4(ref p) => p.serialize(o), + Key::V4(ref p) => p.serialize(o), } } } @@ -1780,13 +1784,13 @@ impl Marshal for Key { impl MarshalInto for Key { fn serialized_len(&self) -> usize { match self { - &Key::V4(ref p) => p.serialized_len(), + Key::V4(ref p) => p.serialized_len(), } } fn serialize_into(&self, buf: &mut [u8]) -> Result { match self { - &Key::V4(ref p) => p.serialize_into(buf), + Key::V4(ref p) => p.serialize_into(buf), } } } @@ -2244,7 +2248,7 @@ impl seal::Sealed for PKESK {} impl Marshal for PKESK { fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> { match self { - &PKESK::V3(ref p) => p.serialize(o), + PKESK::V3(ref p) => p.serialize(o), } } } @@ -2252,7 +2256,7 @@ impl Marshal for PKESK { impl MarshalInto for PKESK { fn serialized_len(&self) -> usize { match self { - &PKESK::V3(ref p) => p.serialized_len(), + PKESK::V3(ref p) => p.serialized_len(), } } @@ -2299,8 +2303,8 @@ impl seal::Sealed for SKESK {} impl Marshal for SKESK { fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> { match self { - &SKESK::V4(ref s) => s.serialize(o), - &SKESK::V5(ref s) => s.serialize(o), + SKESK::V4(ref s) => s.serialize(o), + SKESK::V5(ref s) => s.serialize(o), } } } @@ -2308,8 +2312,8 @@ impl Marshal for SKESK { impl NetLength for SKESK { fn net_len(&self) -> usize { match self { - &SKESK::V4(ref s) => s.net_len(), - &SKESK::V5(ref s) => s.net_len(), + SKESK::V4(ref s) => s.net_len(), + SKESK::V5(ref s) => s.net_len(), } } } @@ -2317,8 +2321,8 @@ impl NetLength for SKESK { impl MarshalInto for SKESK { fn serialized_len(&self) -> usize { match self { - &SKESK::V4(ref s) => s.serialized_len(), - &SKESK::V5(ref s) => s.serialized_len(), + SKESK::V4(ref s) => s.serialized_len(), + SKESK::V5(ref s) => s.serialized_len(), } } @@ -2472,7 +2476,7 @@ impl seal::Sealed for AED {} impl Marshal for AED { fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> { match self { - &AED::V1(ref p) => p.serialize(o), + AED::V1(ref p) => p.serialize(o), } } } @@ -2480,13 +2484,13 @@ impl Marshal for AED { impl MarshalInto for AED { fn serialized_len(&self) -> usize { match self { - &AED::V1(ref p) => p.serialized_len(), + AED::V1(ref p) => p.serialized_len(), } } fn serialize_into(&self, buf: &mut [u8]) -> Result { match self { - &AED::V1(ref p) => p.serialize_into(buf), + AED::V1(ref p) => p.serialize_into(buf), } } } @@ -2572,24 +2576,24 @@ impl Marshal for Packet { BodyLength::Full(self.net_len() as u32).serialize(o)?; match self { - &Packet::Unknown(ref p) => p.serialize(o), - &Packet::Signature(ref p) => p.serialize(o), - &Packet::OnePassSig(ref p) => p.serialize(o), - &Packet::PublicKey(ref p) => p.serialize(o), - &Packet::PublicSubkey(ref p) => p.serialize(o), - &Packet::SecretKey(ref p) => p.serialize(o), - &Packet::SecretSubkey(ref p) => p.serialize(o), - &Packet::Marker(ref p) => p.serialize(o), - &Packet::Trust(ref p) => p.serialize(o), - &Packet::UserID(ref p) => p.serialize(o), - &Packet::UserAttribute(ref p) => p.serialize(o), - &Packet::Literal(ref p) => p.serialize(o), - &Packet::CompressedData(_) => unreachable!("handled above"), - &Packet::PKESK(ref p) => p.serialize(o), - &Packet::SKESK(ref p) => p.serialize(o), - &Packet::SEIP(ref p) => p.serialize(o), - &Packet::MDC(ref p) => p.serialize(o), - &Packet::AED(ref p) => p.serialize(o), + Packet::Unknown(ref p) => p.serialize(o), + Packet::Signature(ref p) => p.serialize(o), + Packet::OnePassSig(ref p) => p.serialize(o), + Packet::PublicKey(ref p) => p.serialize(o), + Packet::PublicSubkey(ref p) => p.serialize(o), + Packet::SecretKey(ref p) => p.serialize(o), + Packet::SecretSubkey(ref p) => p.serialize(o), + Packet::Marker(ref p) => p.serialize(o), + Packet::Trust(ref p) => p.serialize(o), + Packet::UserID(ref p) => p.serialize(o), + Packet::UserAttribute(ref p) => p.serialize(o), + Packet::Literal(ref p) => p.serialize(o), + Packet::CompressedData(_) => unreachable!("handled above"), + Packet::PKESK(ref p) => p.serialize(o), + Packet::SKESK(ref p) => p.serialize(o), + Packet::SEIP(ref p) => p.serialize(o), + Packet::MDC(ref p) => p.serialize(o), + Packet::AED(ref p) => p.serialize(o), } } @@ -2613,24 +2617,24 @@ impl Marshal for Packet { BodyLength::Full(self.net_len() as u32).export(o)?; match self { - &Packet::Unknown(ref p) => p.export(o), - &Packet::Signature(ref p) => p.export(o), - &Packet::OnePassSig(ref p) => p.export(o), - &Packet::PublicKey(ref p) => p.export(o), - &Packet::PublicSubkey(ref p) => p.export(o), - &Packet::SecretKey(ref p) => p.export(o), - &Packet::SecretSubkey(ref p) => p.export(o), - &Packet::Marker(ref p) => p.export(o), - &Packet::Trust(ref p) => p.export(o), - &Packet::UserID(ref p) => p.export(o), - &Packet::UserAttribute(ref p) => p.export(o), - &Packet::Literal(ref p) => p.export(o), - &Packet::CompressedData(_) => unreachable!("handled above"), - &Packet::PKESK(ref p) => p.export(o), - &Packet::SKESK(ref p) => p.export(o), - &Packet::SEIP(ref p) => p.export(o), - &Packet::MDC(ref p) => p.export(o), - &Packet::AED(ref p) => p.export(o), + Packet::Unknown(ref p) => p.export(o), + Packet::Signature(ref p) => p.export(o), + Packet::OnePassSig(ref p) => p.export(o), + Packet::PublicKey(ref p) => p.export(o), + Packet::PublicSubkey(ref p) => p.export(o), + Packet::SecretKey(ref p) => p.export(o), + Packet::SecretSubkey(ref p) => p.export(o), + Packet::Marker(ref p) => p.export(o), + Packet::Trust(ref p) => p.export(o),