From 74b0cc0da723b73e2695f0025236a9cbcb410e29 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 27 Mar 2023 11:59:56 +0200 Subject: [PATCH] Fix lints --- boring-sys/build.rs | 2 +- boring/src/asn1.rs | 1 + boring/src/base64.rs | 6 +++--- boring/src/ec.rs | 1 + boring/src/error.rs | 1 + boring/src/hash.rs | 2 +- boring/src/rsa.rs | 2 ++ boring/src/ssl/mod.rs | 2 +- boring/src/ssl/test/mod.rs | 16 ++++++++-------- boring/src/stack.rs | 2 +- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/boring-sys/build.rs b/boring-sys/build.rs index 5a9e1d5f..c6e1de7e 100644 --- a/boring-sys/build.rs +++ b/boring-sys/build.rs @@ -332,7 +332,7 @@ fn main() { println!("cargo:warning=fetching boringssl git submodule"); // fetch the boringssl submodule let status = Command::new("git") - .args(&[ + .args([ "submodule", "update", "--init", diff --git a/boring/src/asn1.rs b/boring/src/asn1.rs index 3ab1aede..e9b3d43d 100644 --- a/boring/src/asn1.rs +++ b/boring/src/asn1.rs @@ -399,6 +399,7 @@ impl Asn1Integer { } impl Asn1IntegerRef { + #[allow(clippy::unnecessary_cast)] #[allow(missing_docs)] #[deprecated(since = "0.10.6", note = "use to_bn instead")] pub fn get(&self) -> i64 { diff --git a/boring/src/base64.rs b/boring/src/base64.rs index 1426fdc0..2e9ef17d 100644 --- a/boring/src/base64.rs +++ b/boring/src/base64.rs @@ -18,7 +18,7 @@ pub fn encode_block(src: &[u8]) -> String { let src_len = src.len(); let len = encoded_len(src_len).unwrap(); - let mut out = Vec::with_capacity(len as usize); + let mut out = Vec::with_capacity(len); // SAFETY: `encoded_len` ensures space for 4 output characters // for every 3 input bytes including padding and nul terminator. @@ -26,7 +26,7 @@ pub fn encode_block(src: &[u8]) -> String { // `EVP_EncodeBlock` will only write to not read from `out`. unsafe { let out_len = ffi::EVP_EncodeBlock(out.as_mut_ptr(), src.as_ptr(), src_len); - out.set_len(out_len as usize); + out.set_len(out_len); String::from_utf8_unchecked(out) } } @@ -52,7 +52,7 @@ pub fn decode_block(src: &str) -> Result, ErrorStack> { let src_len = src.len(); let len = decoded_len(src_len).unwrap(); - let mut out = Vec::with_capacity(len as usize); + let mut out = Vec::with_capacity(len); // SAFETY: `decoded_len` ensures space for 3 output bytes // for every 4 input characters including padding. diff --git a/boring/src/ec.rs b/boring/src/ec.rs index 5738344e..9c80b2de 100644 --- a/boring/src/ec.rs +++ b/boring/src/ec.rs @@ -174,6 +174,7 @@ impl EcGroupRef { /// OpenSSL documentation at [`EC_GROUP_get_degree`] /// /// [`EC_GROUP_get_degree`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_GROUP_get_degree.html + #[allow(clippy::unnecessary_cast)] pub fn degree(&self) -> u32 { unsafe { ffi::EC_GROUP_get_degree(self.as_ptr()) as u32 } } diff --git a/boring/src/error.rs b/boring/src/error.rs index 8a09dd61..fdc3ba9e 100644 --- a/boring/src/error.rs +++ b/boring/src/error.rs @@ -216,6 +216,7 @@ impl Error { } /// Returns the line in the source file which encountered the error. + #[allow(clippy::unnecessary_cast)] pub fn line(&self) -> u32 { self.line as u32 } diff --git a/boring/src/hash.rs b/boring/src/hash.rs index aa84b520..011fa54b 100644 --- a/boring/src/hash.rs +++ b/boring/src/hash.rs @@ -72,7 +72,7 @@ impl MessageDigest { /// The size of the digest in bytes. #[allow(clippy::trivially_copy_pass_by_ref)] pub fn size(&self) -> usize { - unsafe { ffi::EVP_MD_size(self.0) as usize } + unsafe { ffi::EVP_MD_size(self.0) } } /// The name of the digest. diff --git a/boring/src/rsa.rs b/boring/src/rsa.rs index 01f460ff..c17b36a3 100644 --- a/boring/src/rsa.rs +++ b/boring/src/rsa.rs @@ -296,6 +296,7 @@ where /// This corresponds to [`RSA_check_key`]. /// /// [`RSA_check_key`]: https://www.openssl.org/docs/man1.1.0/crypto/RSA_check_key.html + #[allow(clippy::unnecessary_cast)] pub fn check_key(&self) -> Result { unsafe { let result = ffi::RSA_check_key(self.as_ptr()) as i32; @@ -361,6 +362,7 @@ where /// This corresponds to [`RSA_size`]. /// /// [`RSA_size`]: https://www.openssl.org/docs/man1.1.0/crypto/RSA_size.html + #[allow(clippy::unnecessary_cast)] pub fn size(&self) -> u32 { unsafe { ffi::RSA_size(self.as_ptr()) as u32 } } diff --git a/boring/src/ssl/mod.rs b/boring/src/ssl/mod.rs index c382375d..8ccc1d15 100644 --- a/boring/src/ssl/mod.rs +++ b/boring/src/ssl/mod.rs @@ -2746,7 +2746,7 @@ impl SslRef { if len == 0 { None } else { - Some(slice::from_raw_parts(p as *const u8, len as usize)) + Some(slice::from_raw_parts(p as *const u8, len)) } } } diff --git a/boring/src/ssl/test/mod.rs b/boring/src/ssl/test/mod.rs index 5066a2e6..200ced24 100644 --- a/boring/src/ssl/test/mod.rs +++ b/boring/src/ssl/test/mod.rs @@ -199,7 +199,7 @@ fn verify_callback() { CALLED_BACK.store(true, Ordering::SeqCst); let cert = x509.current_cert().unwrap(); let digest = cert.digest(MessageDigest::sha1()).unwrap(); - assert_eq!(hex::encode(&digest), expected); + assert_eq!(hex::encode(digest), expected); true }); @@ -221,7 +221,7 @@ fn ssl_verify_callback() { CALLED_BACK.store(true, Ordering::SeqCst); let cert = x509.current_cert().unwrap(); let digest = cert.digest(MessageDigest::sha1()).unwrap(); - assert_eq!(hex::encode(&digest), expected); + assert_eq!(hex::encode(digest), expected); true }); @@ -311,9 +311,9 @@ fn test_connect_with_srtp_ctx() { let mut ctx = SslContext::builder(SslMethod::dtls()).unwrap(); ctx.set_tlsext_use_srtp("SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32") .unwrap(); - ctx.set_certificate_file(&Path::new("test/cert.pem"), SslFiletype::PEM) + ctx.set_certificate_file(Path::new("test/cert.pem"), SslFiletype::PEM) .unwrap(); - ctx.set_private_key_file(&Path::new("test/key.pem"), SslFiletype::PEM) + ctx.set_private_key_file(Path::new("test/key.pem"), SslFiletype::PEM) .unwrap(); let mut ssl = Ssl::new(&ctx.build()).unwrap(); ssl.set_mtu(1500).unwrap(); @@ -367,9 +367,9 @@ fn test_connect_with_srtp_ssl() { let guard = thread::spawn(move || { let stream = listener.accept().unwrap().0; let mut ctx = SslContext::builder(SslMethod::dtls()).unwrap(); - ctx.set_certificate_file(&Path::new("test/cert.pem"), SslFiletype::PEM) + ctx.set_certificate_file(Path::new("test/cert.pem"), SslFiletype::PEM) .unwrap(); - ctx.set_private_key_file(&Path::new("test/key.pem"), SslFiletype::PEM) + ctx.set_private_key_file(Path::new("test/key.pem"), SslFiletype::PEM) .unwrap(); let mut ssl = Ssl::new(&ctx.build()).unwrap(); ssl.set_tlsext_use_srtp("SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32") @@ -988,9 +988,9 @@ fn keying_export() { let guard = thread::spawn(move || { let stream = listener.accept().unwrap().0; let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); - ctx.set_certificate_file(&Path::new("test/cert.pem"), SslFiletype::PEM) + ctx.set_certificate_file(Path::new("test/cert.pem"), SslFiletype::PEM) .unwrap(); - ctx.set_private_key_file(&Path::new("test/key.pem"), SslFiletype::PEM) + ctx.set_private_key_file(Path::new("test/key.pem"), SslFiletype::PEM) .unwrap(); let ssl = Ssl::new(&ctx.build()).unwrap(); let mut stream = ssl.accept(stream).unwrap(); diff --git a/boring/src/stack.rs b/boring/src/stack.rs index 812bf52d..67b95273 100644 --- a/boring/src/stack.rs +++ b/boring/src/stack.rs @@ -181,7 +181,7 @@ impl StackRef { /// Returns the number of items in the stack. pub fn len(&self) -> usize { - unsafe { OPENSSL_sk_num(self.as_stack()) as usize } + unsafe { OPENSSL_sk_num(self.as_stack()) } } /// Determines if the stack is empty.