Skip to content

Commit 0f9f2cb

Browse files
authored
Merge 825d86f into 7116abe
2 parents 7116abe + 825d86f commit 0f9f2cb

39 files changed

+706
-650
lines changed

mbedtls-platform-support/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use std::env;
1212
fn main() {
1313
let env_components = env::var("DEP_MBEDTLS_PLATFORM_COMPONENTS").unwrap();
1414
let mut sys_platform_components = HashMap::<_, HashSet<_>>::new();
15-
for mut kv in env_components.split(",").map(|component| component.splitn(2, "=")) {
15+
for mut kv in env_components.split(',').map(|component| component.splitn(2, '=')) {
1616
let k = kv.next().unwrap();
1717
let v = kv.next().unwrap();
1818
sys_platform_components.entry(k).or_insert_with(Default::default).insert(v);
19-
println!(r#"cargo:rustc-cfg=sys_{}="{}""#, k, v);
19+
println!(r#"cargo:rustc-cfg=sys_{k}="{v}""#);
2020
}
2121

2222
let mut b = cc::Build::new();

mbedtls-platform-support/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* option. This file may not be copied, modified, or distributed except
77
* according to those terms. */
88

9+
#![allow(unexpected_cfgs)]
910
#![cfg_attr(not(feature = "std"), no_std)]
1011

1112
#[cfg(not(feature = "std"))]

mbedtls-platform-support/src/self_test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
* option. This file may not be copied, modified, or distributed except
77
* according to those terms. */
88

9-
//! MbedTLS self tests.
9+
//! `MbedTLS` self tests.
1010
//!
11-
//! Calling MbedTLS self test functions before they're enabled using the
11+
//! Calling `MbedTLS` self test functions before they're enabled using the
1212
//! `enable()` function here will result in a panic.
1313
//!
1414
//! Using this module in multithreaded or async environment will fail. The self
1515
//! test functions rely on global variables to track operations and anything
1616
//! non-self-test related operations will clobber these variables, resulting in
17-
//! self test failures. Make sure no other code uses MbedTLS while running the
17+
//! self test failures. Make sure no other code uses `MbedTLS` while running the
1818
//! self tests. Multiple self test operations done simultaneously may also
1919
//! return failures.
2020
@@ -53,7 +53,7 @@ pub unsafe extern "C" fn rand() -> c_int {
5353
rand_f.expect("Called self-test rand without enabling self-test")()
5454
}
5555

56-
/// Set callback functions to enable the MbedTLS self tests.
56+
/// Set callback functions to enable the `MbedTLS` self tests.
5757
///
5858
/// `rand` only needs to be set on platforms that don't have a `rand()`
5959
/// function in libc. `log` only needs to be set when using `no_std`, i.e.
@@ -80,7 +80,7 @@ pub unsafe fn enable(rand: fn() -> c_int, log: Option<unsafe fn(*const c_char)>)
8080
///
8181
/// The caller needs to ensure this function is not called while any other
8282
/// function in this module is called.
83-
pub unsafe fn disable() {
83+
pub const unsafe fn disable() {
8484
#[cfg(any(not(feature = "std"), target_env = "sgx"))]
8585
{
8686
rand_f = None;
@@ -94,7 +94,7 @@ pub unsafe fn disable() {
9494
/// # Safety
9595
///
9696
/// The caller needs to ensure this function is not called while *any other*
97-
/// MbedTLS function is called. See the module documentation for more
97+
/// `MbedTLS` function is called. See the module documentation for more
9898
/// information.
9999
pub use mbedtls_sys::{
100100
aes_self_test as aes, arc4_self_test as arc4, aria_self_test as aria, base64_self_test as base64,

mbedtls-sys/build/bindgen.rs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl bindgen::callbacks::ParseCallbacks for MbedtlsParseCallbacks {
3535
}
3636

3737
fn int_macro(&self, _name: &str, value: i64) -> Option<bindgen::callbacks::IntKind> {
38-
if value < (i32::MIN as i64) || value > (i32::MAX as i64) {
38+
if value < i64::from(i32::MIN) || value > i64::from(i32::MAX) {
3939
Some(bindgen::callbacks::IntKind::LongLong)
4040
} else {
4141
Some(bindgen::callbacks::IntKind::Int)
@@ -87,7 +87,7 @@ fn generate_deprecated_union_accessors(bindings: &str) -> String {
8787
}
8888

8989
let mut impl_builder = UnionImplBuilder::default();
90-
syn::visit::visit_file(&mut impl_builder, &syn::parse_file(&bindings).unwrap());
90+
syn::visit::visit_file(&mut impl_builder, &syn::parse_file(bindings).unwrap());
9191

9292
impl_builder.impls
9393
}
@@ -96,7 +96,7 @@ impl super::BuildConfig {
9696
pub fn bindgen(&self) {
9797
let mut input = String::new();
9898
for h in headers::enabled_ordered() {
99-
let _ = writeln!(input, "#include <mbedtls/{}>", h);
99+
let _ = writeln!(input, "#include <mbedtls/{h}>");
100100
}
101101

102102
let mut cc = cc::Build::new();
@@ -115,14 +115,12 @@ impl super::BuildConfig {
115115
// uses the correct headers
116116
let compiler = cc.get_compiler();
117117
if compiler.is_like_gnu() {
118-
let output = compiler.to_command().args(&["--print-sysroot"]).output();
119-
match output {
120-
Ok(sysroot) => {
121-
let path = std::str::from_utf8(&sysroot.stdout).expect("Malformed sysroot");
122-
let trimmed_path = path.strip_suffix("\r\n").or(path.strip_suffix("\n")).unwrap_or(&path);
123-
cc.flag(&format!("--sysroot={}", trimmed_path));
124-
}
125-
_ => {} // skip toolchains without a configured sysroot
118+
let output = compiler.to_command().args(["--print-sysroot"]).output();
119+
// skip toolchains without a configured sysroot
120+
if let Ok(sysroot) = output {
121+
let path = std::str::from_utf8(&sysroot.stdout).expect("Malformed sysroot");
122+
let trimmed_path = path.strip_suffix("\r\n").or_else(|| path.strip_suffix("\n")).unwrap_or(path);
123+
cc.flag(&format!("--sysroot={trimmed_path}"));
126124
};
127125
}
128126

@@ -146,7 +144,28 @@ impl super::BuildConfig {
146144
.derive_default(true)
147145
.prepend_enum_name(false)
148146
.translate_enum_integer_types(true)
149-
.raw_line("#![allow(dead_code, deref_nullptr, non_snake_case, non_camel_case_types, non_upper_case_globals, invalid_value)]")
147+
.raw_line("#![allow(")
148+
.raw_line(" dead_code,")
149+
.raw_line(" deref_nullptr,")
150+
.raw_line(" invalid_value,")
151+
.raw_line(" non_snake_case,")
152+
.raw_line(" non_camel_case_types,")
153+
.raw_line(" non_upper_case_globals")
154+
.raw_line(")]")
155+
.raw_line("#![allow(")
156+
.raw_line(" clippy::cast_lossless,")
157+
.raw_line(" clippy::cast_possible_truncation,")
158+
.raw_line(" clippy::default_trait_access,")
159+
.raw_line(" clippy::missing_safety_doc,")
160+
.raw_line(" clippy::must_use_candidate,")
161+
.raw_line(" clippy::pub_underscore_fields,")
162+
.raw_line(" clippy::unreadable_literal,")
163+
.raw_line(" clippy::used_underscore_binding,")
164+
.raw_line(" clippy::useless_transmute,")
165+
.raw_line(" clippy::semicolon_if_nothing_returned,")
166+
.raw_line(" clippy::type_complexity,")
167+
.raw_line(" clippy::wildcard_imports")
168+
.raw_line(")]")
150169
.generate()
151170
.expect("bindgen error")
152171
.to_string();

mbedtls-sys/build/build.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>, at your
66
* option. This file may not be copied, modified, or distributed except
77
* according to those terms. */
8+
#![allow(clippy::unwrap_used)]
89

910
extern crate bindgen;
1011
extern crate cmake;
@@ -82,7 +83,7 @@ impl BuildConfig {
8283
fn new() -> Self {
8384
let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR environment not set?"));
8485
let config_h = out_dir.join("config.h");
85-
let mbedtls_src = PathBuf::from(env::var("RUST_MBEDTLS_SYS_SOURCE").unwrap_or("vendor".to_owned()));
86+
let mbedtls_src = PathBuf::from(env::var("RUST_MBEDTLS_SYS_SOURCE").unwrap_or_else(|_| "vendor".to_owned()));
8687
let mbedtls_include = mbedtls_src.join("include");
8788

8889
let mut cflags = vec![];
@@ -93,11 +94,11 @@ impl BuildConfig {
9394
cflags.push("-fno-stack-protector".into());
9495
}
9596

96-
BuildConfig {
97-
config_h,
97+
Self {
9898
out_dir,
9999
mbedtls_src,
100100
mbedtls_include,
101+
config_h,
101102
cflags,
102103
}
103104
}

mbedtls-sys/build/cmake.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ impl super::BuildConfig {
2929
}
3030

3131
println!("cargo:rerun-if-env-changed=RUST_MBED_C_COMPILER_BAREMETAL");
32-
let c_compiler_baremetal = std::env::var("RUST_MBED_C_COMPILER_BAREMETAL")
33-
.map(|val| val == "1")
34-
.unwrap_or_default();
32+
let c_compiler_baremetal = std::env::var("RUST_MBED_C_COMPILER_BAREMETAL").is_ok_and(|val| val == "1");
3533

3634
let target = std::env::var("TARGET").expect("TARGET environment variable should be set in build scripts");
3735
// thumbv6m-none-eabi, thumbv7em-none-eabi, thumbv7em-none-eabihf,

mbedtls-sys/build/config.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ pub enum Macro {
1515
#[allow(dead_code)]
1616
DefinedAs(&'static str),
1717
}
18-
use self::Macro::*;
18+
use self::Macro::{Defined, DefinedAs, Undefined};
1919

2020
impl Macro {
2121
pub fn define(self, name: &'static str) -> String {
2222
match self {
2323
Undefined => String::new(),
24-
Defined => format!("#define {}\n", name),
25-
DefinedAs(v) => format!("#define {} {}\n", name, v),
24+
Defined => format!("#define {name}\n"),
25+
DefinedAs(v) => format!("#define {name} {v}\n"),
2626
}
2727
}
2828
}
2929

3030
pub type CDefine = (&'static str, Macro);
3131

32-
pub const PREFIX: &'static str = r#"
32+
pub const PREFIX: &str = r"
3333
#ifndef MBEDTLS_CONFIG_H
3434
#define MBEDTLS_CONFIG_H
3535
3636
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
3737
#define _CRT_SECURE_NO_DEPRECATE 1
3838
#endif
39-
"#;
39+
";
4040

4141
/*
4242
@@ -64,8 +64,8 @@ for line in open('vendor/include/mbedtls/config.h').readlines():
6464
print format(match.group(1), "Undefined") + (" // default: %s" % (match.group(2)))
6565
*/
6666

67-
#[cfg_attr(rustfmt, rustfmt_skip)]
68-
const DEFAULT_DEFINES: &'static [CDefine] = &[
67+
#[rustfmt::skip]
68+
const DEFAULT_DEFINES: &[CDefine] = &[
6969
("MBEDTLS_HAVE_ASM", Defined),
7070
("MBEDTLS_NO_UDBL_DIVISION", Undefined),
7171
("MBEDTLS_NO_64BIT_MULTIPLICATION", Undefined),
@@ -408,17 +408,20 @@ const DEFAULT_DEFINES: &'static [CDefine] = &[
408408
pub fn default_defines() -> HashMap<&'static str, Macro> {
409409
let mut defines = HashMap::new();
410410

411-
for (key, value) in DEFAULT_DEFINES.iter() {
412-
if defines.insert(*key, *value).is_some() {
413-
panic!("Duplicate default define in {}: {}", file!(), key);
414-
}
411+
for (key, value) in DEFAULT_DEFINES {
412+
assert!(
413+
defines.insert(*key, *value).is_none(),
414+
"Duplicate default define in {}: {}",
415+
file!(),
416+
key
417+
);
415418
}
416419

417420
defines
418421
}
419422

420-
#[cfg_attr(rustfmt, rustfmt_skip)]
421-
pub const FEATURE_DEFINES: &'static [(&'static str, CDefine)] = &[
423+
#[rustfmt::skip]
424+
pub const FEATURE_DEFINES: &[(&str, CDefine)] = &[
422425
("time", ("MBEDTLS_HAVE_TIME", Defined)),
423426
("time", ("MBEDTLS_HAVE_TIME_DATE", Defined)),
424427
("havege", ("MBEDTLS_HAVEGE_C", Defined)),
@@ -442,8 +445,8 @@ pub const FEATURE_DEFINES: &'static [(&'static str, CDefine)] = &[
442445
("trusted_cert_callback", ("MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK", Defined)),
443446
];
444447

445-
#[cfg_attr(rustfmt, rustfmt_skip)]
446-
pub const PLATFORM_DEFINES: &'static [(&'static str, &'static str, CDefine)] = &[
448+
#[rustfmt::skip]
449+
pub const PLATFORM_DEFINES: &[(&str, &str, CDefine)] = &[
447450
("time", "libc", ("MBEDTLS_TIMING_C", Defined)),
448451
("time", "custom", ("MBEDTLS_PLATFORM_TIME_MACRO", DefinedAs("mbedtls_time"))),
449452
("time", "custom", ("MBEDTLS_PLATFORM_TIME_TYPE_MACRO", DefinedAs("long long"))),
@@ -456,7 +459,7 @@ pub const PLATFORM_DEFINES: &'static [(&'static str, &'static str, CDefine)] = &
456459
("std", "entropy", ("MBEDTLS_ENTROPY_C", Defined)),
457460
];
458461

459-
pub const SUFFIX: &'static str = r#"
462+
pub const SUFFIX: &str = r#"
460463
#if defined(TARGET_LIKE_MBED)
461464
#include "mbedtls/target_config.h"
462465
#endif

mbedtls-sys/build/features.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Features {
5959

6060
for (feature, components) in &self.platform_components {
6161
for component in components {
62-
println!(r#"cargo:rustc-cfg={}_component="{}""#, feature, component);
62+
println!(r#"cargo:rustc-cfg={feature}_component="{component}""#);
6363
}
6464
}
6565
println!(
@@ -69,7 +69,7 @@ impl Features {
6969
.flat_map(|(feature, components)| {
7070
components
7171
.iter()
72-
.map(move |component| format!(r#"{}_component={}"#, feature, component))
72+
.map(move |component| format!(r#"{feature}_component={component}"#))
7373
})
7474
.collect::<Vec<_>>()
7575
.join(",")
@@ -78,7 +78,9 @@ impl Features {
7878

7979
fn with_feature(&mut self, feature: &'static str) -> Option<&mut HashSet<&'static str>> {
8080
if self.have_feature(feature) {
81-
Some(self.platform_components.entry(feature).or_insert_with(HashSet::new))
81+
Some(self.platform_components.entry(feature).or_default())
82+
//This should be the same
83+
//Some(self.platform_components.entry(feature).or_insert_with(HashSet::new))
8284
} else {
8385
None
8486
}
@@ -96,11 +98,11 @@ impl Features {
9698
}
9799

98100
fn env_have_target_cfg(var: &'static str, value: &'static str) -> bool {
99-
let env = format!("CARGO_CFG_TARGET_{}", var).to_uppercase().replace("-", "_");
101+
let env = format!("CARGO_CFG_TARGET_{var}").to_uppercase().replace('-', "_");
100102
env::var_os(env).map_or(false, |s| s == value)
101103
}
102104

103105
fn env_have_feature(feature: &'static str) -> bool {
104-
let env = format!("CARGO_FEATURE_{}", feature).to_uppercase().replace("-", "_");
106+
let env = format!("CARGO_FEATURE_{feature}").to_uppercase().replace('-', "_");
105107
env::var_os(env).is_some()
106108
}

mbedtls-sys/build/headers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use crate::features::FEATURES;
2525
* )
2626
*/
2727

28-
#[cfg_attr(rustfmt, rustfmt_skip)]
29-
pub const ORDERED: &'static [(Option<&'static str>, &'static str)] = &[
28+
#[rustfmt::skip]
29+
pub const ORDERED: &[(Option<&'static str>, &str)] = &[
3030
(None, "config_psa.h"),
3131
(None, "platform_time.h"),
3232
(None, "platform_util.h"),

mbedtls-sys/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* option. This file may not be copied, modified, or distributed except
77
* according to those terms. */
88

9+
#![allow(unexpected_cfgs)]
910
#![cfg_attr(not(feature = "std"), no_std)]
1011
#[cfg(feature = "std")]
1112
extern crate core;

mbedtls-sys/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* option. This file may not be copied, modified, or distributed except
77
* according to those terms. */
88

9-
#![allow(non_camel_case_types)]
9+
#![allow(non_camel_case_types, clippy::module_name_repetitions)]
1010

1111
pub type int8_t = i8;
1212
pub type int16_t = i16;

0 commit comments

Comments
 (0)