This commit is contained in:
Kornel 2025-05-20 15:46:11 +01:00 committed by Kornel
parent bcec9462af
commit 4d178a7f9f
20 changed files with 80 additions and 79 deletions

View File

@ -152,9 +152,9 @@ impl Env {
let kind = if host == target { "HOST" } else { "TARGET" }; let kind = if host == target { "HOST" } else { "TARGET" };
// TODO(rmehra): look for just `name` first, as most people just set that // TODO(rmehra): look for just `name` first, as most people just set that
var(&format!("{}_{}", name, target)) var(&format!("{name}_{target}"))
.or_else(|| var(&format!("{}_{}", name, target_with_underscores))) .or_else(|| var(&format!("{name}_{target_with_underscores}")))
.or_else(|| var(&format!("{}_{}", kind, name))) .or_else(|| var(&format!("{kind}_{name}")))
.or_else(|| var(name)) .or_else(|| var(name))
}; };

View File

@ -165,7 +165,7 @@ fn get_boringssl_platform_output_path(config: &Config) -> String {
let deb_info = match debug_env_var.to_str() { let deb_info = match debug_env_var.to_str() {
Some("false") => false, Some("false") => false,
Some("true") => true, Some("true") => true,
_ => panic!("Unknown DEBUG={:?} env var.", debug_env_var), _ => panic!("Unknown DEBUG={debug_env_var:?} env var."),
}; };
let opt_env_var = config let opt_env_var = config
@ -184,12 +184,12 @@ fn get_boringssl_platform_output_path(config: &Config) -> String {
} }
} }
Some("s" | "z") => "MinSizeRel", Some("s" | "z") => "MinSizeRel",
_ => panic!("Unknown OPT_LEVEL={:?} env var.", opt_env_var), _ => panic!("Unknown OPT_LEVEL={opt_env_var:?} env var."),
}; };
subdir.to_string() subdir.to_string()
} else { } else {
"".to_string() String::new()
} }
} }
@ -242,7 +242,7 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
} }
let toolchain_file = android_ndk_home.join("build/cmake/android.toolchain.cmake"); let toolchain_file = android_ndk_home.join("build/cmake/android.toolchain.cmake");
let toolchain_file = toolchain_file.to_str().unwrap(); let toolchain_file = toolchain_file.to_str().unwrap();
eprintln!("android toolchain={}", toolchain_file); eprintln!("android toolchain={toolchain_file}");
boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file); boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file);
// 21 is the minimum level tested. You can give higher value. // 21 is the minimum level tested. You can give higher value.
@ -273,7 +273,7 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
"" ""
}; };
let cflag = format!("{} {}", bitcode_cflag, target_cflag); let cflag = format!("{bitcode_cflag} {target_cflag}");
boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag); boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag);
boringssl_cmake.cflag(&cflag); boringssl_cmake.cflag(&cflag);
} }
@ -339,7 +339,7 @@ fn verify_fips_clang_version() -> (&'static str, &'static str) {
let output = match Command::new(tool).arg("--version").output() { let output = match Command::new(tool).arg("--version").output() {
Ok(o) => o, Ok(o) => o,
Err(e) => { Err(e) => {
eprintln!("warning: missing {}, trying other compilers: {}", tool, e); eprintln!("warning: missing {tool}, trying other compilers: {e}");
// NOTE: hard-codes that the loop below checks the version // NOTE: hard-codes that the loop below checks the version
return None; return None;
} }
@ -369,13 +369,11 @@ fn verify_fips_clang_version() -> (&'static str, &'static str) {
return (cc, cxx); return (cc, cxx);
} else if cc == "cc" { } else if cc == "cc" {
panic!( panic!(
"unsupported clang version \"{}\": FIPS requires clang {}", "unsupported clang version \"{cc_version}\": FIPS requires clang {REQUIRED_CLANG_VERSION}"
cc_version, REQUIRED_CLANG_VERSION
); );
} else if !cc_version.is_empty() { } else if !cc_version.is_empty() {
eprintln!( eprintln!(
"warning: FIPS requires clang version {}, skipping incompatible version \"{}\"", "warning: FIPS requires clang version {REQUIRED_CLANG_VERSION}, skipping incompatible version \"{cc_version}\""
REQUIRED_CLANG_VERSION, cc_version
); );
} }
} }
@ -425,7 +423,7 @@ fn get_extra_clang_args_for_bindgen(config: &Config) -> Vec<String> {
.unwrap(); .unwrap();
if !output.status.success() { if !output.status.success() {
if let Some(exit_code) = output.status.code() { if let Some(exit_code) = output.status.code() {
eprintln!("xcrun failed: exit code {}", exit_code); eprintln!("xcrun failed: exit code {exit_code}");
} else { } else {
eprintln!("xcrun failed: killed"); eprintln!("xcrun failed: killed");
} }
@ -452,8 +450,7 @@ fn get_extra_clang_args_for_bindgen(config: &Config) -> Vec<String> {
Ok(toolchain) => toolchain, Ok(toolchain) => toolchain,
Err(e) => { Err(e) => {
eprintln!( eprintln!(
"warning: failed to find prebuilt Android NDK toolchain for bindgen: {}", "warning: failed to find prebuilt Android NDK toolchain for bindgen: {e}"
e
); );
// Uh... let's try anyway, I guess? // Uh... let's try anyway, I guess?
return params; return params;
@ -537,8 +534,8 @@ fn run_command(command: &mut Command) -> io::Result<Output> {
if !out.status.success() { if !out.status.success() {
let err = match out.status.code() { let err = match out.status.code() {
Some(code) => format!("{:?} exited with status: {}", command, code), Some(code) => format!("{command:?} exited with status: {code}"),
None => format!("{:?} was terminated by signal", command), None => format!("{command:?} was terminated by signal"),
}; };
return Err(io::Error::other(err)); return Err(io::Error::other(err));
@ -696,7 +693,7 @@ fn main() {
} }
if let Some(cpp_lib) = get_cpp_runtime_lib(&config) { if let Some(cpp_lib) = get_cpp_runtime_lib(&config) {
println!("cargo:rustc-link-lib={}", cpp_lib); println!("cargo:rustc-link-lib={cpp_lib}");
} }
println!("cargo:rustc-link-lib=static=crypto"); println!("cargo:rustc-link-lib=static=crypto");
println!("cargo:rustc-link-lib=static=ssl"); println!("cargo:rustc-link-lib=static=ssl");

View File

@ -146,7 +146,7 @@ fn real_main() -> Result<(), ErrorStack> {
// Verify that this cert was issued by this ca // Verify that this cert was issued by this ca
match ca_cert.issued(&cert) { match ca_cert.issued(&cert) {
Ok(()) => println!("Certificate verified!"), Ok(()) => println!("Certificate verified!"),
Err(ver_err) => println!("Failed to verify certificate: {}", ver_err), Err(ver_err) => println!("Failed to verify certificate: {ver_err}"),
}; };
Ok(()) Ok(())
@ -155,6 +155,6 @@ fn real_main() -> Result<(), ErrorStack> {
fn main() { fn main() {
match real_main() { match real_main() {
Ok(()) => println!("Finished."), Ok(()) => println!("Finished."),
Err(e) => println!("Error: {}", e), Err(e) => println!("Error: {e}"),
}; };
} }

View File

@ -304,7 +304,8 @@ impl Asn1Time {
/// Creates a new time on specified interval in days from now /// Creates a new time on specified interval in days from now
pub fn days_from_now(days: u32) -> Result<Asn1Time, ErrorStack> { pub fn days_from_now(days: u32) -> Result<Asn1Time, ErrorStack> {
Asn1Time::from_period(days as c_long * 60 * 60 * 24) // the type varies between platforms, so both into() and try_into() trigger Clippy lints
Self::from_period((days * 60 * 60 * 24) as _)
} }
/// Creates a new time from the specified `time_t` value /// Creates a new time from the specified `time_t` value
@ -494,7 +495,13 @@ impl Asn1IntegerRef {
/// [`bn`]: ../bn/struct.BigNumRef.html#method.to_asn1_integer /// [`bn`]: ../bn/struct.BigNumRef.html#method.to_asn1_integer
#[corresponds(ASN1_INTEGER_set)] #[corresponds(ASN1_INTEGER_set)]
pub fn set(&mut self, value: i32) -> Result<(), ErrorStack> { pub fn set(&mut self, value: i32) -> Result<(), ErrorStack> {
unsafe { cvt(crate::ffi::ASN1_INTEGER_set(self.as_ptr(), value as c_long)).map(|_| ()) } unsafe {
cvt(crate::ffi::ASN1_INTEGER_set(
self.as_ptr(),
c_long::from(value),
))
.map(|_| ())
}
} }
} }

View File

@ -101,7 +101,7 @@ mod tests {
#[test] #[test]
fn test_encode_block() { fn test_encode_block() {
assert_eq!("".to_string(), encode_block(b"")); assert_eq!(String::new(), encode_block(b""));
assert_eq!("Zg==".to_string(), encode_block(b"f")); assert_eq!("Zg==".to_string(), encode_block(b"f"));
assert_eq!("Zm8=".to_string(), encode_block(b"fo")); assert_eq!("Zm8=".to_string(), encode_block(b"fo"));
assert_eq!("Zm9v".to_string(), encode_block(b"foo")); assert_eq!("Zm9v".to_string(), encode_block(b"foo"));

View File

@ -121,19 +121,19 @@ impl BigNumRef {
/// Adds a `u32` to `self`. /// Adds a `u32` to `self`.
#[corresponds(BN_add_word)] #[corresponds(BN_add_word)]
pub fn add_word(&mut self, w: u32) -> Result<(), ErrorStack> { pub fn add_word(&mut self, w: u32) -> Result<(), ErrorStack> {
unsafe { cvt(ffi::BN_add_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) } unsafe { cvt(ffi::BN_add_word(self.as_ptr(), ffi::BN_ULONG::from(w))).map(|_| ()) }
} }
/// Subtracts a `u32` from `self`. /// Subtracts a `u32` from `self`.
#[corresponds(BN_sub_word)] #[corresponds(BN_sub_word)]
pub fn sub_word(&mut self, w: u32) -> Result<(), ErrorStack> { pub fn sub_word(&mut self, w: u32) -> Result<(), ErrorStack> {
unsafe { cvt(ffi::BN_sub_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) } unsafe { cvt(ffi::BN_sub_word(self.as_ptr(), ffi::BN_ULONG::from(w))).map(|_| ()) }
} }
/// Multiplies a `u32` by `self`. /// Multiplies a `u32` by `self`.
#[corresponds(BN_mul_word)] #[corresponds(BN_mul_word)]
pub fn mul_word(&mut self, w: u32) -> Result<(), ErrorStack> { pub fn mul_word(&mut self, w: u32) -> Result<(), ErrorStack> {
unsafe { cvt(ffi::BN_mul_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) } unsafe { cvt(ffi::BN_mul_word(self.as_ptr(), ffi::BN_ULONG::from(w))).map(|_| ()) }
} }
/// Divides `self` by a `u32`, returning the remainder. /// Divides `self` by a `u32`, returning the remainder.
@ -263,7 +263,7 @@ impl BigNumRef {
/// `self` positive. /// `self` positive.
#[corresponds(BN_set_negative)] #[corresponds(BN_set_negative)]
pub fn set_negative(&mut self, negative: bool) { pub fn set_negative(&mut self, negative: bool) {
unsafe { ffi::BN_set_negative(self.as_ptr(), negative as c_int) } unsafe { ffi::BN_set_negative(self.as_ptr(), c_int::from(negative)) }
} }
/// Compare the absolute values of `self` and `oth`. /// Compare the absolute values of `self` and `oth`.
@ -332,7 +332,7 @@ impl BigNumRef {
self.as_ptr(), self.as_ptr(),
bits.into(), bits.into(),
msb.0, msb.0,
odd as c_int, c_int::from(odd),
)) ))
.map(|_| ()) .map(|_| ())
} }
@ -347,7 +347,7 @@ impl BigNumRef {
self.as_ptr(), self.as_ptr(),
bits.into(), bits.into(),
msb.0, msb.0,
odd as c_int, c_int::from(odd),
)) ))
.map(|_| ()) .map(|_| ())
} }
@ -388,7 +388,7 @@ impl BigNumRef {
cvt(ffi::BN_generate_prime_ex( cvt(ffi::BN_generate_prime_ex(
self.as_ptr(), self.as_ptr(),
bits as c_int, bits as c_int,
safe as c_int, c_int::from(safe),
add.map(|n| n.as_ptr()).unwrap_or(ptr::null_mut()), add.map(|n| n.as_ptr()).unwrap_or(ptr::null_mut()),
rem.map(|n| n.as_ptr()).unwrap_or(ptr::null_mut()), rem.map(|n| n.as_ptr()).unwrap_or(ptr::null_mut()),
ptr::null_mut(), ptr::null_mut(),
@ -712,7 +712,7 @@ impl BigNumRef {
self.as_ptr(), self.as_ptr(),
checks.into(), checks.into(),
ctx.as_ptr(), ctx.as_ptr(),
do_trial_division as c_int, c_int::from(do_trial_division),
ptr::null_mut(), ptr::null_mut(),
)) ))
.map(|r| r != 0) .map(|r| r != 0)
@ -829,7 +829,7 @@ impl BigNum {
#[corresponds(BN_set_word)] #[corresponds(BN_set_word)]
pub fn from_u32(n: u32) -> Result<BigNum, ErrorStack> { pub fn from_u32(n: u32) -> Result<BigNum, ErrorStack> {
BigNum::new().and_then(|v| unsafe { BigNum::new().and_then(|v| unsafe {
cvt(ffi::BN_set_word(v.as_ptr(), n as ffi::BN_ULONG)).map(|_| v) cvt(ffi::BN_set_word(v.as_ptr(), ffi::BN_ULONG::from(n))).map(|_| v)
}) })
} }
@ -928,7 +928,7 @@ impl PartialEq<BigNumRef> for BigNumRef {
impl PartialEq<BigNum> for BigNumRef { impl PartialEq<BigNum> for BigNumRef {
fn eq(&self, oth: &BigNum) -> bool { fn eq(&self, oth: &BigNum) -> bool {
self.eq(oth.deref()) self.eq(&**oth)
} }
} }
@ -956,7 +956,7 @@ impl PartialOrd<BigNumRef> for BigNumRef {
impl PartialOrd<BigNum> for BigNumRef { impl PartialOrd<BigNum> for BigNumRef {
fn partial_cmp(&self, oth: &BigNum) -> Option<Ordering> { fn partial_cmp(&self, oth: &BigNum) -> Option<Ordering> {
Some(self.cmp(oth.deref())) Some(self.cmp(&**oth))
} }
} }
@ -980,7 +980,7 @@ impl PartialOrd<BigNumRef> for BigNum {
impl Ord for BigNum { impl Ord for BigNum {
fn cmp(&self, oth: &BigNum) -> Ordering { fn cmp(&self, oth: &BigNum) -> Ordering {
self.deref().cmp(oth.deref()) self.deref().cmp(&**oth)
} }
} }

View File

@ -308,7 +308,7 @@ impl DerefMut for DigestBytes {
impl AsRef<[u8]> for DigestBytes { impl AsRef<[u8]> for DigestBytes {
#[inline] #[inline]
fn as_ref(&self) -> &[u8] { fn as_ref(&self) -> &[u8] {
self.deref() self
} }
} }
@ -455,7 +455,7 @@ mod tests {
#[test] #[test]
fn test_md5() { fn test_md5() {
for test in MD5_TESTS.iter() { for test in &MD5_TESTS {
hash_test(MessageDigest::md5(), test); hash_test(MessageDigest::md5(), test);
} }
} }
@ -463,7 +463,7 @@ mod tests {
#[test] #[test]
fn test_md5_recycle() { fn test_md5_recycle() {
let mut h = Hasher::new(MessageDigest::md5()).unwrap(); let mut h = Hasher::new(MessageDigest::md5()).unwrap();
for test in MD5_TESTS.iter() { for test in &MD5_TESTS {
hash_recycle_test(&mut h, test); hash_recycle_test(&mut h, test);
} }
} }
@ -514,7 +514,7 @@ mod tests {
fn test_sha1() { fn test_sha1() {
let tests = [("616263", "a9993e364706816aba3e25717850c26c9cd0d89d")]; let tests = [("616263", "a9993e364706816aba3e25717850c26c9cd0d89d")];
for test in tests.iter() { for test in &tests {
hash_test(MessageDigest::sha1(), test); hash_test(MessageDigest::sha1(), test);
} }
} }
@ -526,7 +526,7 @@ mod tests {
"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7",
)]; )];
for test in tests.iter() { for test in &tests {
hash_test(MessageDigest::sha224(), test); hash_test(MessageDigest::sha224(), test);
} }
} }
@ -538,7 +538,7 @@ mod tests {
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
)]; )];
for test in tests.iter() { for test in &tests {
hash_test(MessageDigest::sha256(), test); hash_test(MessageDigest::sha256(), test);
} }
} }
@ -551,7 +551,7 @@ mod tests {
192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f", 192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
)]; )];
for test in tests.iter() { for test in &tests {
hash_test(MessageDigest::sha512(), test); hash_test(MessageDigest::sha512(), test);
} }
} }
@ -563,7 +563,7 @@ mod tests {
"53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23", "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23",
)]; )];
for test in tests.iter() { for test in &tests {
hash_test(MessageDigest::sha512_256(), test); hash_test(MessageDigest::sha512_256(), test);
} }
} }

View File

@ -143,7 +143,7 @@ where
to: &mut [u8], to: &mut [u8],
padding: Padding, padding: Padding,
) -> Result<usize, ErrorStack> { ) -> Result<usize, ErrorStack> {
assert!(from.len() <= i32::MAX as usize); assert!(i32::try_from(from.len()).is_ok());
assert!(to.len() >= self.size() as usize); assert!(to.len() >= self.size() as usize);
unsafe { unsafe {
@ -170,7 +170,7 @@ where
to: &mut [u8], to: &mut [u8],
padding: Padding, padding: Padding,
) -> Result<usize, ErrorStack> { ) -> Result<usize, ErrorStack> {
assert!(from.len() <= i32::MAX as usize); assert!(i32::try_from(from.len()).is_ok());
assert!(to.len() >= self.size() as usize); assert!(to.len() >= self.size() as usize);
unsafe { unsafe {
@ -334,7 +334,7 @@ where
to: &mut [u8], to: &mut [u8],
padding: Padding, padding: Padding,
) -> Result<usize, ErrorStack> { ) -> Result<usize, ErrorStack> {
assert!(from.len() <= i32::MAX as usize); assert!(i32::try_from(from.len()).is_ok());
assert!(to.len() >= self.size() as usize); assert!(to.len() >= self.size() as usize);
unsafe { unsafe {
@ -360,7 +360,7 @@ where
to: &mut [u8], to: &mut [u8],
padding: Padding, padding: Padding,
) -> Result<usize, ErrorStack> { ) -> Result<usize, ErrorStack> {
assert!(from.len() <= i32::MAX as usize); assert!(i32::try_from(from.len()).is_ok());
assert!(to.len() >= self.size() as usize); assert!(to.len() >= self.size() as usize);
unsafe { unsafe {

View File

@ -85,10 +85,7 @@ pub unsafe extern "C" fn take_stream<S>(bio: *mut BIO) -> S {
pub unsafe fn set_dtls_mtu_size<S>(bio: *mut BIO, mtu_size: usize) { pub unsafe fn set_dtls_mtu_size<S>(bio: *mut BIO, mtu_size: usize) {
if mtu_size as u64 > c_long::MAX as u64 { if mtu_size as u64 > c_long::MAX as u64 {
panic!( panic!("Given MTU size {mtu_size} can't be represented in a positive `c_long` range")
"Given MTU size {} can't be represented in a positive `c_long` range",
mtu_size
)
} }
state::<S>(bio).dtls_mtu_size = mtu_size as c_long; state::<S>(bio).dtls_mtu_size = mtu_size as c_long;
} }

View File

@ -40,7 +40,7 @@ where
// because there is no `X509StoreContextRef::ssl_mut(&mut self)` method. // because there is no `X509StoreContextRef::ssl_mut(&mut self)` method.
let verify = unsafe { &*(verify as *const F) }; let verify = unsafe { &*(verify as *const F) };
verify(preverify_ok != 0, ctx) as c_int c_int::from(verify(preverify_ok != 0, ctx))
} }
pub(super) unsafe extern "C" fn raw_custom_verify<F>( pub(super) unsafe extern "C" fn raw_custom_verify<F>(
@ -89,7 +89,7 @@ where
// so the callback can't replace itself. // so the callback can't replace itself.
let verify = unsafe { &*(verify as *const F) }; let verify = unsafe { &*(verify as *const F) };
verify(ctx) as c_int c_int::from(verify(ctx))
} }
pub(super) unsafe extern "C" fn ssl_raw_custom_verify<F>( pub(super) unsafe extern "C" fn ssl_raw_custom_verify<F>(
@ -235,7 +235,7 @@ where
.expect("BUG: ssl verify callback missing") .expect("BUG: ssl verify callback missing")
.clone(); .clone();
callback(preverify_ok != 0, ctx) as c_int c_int::from(callback(preverify_ok != 0, ctx))
} }
pub(super) unsafe extern "C" fn raw_sni<F>( pub(super) unsafe extern "C" fn raw_sni<F>(

View File

@ -35,7 +35,7 @@ impl SslEchKeysBuilder {
unsafe { unsafe {
cvt_0i(ffi::SSL_ECH_KEYS_add( cvt_0i(ffi::SSL_ECH_KEYS_add(
self.keys.as_ptr(), self.keys.as_ptr(),
is_retry_config as c_int, c_int::from(is_retry_config),
ech_config.as_ptr(), ech_config.as_ptr(),
ech_config.len(), ech_config.len(),
key.as_ptr(), key.as_ptr(),

View File

@ -136,14 +136,14 @@ impl fmt::Display for Error {
None => fmt.write_str("the operation should be retried"), None => fmt.write_str("the operation should be retried"),
}, },
ErrorCode::SYSCALL => match self.io_error() { ErrorCode::SYSCALL => match self.io_error() {
Some(err) => write!(fmt, "{}", err), Some(err) => write!(fmt, "{err}"),
None => fmt.write_str("unexpected EOF"), None => fmt.write_str("unexpected EOF"),
}, },
ErrorCode::SSL => match self.ssl_error() { ErrorCode::SSL => match self.ssl_error() {
Some(e) => write!(fmt, "{}", e), Some(e) => write!(fmt, "{e}"),
None => fmt.write_str("unknown BoringSSL error"), None => fmt.write_str("unknown BoringSSL error"),
}, },
ErrorCode(code) => write!(fmt, "unknown error code {}", code), ErrorCode(code) => write!(fmt, "unknown error code {code}"),
} }
} }
} }
@ -185,7 +185,7 @@ impl<S> fmt::Display for HandshakeError<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
HandshakeError::SetupFailure(ref e) => { HandshakeError::SetupFailure(ref e) => {
write!(f, "TLS stream setup failed {}", e) write!(f, "TLS stream setup failed {e}")
} }
HandshakeError::Failure(ref s) => fmt_mid_handshake_error(s, f, "TLS handshake failed"), HandshakeError::Failure(ref s) => fmt_mid_handshake_error(s, f, "TLS handshake failed"),
HandshakeError::WouldBlock(ref s) => { HandshakeError::WouldBlock(ref s) => {
@ -209,8 +209,8 @@ fn fmt_mid_handshake_error(
match s.ssl().verify_result() { match s.ssl().verify_result() {
// INVALID_CALL is returned if no verification took place, // INVALID_CALL is returned if no verification took place,
// such as before a cert is sent. // such as before a cert is sent.
Ok(()) | Err(X509VerifyError::INVALID_CALL) => write!(f, "{}", prefix)?, Ok(()) | Err(X509VerifyError::INVALID_CALL) => write!(f, "{prefix}")?,
Err(verify) => write!(f, "{}: cert verification failed - {}", prefix, verify)?, Err(verify) => write!(f, "{prefix}: cert verification failed - {verify}")?,
} }
write!(f, " {}", s.error()) write!(f, " {}", s.error())

View File

@ -593,7 +593,7 @@ impl TryFrom<u16> for SslVersion {
type Error = &'static str; type Error = &'static str;
fn try_from(value: u16) -> Result<Self, Self::Error> { fn try_from(value: u16) -> Result<Self, Self::Error> {
match value as i32 { match i32::from(value) {
ffi::SSL3_VERSION ffi::SSL3_VERSION
| ffi::TLS1_VERSION | ffi::TLS1_VERSION
| ffi::TLS1_1_VERSION | ffi::TLS1_1_VERSION
@ -908,7 +908,7 @@ impl SslInfoCallbackAlert {
/// The value of the SSL alert. /// The value of the SSL alert.
pub fn alert(&self) -> SslAlert { pub fn alert(&self) -> SslAlert {
let value = self.0 & (u8::MAX as i32); let value = self.0 & i32::from(u8::MAX);
SslAlert(value) SslAlert(value)
} }
} }
@ -1226,7 +1226,7 @@ impl SslContextBuilder {
#[corresponds(SSL_CTX_set_read_ahead)] #[corresponds(SSL_CTX_set_read_ahead)]
pub fn set_read_ahead(&mut self, read_ahead: bool) { pub fn set_read_ahead(&mut self, read_ahead: bool) {
unsafe { unsafe {
ffi::SSL_CTX_set_read_ahead(self.as_ptr(), read_ahead as c_int); ffi::SSL_CTX_set_read_ahead(self.as_ptr(), c_int::from(read_ahead));
} }
} }

View File

@ -341,7 +341,7 @@ impl Crypter {
} }
iv.as_ptr() as *mut _ iv.as_ptr() as *mut _
} }
(Some(_), None) | (None, None) => ptr::null_mut(), (Some(_) | None, None) => ptr::null_mut(),
(None, Some(_)) => panic!("an IV is required for this cipher"), (None, Some(_)) => panic!("an IV is required for this cipher"),
}; };
cvt(ffi::EVP_CipherInit_ex( cvt(ffi::EVP_CipherInit_ex(
@ -363,7 +363,7 @@ impl Crypter {
/// be a multiple of the cipher's block size. /// be a multiple of the cipher's block size.
pub fn pad(&mut self, padding: bool) { pub fn pad(&mut self, padding: bool) {
unsafe { unsafe {
ffi::EVP_CIPHER_CTX_set_padding(self.ctx, padding as c_int); ffi::EVP_CIPHER_CTX_set_padding(self.ctx, c_int::from(padding));
} }
} }

View File

@ -78,7 +78,7 @@ impl BasicConstraints {
value.push_str("FALSE"); value.push_str("FALSE");
} }
if let Some(pathlen) = self.pathlen { if let Some(pathlen) = self.pathlen {
write!(value, ",pathlen:{}", pathlen).unwrap(); write!(value, ",pathlen:{pathlen}").unwrap();
} }
X509Extension::new_nid(None, None, Nid::BASIC_CONSTRAINTS, &value) X509Extension::new_nid(None, None, Nid::BASIC_CONSTRAINTS, &value)
} }

View File

@ -1516,7 +1516,7 @@ impl X509VerifyError {
ffi::init(); ffi::init();
unsafe { unsafe {
let s = ffi::X509_verify_cert_error_string(self.0 as c_long); let s = ffi::X509_verify_cert_error_string(c_long::from(self.0));
str::from_utf8(CStr::from_ptr(s).to_bytes()).unwrap() str::from_utf8(CStr::from_ptr(s).to_bytes()).unwrap()
} }
} }

View File

@ -37,7 +37,7 @@ fn test_cert_loading() {
fn test_debug() { fn test_debug() {
let cert = include_bytes!("../../../test/cert.pem"); let cert = include_bytes!("../../../test/cert.pem");
let cert = X509::from_pem(cert).unwrap(); let cert = X509::from_pem(cert).unwrap();
let debugged = format!("{:#?}", cert); let debugged = format!("{cert:#?}");
assert!(debugged.contains(r#"serial_number: "8771f7bdee982fa5""#)); assert!(debugged.contains(r#"serial_number: "8771f7bdee982fa5""#));
assert!(debugged.contains(r#"signature_algorithm: sha256WithRSAEncryption"#)); assert!(debugged.contains(r#"signature_algorithm: sha256WithRSAEncryption"#));
@ -497,7 +497,7 @@ fn test_save_subject_der() {
let cert = X509::from_pem(cert).unwrap(); let cert = X509::from_pem(cert).unwrap();
let der = cert.subject_name().to_der().unwrap(); let der = cert.subject_name().to_der().unwrap();
println!("der: {:?}", der); println!("der: {der:?}");
assert!(!der.is_empty()); assert!(!der.is_empty());
} }

View File

@ -259,10 +259,10 @@ where
let last = host.len() - 1; let last = host.len() - 1;
let mut chars = host.chars(); let mut chars = host.chars();
if let (Some('['), Some(']')) = (chars.next(), chars.last()) { if (chars.next(), chars.last()) == (Some('['), Some(']'))
if host[1..last].parse::<net::Ipv6Addr>().is_ok() { && host[1..last].parse::<net::Ipv6Addr>().is_ok()
host = &host[1..last]; {
} host = &host[1..last];
} }
} }

View File

@ -76,7 +76,7 @@ async fn localhost() {
let file = File::create("../target/keyfile.log").unwrap(); let file = File::create("../target/keyfile.log").unwrap();
ssl.set_keylog_callback(move |_, line| { ssl.set_keylog_callback(move |_, line| {
let _ = writeln!(&file, "{}", line); let _ = writeln!(&file, "{line}");
}); });
let ssl = HttpsConnector::with_connector(connector, ssl).unwrap(); let ssl = HttpsConnector::with_connector(connector, ssl).unwrap();
@ -84,7 +84,7 @@ async fn localhost() {
for _ in 0..3 { for _ in 0..3 {
let resp = client let resp = client
.get(format!("https://foobar.com:{}", port).parse().unwrap()) .get(format!("https://foobar.com:{port}").parse().unwrap())
.await .await
.unwrap(); .unwrap();
assert!(resp.status().is_success(), "{}", resp.status()); assert!(resp.status().is_success(), "{}", resp.status());
@ -147,7 +147,7 @@ async fn alpn_h2() {
let client = Client::builder().build::<_, Body>(ssl); let client = Client::builder().build::<_, Body>(ssl);
let resp = client let resp = client
.get(format!("https://foobar.com:{}", port).parse().unwrap()) .get(format!("https://foobar.com:{port}").parse().unwrap())
.await .await
.unwrap(); .unwrap();
assert!(resp.status().is_success(), "{}", resp.status()); assert!(resp.status().is_success(), "{}", resp.status());

View File

@ -234,7 +234,7 @@ where
fn poll_shutdown(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll<io::Result<()>> { fn poll_shutdown(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll<io::Result<()>> {
match self.run_in_context(ctx, |s| s.shutdown()) { match self.run_in_context(ctx, |s| s.shutdown()) {
Ok(ShutdownResult::Sent) | Ok(ShutdownResult::Received) => {} Ok(ShutdownResult::Sent | ShutdownResult::Received) => {}
Err(ref e) if e.code() == ErrorCode::ZERO_RETURN => {} Err(ref e) if e.code() == ErrorCode::ZERO_RETURN => {}
Err(ref e) if e.code() == ErrorCode::WANT_READ || e.code() == ErrorCode::WANT_WRITE => { Err(ref e) if e.code() == ErrorCode::WANT_READ || e.code() == ErrorCode::WANT_WRITE => {
return Poll::Pending; return Poll::Pending;