Skip to content

Commit f146c54

Browse files
committed
Clippy
1 parent 05f798a commit f146c54

File tree

20 files changed

+80
-79
lines changed

20 files changed

+80
-79
lines changed

boring-sys/build/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ impl Env {
152152
let kind = if host == target { "HOST" } else { "TARGET" };
153153

154154
// TODO(rmehra): look for just `name` first, as most people just set that
155-
var(&format!("{}_{}", name, target))
156-
.or_else(|| var(&format!("{}_{}", name, target_with_underscores)))
157-
.or_else(|| var(&format!("{}_{}", kind, name)))
155+
var(&format!("{name}_{target}"))
156+
.or_else(|| var(&format!("{name}_{target_with_underscores}")))
157+
.or_else(|| var(&format!("{kind}_{name}")))
158158
.or_else(|| var(name))
159159
};
160160

boring-sys/build/main.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn get_boringssl_platform_output_path(config: &Config) -> String {
165165
let deb_info = match debug_env_var.to_str() {
166166
Some("false") => false,
167167
Some("true") => true,
168-
_ => panic!("Unknown DEBUG={:?} env var.", debug_env_var),
168+
_ => panic!("Unknown DEBUG={debug_env_var:?} env var."),
169169
};
170170

171171
let opt_env_var = config
@@ -184,12 +184,12 @@ fn get_boringssl_platform_output_path(config: &Config) -> String {
184184
}
185185
}
186186
Some("s" | "z") => "MinSizeRel",
187-
_ => panic!("Unknown OPT_LEVEL={:?} env var.", opt_env_var),
187+
_ => panic!("Unknown OPT_LEVEL={opt_env_var:?} env var."),
188188
};
189189

190190
subdir.to_string()
191191
} else {
192-
"".to_string()
192+
String::new()
193193
}
194194
}
195195

@@ -242,7 +242,7 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
242242
}
243243
let toolchain_file = android_ndk_home.join("build/cmake/android.toolchain.cmake");
244244
let toolchain_file = toolchain_file.to_str().unwrap();
245-
eprintln!("android toolchain={}", toolchain_file);
245+
eprintln!("android toolchain={toolchain_file}");
246246
boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file);
247247

248248
// 21 is the minimum level tested. You can give higher value.
@@ -273,7 +273,7 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
273273
""
274274
};
275275

276-
let cflag = format!("{} {}", bitcode_cflag, target_cflag);
276+
let cflag = format!("{bitcode_cflag} {target_cflag}");
277277
boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag);
278278
boringssl_cmake.cflag(&cflag);
279279
}
@@ -339,7 +339,7 @@ fn verify_fips_clang_version() -> (&'static str, &'static str) {
339339
let output = match Command::new(tool).arg("--version").output() {
340340
Ok(o) => o,
341341
Err(e) => {
342-
eprintln!("warning: missing {}, trying other compilers: {}", tool, e);
342+
eprintln!("warning: missing {tool}, trying other compilers: {e}");
343343
// NOTE: hard-codes that the loop below checks the version
344344
return None;
345345
}
@@ -369,13 +369,11 @@ fn verify_fips_clang_version() -> (&'static str, &'static str) {
369369
return (cc, cxx);
370370
} else if cc == "cc" {
371371
panic!(
372-
"unsupported clang version \"{}\": FIPS requires clang {}",
373-
cc_version, REQUIRED_CLANG_VERSION
372+
"unsupported clang version \"{cc_version}\": FIPS requires clang {REQUIRED_CLANG_VERSION}"
374373
);
375374
} else if !cc_version.is_empty() {
376375
eprintln!(
377-
"warning: FIPS requires clang version {}, skipping incompatible version \"{}\"",
378-
REQUIRED_CLANG_VERSION, cc_version
376+
"warning: FIPS requires clang version {REQUIRED_CLANG_VERSION}, skipping incompatible version \"{cc_version}\""
379377
);
380378
}
381379
}
@@ -425,7 +423,7 @@ fn get_extra_clang_args_for_bindgen(config: &Config) -> Vec<String> {
425423
.unwrap();
426424
if !output.status.success() {
427425
if let Some(exit_code) = output.status.code() {
428-
eprintln!("xcrun failed: exit code {}", exit_code);
426+
eprintln!("xcrun failed: exit code {exit_code}");
429427
} else {
430428
eprintln!("xcrun failed: killed");
431429
}
@@ -452,8 +450,7 @@ fn get_extra_clang_args_for_bindgen(config: &Config) -> Vec<String> {
452450
Ok(toolchain) => toolchain,
453451
Err(e) => {
454452
eprintln!(
455-
"warning: failed to find prebuilt Android NDK toolchain for bindgen: {}",
456-
e
453+
"warning: failed to find prebuilt Android NDK toolchain for bindgen: {e}"
457454
);
458455
// Uh... let's try anyway, I guess?
459456
return params;
@@ -537,8 +534,8 @@ fn run_command(command: &mut Command) -> io::Result<Output> {
537534

538535
if !out.status.success() {
539536
let err = match out.status.code() {
540-
Some(code) => format!("{:?} exited with status: {}", command, code),
541-
None => format!("{:?} was terminated by signal", command),
537+
Some(code) => format!("{command:?} exited with status: {code}"),
538+
None => format!("{command:?} was terminated by signal"),
542539
};
543540

544541
return Err(io::Error::other(err));
@@ -696,7 +693,7 @@ fn main() {
696693
}
697694

698695
if let Some(cpp_lib) = get_cpp_runtime_lib(&config) {
699-
println!("cargo:rustc-link-lib={}", cpp_lib);
696+
println!("cargo:rustc-link-lib={cpp_lib}");
700697
}
701698
println!("cargo:rustc-link-lib=static=crypto");
702699
println!("cargo:rustc-link-lib=static=ssl");

boring/examples/mk_certs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn real_main() -> Result<(), ErrorStack> {
146146
// Verify that this cert was issued by this ca
147147
match ca_cert.issued(&cert) {
148148
Ok(()) => println!("Certificate verified!"),
149-
Err(ver_err) => println!("Failed to verify certificate: {}", ver_err),
149+
Err(ver_err) => println!("Failed to verify certificate: {ver_err}"),
150150
};
151151

152152
Ok(())
@@ -155,6 +155,6 @@ fn real_main() -> Result<(), ErrorStack> {
155155
fn main() {
156156
match real_main() {
157157
Ok(()) => println!("Finished."),
158-
Err(e) => println!("Error: {}", e),
158+
Err(e) => println!("Error: {e}"),
159159
};
160160
}

boring/src/asn1.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ impl Asn1Time {
304304

305305
/// Creates a new time on specified interval in days from now
306306
pub fn days_from_now(days: u32) -> Result<Asn1Time, ErrorStack> {
307-
Asn1Time::from_period(days as c_long * 60 * 60 * 24)
307+
// the type varies between platforms, so both into() and try_into() trigger Clippy lints
308+
Self::from_period((days * 60 * 60 * 24) as _)
308309
}
309310

310311
/// Creates a new time from the specified `time_t` value
@@ -494,7 +495,13 @@ impl Asn1IntegerRef {
494495
/// [`bn`]: ../bn/struct.BigNumRef.html#method.to_asn1_integer
495496
#[corresponds(ASN1_INTEGER_set)]
496497
pub fn set(&mut self, value: i32) -> Result<(), ErrorStack> {
497-
unsafe { cvt(crate::ffi::ASN1_INTEGER_set(self.as_ptr(), value as c_long)).map(|_| ()) }
498+
unsafe {
499+
cvt(crate::ffi::ASN1_INTEGER_set(
500+
self.as_ptr(),
501+
c_long::from(value),
502+
))
503+
.map(|_| ())
504+
}
498505
}
499506
}
500507

boring/src/base64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ mod tests {
101101

102102
#[test]
103103
fn test_encode_block() {
104-
assert_eq!("".to_string(), encode_block(b""));
104+
assert_eq!(String::new(), encode_block(b""));
105105
assert_eq!("Zg==".to_string(), encode_block(b"f"));
106106
assert_eq!("Zm8=".to_string(), encode_block(b"fo"));
107107
assert_eq!("Zm9v".to_string(), encode_block(b"foo"));

boring/src/bn.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ impl BigNumRef {
121121
/// Adds a `u32` to `self`.
122122
#[corresponds(BN_add_word)]
123123
pub fn add_word(&mut self, w: u32) -> Result<(), ErrorStack> {
124-
unsafe { cvt(ffi::BN_add_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) }
124+
unsafe { cvt(ffi::BN_add_word(self.as_ptr(), ffi::BN_ULONG::from(w))).map(|_| ()) }
125125
}
126126

127127
/// Subtracts a `u32` from `self`.
128128
#[corresponds(BN_sub_word)]
129129
pub fn sub_word(&mut self, w: u32) -> Result<(), ErrorStack> {
130-
unsafe { cvt(ffi::BN_sub_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) }
130+
unsafe { cvt(ffi::BN_sub_word(self.as_ptr(), ffi::BN_ULONG::from(w))).map(|_| ()) }
131131
}
132132

133133
/// Multiplies a `u32` by `self`.
134134
#[corresponds(BN_mul_word)]
135135
pub fn mul_word(&mut self, w: u32) -> Result<(), ErrorStack> {
136-
unsafe { cvt(ffi::BN_mul_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) }
136+
unsafe { cvt(ffi::BN_mul_word(self.as_ptr(), ffi::BN_ULONG::from(w))).map(|_| ()) }
137137
}
138138

139139
/// Divides `self` by a `u32`, returning the remainder.
@@ -263,7 +263,7 @@ impl BigNumRef {
263263
/// `self` positive.
264264
#[corresponds(BN_set_negative)]
265265
pub fn set_negative(&mut self, negative: bool) {
266-
unsafe { ffi::BN_set_negative(self.as_ptr(), negative as c_int) }
266+
unsafe { ffi::BN_set_negative(self.as_ptr(), c_int::from(negative)) }
267267
}
268268

269269
/// Compare the absolute values of `self` and `oth`.
@@ -332,7 +332,7 @@ impl BigNumRef {
332332
self.as_ptr(),
333333
bits.into(),
334334
msb.0,
335-
odd as c_int,
335+
c_int::from(odd),
336336
))
337337
.map(|_| ())
338338
}
@@ -347,7 +347,7 @@ impl BigNumRef {
347347
self.as_ptr(),
348348
bits.into(),
349349
msb.0,
350-
odd as c_int,
350+
c_int::from(odd),
351351
))
352352
.map(|_| ())
353353
}
@@ -388,7 +388,7 @@ impl BigNumRef {
388388
cvt(ffi::BN_generate_prime_ex(
389389
self.as_ptr(),
390390
bits as c_int,
391-
safe as c_int,
391+
c_int::from(safe),
392392
add.map(|n| n.as_ptr()).unwrap_or(ptr::null_mut()),
393393
rem.map(|n| n.as_ptr()).unwrap_or(ptr::null_mut()),
394394
ptr::null_mut(),
@@ -712,7 +712,7 @@ impl BigNumRef {
712712
self.as_ptr(),
713713
checks.into(),
714714
ctx.as_ptr(),
715-
do_trial_division as c_int,
715+
c_int::from(do_trial_division),
716716
ptr::null_mut(),
717717
))
718718
.map(|r| r != 0)
@@ -829,7 +829,7 @@ impl BigNum {
829829
#[corresponds(BN_set_word)]
830830
pub fn from_u32(n: u32) -> Result<BigNum, ErrorStack> {
831831
BigNum::new().and_then(|v| unsafe {
832-
cvt(ffi::BN_set_word(v.as_ptr(), n as ffi::BN_ULONG)).map(|_| v)
832+
cvt(ffi::BN_set_word(v.as_ptr(), ffi::BN_ULONG::from(n))).map(|_| v)
833833
})
834834
}
835835

@@ -928,7 +928,7 @@ impl PartialEq<BigNumRef> for BigNumRef {
928928

929929
impl PartialEq<BigNum> for BigNumRef {
930930
fn eq(&self, oth: &BigNum) -> bool {
931-
self.eq(oth.deref())
931+
self.eq(&**oth)
932932
}
933933
}
934934

@@ -956,7 +956,7 @@ impl PartialOrd<BigNumRef> for BigNumRef {
956956

957957
impl PartialOrd<BigNum> for BigNumRef {
958958
fn partial_cmp(&self, oth: &BigNum) -> Option<Ordering> {
959-
Some(self.cmp(oth.deref()))
959+
Some(self.cmp(&**oth))
960960
}
961961
}
962962

@@ -980,7 +980,7 @@ impl PartialOrd<BigNumRef> for BigNum {
980980

981981
impl Ord for BigNum {
982982
fn cmp(&self, oth: &BigNum) -> Ordering {
983-
self.deref().cmp(oth.deref())
983+
self.deref().cmp(&**oth)
984984
}
985985
}
986986

boring/src/hash.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl DerefMut for DigestBytes {
308308
impl AsRef<[u8]> for DigestBytes {
309309
#[inline]
310310
fn as_ref(&self) -> &[u8] {
311-
self.deref()
311+
self
312312
}
313313
}
314314

@@ -455,15 +455,15 @@ mod tests {
455455

456456
#[test]
457457
fn test_md5() {
458-
for test in MD5_TESTS.iter() {
458+
for test in &MD5_TESTS {
459459
hash_test(MessageDigest::md5(), test);
460460
}
461461
}
462462

463463
#[test]
464464
fn test_md5_recycle() {
465465
let mut h = Hasher::new(MessageDigest::md5()).unwrap();
466-
for test in MD5_TESTS.iter() {
466+
for test in &MD5_TESTS {
467467
hash_recycle_test(&mut h, test);
468468
}
469469
}
@@ -514,7 +514,7 @@ mod tests {
514514
fn test_sha1() {
515515
let tests = [("616263", "a9993e364706816aba3e25717850c26c9cd0d89d")];
516516

517-
for test in tests.iter() {
517+
for test in &tests {
518518
hash_test(MessageDigest::sha1(), test);
519519
}
520520
}
@@ -526,7 +526,7 @@ mod tests {
526526
"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7",
527527
)];
528528

529-
for test in tests.iter() {
529+
for test in &tests {
530530
hash_test(MessageDigest::sha224(), test);
531531
}
532532
}
@@ -538,7 +538,7 @@ mod tests {
538538
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
539539
)];
540540

541-
for test in tests.iter() {
541+
for test in &tests {
542542
hash_test(MessageDigest::sha256(), test);
543543
}
544544
}
@@ -551,7 +551,7 @@ mod tests {
551551
192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
552552
)];
553553

554-
for test in tests.iter() {
554+
for test in &tests {
555555
hash_test(MessageDigest::sha512(), test);
556556
}
557557
}
@@ -563,7 +563,7 @@ mod tests {
563563
"53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23",
564564
)];
565565

566-
for test in tests.iter() {
566+
for test in &tests {
567567
hash_test(MessageDigest::sha512_256(), test);
568568
}
569569
}

boring/src/rsa.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ where
143143
to: &mut [u8],
144144
padding: Padding,
145145
) -> Result<usize, ErrorStack> {
146-
assert!(from.len() <= i32::MAX as usize);
146+
assert!(i32::try_from(from.len()).is_ok());
147147
assert!(to.len() >= self.size() as usize);
148148

149149
unsafe {
@@ -170,7 +170,7 @@ where
170170
to: &mut [u8],
171171
padding: Padding,
172172
) -> Result<usize, ErrorStack> {
173-
assert!(from.len() <= i32::MAX as usize);
173+
assert!(i32::try_from(from.len()).is_ok());
174174
assert!(to.len() >= self.size() as usize);
175175

176176
unsafe {
@@ -334,7 +334,7 @@ where
334334
to: &mut [u8],
335335
padding: Padding,
336336
) -> Result<usize, ErrorStack> {
337-
assert!(from.len() <= i32::MAX as usize);
337+
assert!(i32::try_from(from.len()).is_ok());
338338
assert!(to.len() >= self.size() as usize);
339339

340340
unsafe {
@@ -360,7 +360,7 @@ where
360360
to: &mut [u8],
361361
padding: Padding,
362362
) -> Result<usize, ErrorStack> {
363-
assert!(from.len() <= i32::MAX as usize);
363+
assert!(i32::try_from(from.len()).is_ok());
364364
assert!(to.len() >= self.size() as usize);
365365

366366
unsafe {

boring/src/ssl/bio.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ pub unsafe extern "C" fn take_stream<S>(bio: *mut BIO) -> S {
8585

8686
pub unsafe fn set_dtls_mtu_size<S>(bio: *mut BIO, mtu_size: usize) {
8787
if mtu_size as u64 > c_long::MAX as u64 {
88-
panic!(
89-
"Given MTU size {} can't be represented in a positive `c_long` range",
90-
mtu_size
91-
)
88+
panic!("Given MTU size {mtu_size} can't be represented in a positive `c_long` range")
9289
}
9390
state::<S>(bio).dtls_mtu_size = mtu_size as c_long;
9491
}

0 commit comments

Comments
 (0)