Merge pull request #116 from nox/clippy

Fix all clippy lints
This commit is contained in:
Ivan Nikulin 2023-05-05 09:44:30 +01:00 committed by GitHub
commit 4ce9c50b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 22 additions and 18 deletions

View File

@ -179,7 +179,7 @@ jobs:
test-fips: test-fips:
name: Test FIPS integration name: Test FIPS integration
runs-on: ubuntu-latest runs-on: ubuntu-20.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:

View File

@ -332,7 +332,7 @@ fn main() {
println!("cargo:warning=fetching boringssl git submodule"); println!("cargo:warning=fetching boringssl git submodule");
// fetch the boringssl submodule // fetch the boringssl submodule
let status = Command::new("git") let status = Command::new("git")
.args(&[ .args([
"submodule", "submodule",
"update", "update",
"--init", "--init",

View File

@ -399,6 +399,7 @@ impl Asn1Integer {
} }
impl Asn1IntegerRef { impl Asn1IntegerRef {
#[allow(clippy::unnecessary_cast)]
#[allow(missing_docs)] #[allow(missing_docs)]
#[deprecated(since = "0.10.6", note = "use to_bn instead")] #[deprecated(since = "0.10.6", note = "use to_bn instead")]
pub fn get(&self) -> i64 { pub fn get(&self) -> i64 {

View File

@ -18,7 +18,7 @@ pub fn encode_block(src: &[u8]) -> String {
let src_len = src.len(); let src_len = src.len();
let len = encoded_len(src_len).unwrap(); 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 // SAFETY: `encoded_len` ensures space for 4 output characters
// for every 3 input bytes including padding and nul terminator. // 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`. // `EVP_EncodeBlock` will only write to not read from `out`.
unsafe { unsafe {
let out_len = ffi::EVP_EncodeBlock(out.as_mut_ptr(), src.as_ptr(), src_len); 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) String::from_utf8_unchecked(out)
} }
} }
@ -52,7 +52,7 @@ pub fn decode_block(src: &str) -> Result<Vec<u8>, ErrorStack> {
let src_len = src.len(); let src_len = src.len();
let len = decoded_len(src_len).unwrap(); 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 // SAFETY: `decoded_len` ensures space for 3 output bytes
// for every 4 input characters including padding. // for every 4 input characters including padding.

View File

@ -174,6 +174,7 @@ impl EcGroupRef {
/// OpenSSL documentation at [`EC_GROUP_get_degree`] /// 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 /// [`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 { pub fn degree(&self) -> u32 {
unsafe { ffi::EC_GROUP_get_degree(self.as_ptr()) as u32 } unsafe { ffi::EC_GROUP_get_degree(self.as_ptr()) as u32 }
} }

View File

@ -216,6 +216,7 @@ impl Error {
} }
/// Returns the line in the source file which encountered the error. /// Returns the line in the source file which encountered the error.
#[allow(clippy::unnecessary_cast)]
pub fn line(&self) -> u32 { pub fn line(&self) -> u32 {
self.line as u32 self.line as u32
} }

View File

@ -72,7 +72,7 @@ impl MessageDigest {
/// The size of the digest in bytes. /// The size of the digest in bytes.
#[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::trivially_copy_pass_by_ref)]
pub fn size(&self) -> usize { 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. /// The name of the digest.

View File

@ -296,6 +296,7 @@ where
/// This corresponds to [`RSA_check_key`]. /// This corresponds to [`RSA_check_key`].
/// ///
/// [`RSA_check_key`]: https://www.openssl.org/docs/man1.1.0/crypto/RSA_check_key.html /// [`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<bool, ErrorStack> { pub fn check_key(&self) -> Result<bool, ErrorStack> {
unsafe { unsafe {
let result = ffi::RSA_check_key(self.as_ptr()) as i32; let result = ffi::RSA_check_key(self.as_ptr()) as i32;
@ -361,6 +362,7 @@ where
/// This corresponds to [`RSA_size`]. /// This corresponds to [`RSA_size`].
/// ///
/// [`RSA_size`]: https://www.openssl.org/docs/man1.1.0/crypto/RSA_size.html /// [`RSA_size`]: https://www.openssl.org/docs/man1.1.0/crypto/RSA_size.html
#[allow(clippy::unnecessary_cast)]
pub fn size(&self) -> u32 { pub fn size(&self) -> u32 {
unsafe { ffi::RSA_size(self.as_ptr()) as u32 } unsafe { ffi::RSA_size(self.as_ptr()) as u32 }
} }

View File

@ -2746,7 +2746,7 @@ impl SslRef {
if len == 0 { if len == 0 {
None None
} else { } else {
Some(slice::from_raw_parts(p as *const u8, len as usize)) Some(slice::from_raw_parts(p as *const u8, len))
} }
} }
} }

View File

@ -199,7 +199,7 @@ fn verify_callback() {
CALLED_BACK.store(true, Ordering::SeqCst); CALLED_BACK.store(true, Ordering::SeqCst);
let cert = x509.current_cert().unwrap(); let cert = x509.current_cert().unwrap();
let digest = cert.digest(MessageDigest::sha1()).unwrap(); let digest = cert.digest(MessageDigest::sha1()).unwrap();
assert_eq!(hex::encode(&digest), expected); assert_eq!(hex::encode(digest), expected);
true true
}); });
@ -221,7 +221,7 @@ fn ssl_verify_callback() {
CALLED_BACK.store(true, Ordering::SeqCst); CALLED_BACK.store(true, Ordering::SeqCst);
let cert = x509.current_cert().unwrap(); let cert = x509.current_cert().unwrap();
let digest = cert.digest(MessageDigest::sha1()).unwrap(); let digest = cert.digest(MessageDigest::sha1()).unwrap();
assert_eq!(hex::encode(&digest), expected); assert_eq!(hex::encode(digest), expected);
true true
}); });
@ -311,9 +311,9 @@ fn test_connect_with_srtp_ctx() {
let mut ctx = SslContext::builder(SslMethod::dtls()).unwrap(); let mut ctx = SslContext::builder(SslMethod::dtls()).unwrap();
ctx.set_tlsext_use_srtp("SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32") ctx.set_tlsext_use_srtp("SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32")
.unwrap(); .unwrap();
ctx.set_certificate_file(&Path::new("test/cert.pem"), SslFiletype::PEM) ctx.set_certificate_file(Path::new("test/cert.pem"), SslFiletype::PEM)
.unwrap(); .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(); .unwrap();
let mut ssl = Ssl::new(&ctx.build()).unwrap(); let mut ssl = Ssl::new(&ctx.build()).unwrap();
ssl.set_mtu(1500).unwrap(); ssl.set_mtu(1500).unwrap();
@ -367,9 +367,9 @@ fn test_connect_with_srtp_ssl() {
let guard = thread::spawn(move || { let guard = thread::spawn(move || {
let stream = listener.accept().unwrap().0; let stream = listener.accept().unwrap().0;
let mut ctx = SslContext::builder(SslMethod::dtls()).unwrap(); 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(); .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(); .unwrap();
let mut ssl = Ssl::new(&ctx.build()).unwrap(); let mut ssl = Ssl::new(&ctx.build()).unwrap();
ssl.set_tlsext_use_srtp("SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32") 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 guard = thread::spawn(move || {
let stream = listener.accept().unwrap().0; let stream = listener.accept().unwrap().0;
let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); 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(); .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(); .unwrap();
let ssl = Ssl::new(&ctx.build()).unwrap(); let ssl = Ssl::new(&ctx.build()).unwrap();
let mut stream = ssl.accept(stream).unwrap(); let mut stream = ssl.accept(stream).unwrap();

View File

@ -181,7 +181,7 @@ impl<T: Stackable> StackRef<T> {
/// Returns the number of items in the stack. /// Returns the number of items in the stack.
pub fn len(&self) -> usize { 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. /// Determines if the stack is empty.

View File

@ -19,8 +19,7 @@ async fn google() {
let resp = client let resp = client
.get("https://www.google.com".parse().unwrap()) .get("https://www.google.com".parse().unwrap())
.await .await
.unwrap(); .expect("connection should succeed");
assert!(resp.status().is_success(), "{}", resp.status());
let mut body = resp.into_body(); let mut body = resp.into_body();
while body.next().await.transpose().unwrap().is_some() {} while body.next().await.transpose().unwrap().is_some() {}
} }