Skip to content

Commit 2beb625

Browse files
committed
cargo fmt; build
1 parent 6dd99a5 commit 2beb625

File tree

11 files changed

+258
-145
lines changed

11 files changed

+258
-145
lines changed

esp-mbedtls-sys/build.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,41 @@ fn main() -> Result<()> {
2727
let libs_dir = crate_root_path.join("libs");
2828

2929
let dirs = if esp32 {
30-
Some((bindings_dir.join("esp32.rs"), libs_dir.join("xtensa-esp32-none-elf")))
30+
Some((
31+
bindings_dir.join("esp32.rs"),
32+
libs_dir.join("xtensa-esp32-none-elf"),
33+
))
3134
} else if esp32c3 {
32-
Some((bindings_dir.join("esp32c3.rs"), libs_dir.join("riscv32imc-unknown-none-elf")))
35+
Some((
36+
bindings_dir.join("esp32c3.rs"),
37+
libs_dir.join("riscv32imc-unknown-none-elf"),
38+
))
3339
} else if esp32s2 {
34-
Some((bindings_dir.join("esp32s2.rs"), libs_dir.join("xtensa-esp32s2-none-elf")))
40+
Some((
41+
bindings_dir.join("esp32s2.rs"),
42+
libs_dir.join("xtensa-esp32s2-none-elf"),
43+
))
3544
} else if esp32s3 {
36-
Some((bindings_dir.join("esp32s3.rs"), libs_dir.join("xtensa-esp32s3-none-elf")))
45+
Some((
46+
bindings_dir.join("esp32s3.rs"),
47+
libs_dir.join("xtensa-esp32s3-none-elf"),
48+
))
3749
} else if target.ends_with("-espidf") {
3850
// Nothing to do for ESP-IDF, `esp-idf-sys` will do everything for us
3951
None
4052
} else {
4153
// Need to do on-the-fly build and bindings' generation
4254
let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());
4355

44-
let builder = builder::MbedtlsBuilder::new(crate_root_path.clone(), "generic".to_string(), None, None, None, Some(target), Some(host));
56+
let builder = builder::MbedtlsBuilder::new(
57+
crate_root_path.clone(),
58+
"generic".to_string(),
59+
None,
60+
None,
61+
None,
62+
Some(target),
63+
Some(host),
64+
);
4565

4666
let libs_dir = builder.compile(&out, None)?;
4767
let bindings = builder.generate_bindings(&out, None)?;
@@ -50,7 +70,10 @@ fn main() -> Result<()> {
5070
};
5171

5272
if let Some((bindings, libs_dir)) = dirs {
53-
println!("cargo::rustc-env=ESP_MBEDTLS_SYS_GENERATED_BINDINGS_FILE={}", bindings.display());
73+
println!(
74+
"cargo::rustc-env=ESP_MBEDTLS_SYS_GENERATED_BINDINGS_FILE={}",
75+
bindings.display()
76+
);
5477

5578
println!("cargo:rustc-link-lib=static={}", "mbedtls");
5679
println!("cargo:rustc-link-lib=static={}", "mbedx509");

esp-mbedtls-sys/gen/builder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,15 @@ impl MbedtlsBuilder {
166166
// Clang will complain about some documentation formatting in mbedtls
167167
.define("MBEDTLS_FATAL_WARNINGS", "OFF")
168168
.define(
169-
"MBEDTLS_CONFIG_FILE",
169+
"MBEDTLS_CONFIG_FILE",
170170
&self
171171
.crate_root_path
172172
.join("gen")
173173
.join("include")
174174
.join("soc")
175175
.join(&self.soc_config)
176-
.join("config.h"))
176+
.join("config.h"),
177+
)
177178
.define(
178179
"CMAKE_TOOLCHAIN_FILE",
179180
&self

esp-mbedtls-sys/src/lib.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#![no_std]
22

33
// For `malloc`, `calloc` and `free` which are provided by `esp-wifi` on baremetal
4-
#[cfg(any(feature = "esp32", feature = "esp32c3", feature = "esp32s2", feature = "esp32s3"))]
4+
#[cfg(any(
5+
feature = "esp32",
6+
feature = "esp32c3",
7+
feature = "esp32s2",
8+
feature = "esp32s3"
9+
))]
510
use esp_wifi as _;
611

712
#[cfg(not(target_os = "espidf"))]
@@ -14,7 +19,15 @@ mod c_types;
1419
dead_code
1520
)]
1621
pub mod bindings {
17-
#[cfg(all(not(target_os = "espidf"), not(any(feature = "esp32", feature = "esp32c3", feature = "esp32s2", feature = "esp32s3"))))]
22+
#[cfg(all(
23+
not(target_os = "espidf"),
24+
not(any(
25+
feature = "esp32",
26+
feature = "esp32c3",
27+
feature = "esp32s2",
28+
feature = "esp32s3"
29+
))
30+
))]
1831
include!(env!("ESP_MBEDTLS_SYS_GENERATED_BINDINGS_FILE"));
1932

2033
// This and below are necessary because of https://github.com/rust-lang/cargo/issues/10358

esp-mbedtls/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ esp32s3 = ["esp-hal/esp32s3", "esp-wifi/esp32s3", "esp-mbedtls-sys/esp32s3", "cr
3333

3434
# Implement the traits defined in the latest HEAD of `edge-nal`
3535
edge-nal = ["dep:edge-nal", "async"]
36+
37+
# Patch until new release
38+
[patch.crates-io]
39+
edge-nal = { git = "https://github.com/ivmarkov/edge-net" }
40+
esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc" }
41+
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" }
42+
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" }
43+
cmake = { git = "https://github.com/ivmarkov/cmake-rs" }

esp-mbedtls/src/edge_nal.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::net::SocketAddr;
44
use embedded_io::Error;
55

66
use crate::asynch::Session;
7-
use crate::{Certificates, TlsReference, Mode, TlsError, TlsVersion};
7+
use crate::{Certificates, Mode, TlsError, TlsReference, TlsVersion};
88

99
/// An implementation of `edge-nal`'s `TcpAccept` trait over TLS.
1010
pub struct TlsAcceptor<'d, T> {
@@ -19,9 +19,9 @@ where
1919
T: edge_nal::TcpAccept,
2020
{
2121
/// Create a new instance of the `TlsAcceptor` type.
22-
///
22+
///
2323
/// Arguments:
24-
///
24+
///
2525
/// * `acceptor` - The underlying TCP acceptor
2626
/// * `min_version` - The minimum TLS version to support
2727
/// * `certificates` - The certificates to use for each accepted TLS connection
@@ -84,9 +84,9 @@ where
8484
T: edge_nal::TcpConnect,
8585
{
8686
/// Create a new instance of the `TlsConnector` type.
87-
///
87+
///
8888
/// Arguments:
89-
///
89+
///
9090
/// * `connector` - The underlying TCP connector
9191
/// * `servername` - The server name to check against the certificate presented by the server
9292
/// * `min_version` - The minimum TLS version to support
@@ -114,9 +114,9 @@ where
114114
T: edge_nal::TcpConnect,
115115
{
116116
type Error = TlsError;
117-
117+
118118
type Socket<'a> = Session<'a, T::Socket<'a>> where Self: 'a;
119-
119+
120120
async fn connect(&self, remote: SocketAddr) -> Result<Self::Socket<'_>, Self::Error> {
121121
let socket = self
122122
.connector
@@ -127,7 +127,9 @@ where
127127

128128
let session = Session::new(
129129
socket,
130-
Mode::Client { servername: self.servername },
130+
Mode::Client {
131+
servername: self.servername,
132+
},
131133
self.min_version,
132134
self.certificates,
133135
self.tls_ref,
@@ -142,9 +144,9 @@ where
142144
T: edge_nal::Readable,
143145
{
144146
async fn readable(&mut self) -> Result<(), Self::Error> {
145-
// ... 1- because it is difficult to figure out - with the MbedTLS API - if `Session::read` would return without blocking
146-
// For this, we need support for that in MbedTLS itself, which is not available at the moment.
147-
// 2- because `Readable` currently throws exception with `edge-nal-embassy`
147+
// ... 1- because it is difficult to figure out - with the MbedTLS API - if `Session::read` would return without blocking
148+
// For this, we need support for that in MbedTLS itself, which is not available at the moment.
149+
// 2- because `Readable` currently throws exception with `edge-nal-embassy`
148150
Ok(())
149151
}
150152
}
@@ -163,6 +165,9 @@ where
163165
}
164166

165167
async fn abort(&mut self) -> Result<(), Self::Error> {
166-
self.stream.abort().await.map_err(|e| TlsError::Io(e.kind()))
168+
self.stream
169+
.abort()
170+
.await
171+
.map_err(|e| TlsError::Io(e.kind()))
167172
}
168173
}

esp-mbedtls/src/esp_hal.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#[doc(hidden)]
2-
32
use core::cell::RefCell;
43
use critical_section::Mutex;
54

@@ -29,12 +28,12 @@ static SHARED_SHA: Mutex<RefCell<Option<Sha<'static>>>> = Mutex::new(RefCell::ne
2928

3029
impl<'d> Tls<'d> {
3130
/// Create a new instance of the `Tls` type.
32-
///
31+
///
3332
/// Note that there could be only one active `Tls` instance at any point in time,
3433
/// and the function will return an error if there is already an active instance.
35-
///
34+
///
3635
/// Arguments:
37-
///
36+
///
3837
/// * `sha` - The SHA peripheral from the HAL
3938
pub fn new(sha: impl Peripheral<P = SHA> + 'd) -> Result<Self, TlsError> {
4039
let this = Self::create()?;
@@ -61,7 +60,9 @@ impl<'d> Tls<'d> {
6160

6261
impl Drop for Tls<'_> {
6362
fn drop(&mut self) {
64-
unsafe { RSA_REF = core::mem::transmute(None::<RSA>); }
63+
unsafe {
64+
RSA_REF = core::mem::transmute(None::<RSA>);
65+
}
6566
critical_section::with(|cs| SHARED_SHA.borrow_ref_mut(cs).take());
6667
}
6768
}

esp-mbedtls/src/esp_hal/sha/sha1.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ pub struct mbedtls_sha1_context {
1414

1515
#[no_mangle]
1616
pub unsafe extern "C" fn mbedtls_sha1_init(ctx: *mut mbedtls_sha1_context) {
17-
let hasher_mem =
18-
crate::aligned_calloc(core::mem::align_of::<Context<Sha1>>(), core::mem::size_of::<Context<Sha1>>()) as *mut Context<Sha1>;
17+
let hasher_mem = crate::aligned_calloc(
18+
core::mem::align_of::<Context<Sha1>>(),
19+
core::mem::size_of::<Context<Sha1>>(),
20+
) as *mut Context<Sha1>;
1921
core::ptr::write(hasher_mem, Context::<Sha1>::new());
2022
(*ctx).hasher = hasher_mem;
2123
}

esp-mbedtls/src/esp_hal/sha/sha256.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ pub struct mbedtls_sha256_context {
1616

1717
#[no_mangle]
1818
pub unsafe extern "C" fn mbedtls_sha256_init(ctx: *mut mbedtls_sha256_context) {
19-
let sha224_mem =
20-
crate::aligned_calloc(core::mem::align_of::<Context<Sha224>>(), core::mem::size_of::<Context<Sha224>>()) as *mut Context<Sha224>;
21-
let sha256_mem =
22-
crate::aligned_calloc(core::mem::align_of::<Context<Sha256>>(), core::mem::size_of::<Context<Sha256>>()) as *mut Context<Sha256>;
19+
let sha224_mem = crate::aligned_calloc(
20+
core::mem::align_of::<Context<Sha224>>(),
21+
core::mem::size_of::<Context<Sha224>>(),
22+
) as *mut Context<Sha224>;
23+
let sha256_mem = crate::aligned_calloc(
24+
core::mem::align_of::<Context<Sha256>>(),
25+
core::mem::size_of::<Context<Sha256>>(),
26+
) as *mut Context<Sha256>;
2327
(*ctx).sha224_hasher = sha224_mem;
2428
(*ctx).sha256_hasher = sha256_mem;
2529
}

esp-mbedtls/src/esp_hal/sha/sha512.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ pub struct mbedtls_sha512_context {
1616

1717
#[no_mangle]
1818
pub unsafe extern "C" fn mbedtls_sha512_init(ctx: *mut mbedtls_sha512_context) {
19-
let sha384_mem =
20-
crate::aligned_calloc(core::mem::align_of::<Context<Sha384>>(), core::mem::size_of::<Context<Sha384>>()) as *mut Context<Sha384>;
21-
let sha512_mem =
22-
crate::aligned_calloc(core::mem::align_of::<Context<Sha512>>(), core::mem::size_of::<Context<Sha512>>()) as *mut Context<Sha512>;
19+
let sha384_mem = crate::aligned_calloc(
20+
core::mem::align_of::<Context<Sha384>>(),
21+
core::mem::size_of::<Context<Sha384>>(),
22+
) as *mut Context<Sha384>;
23+
let sha512_mem = crate::aligned_calloc(
24+
core::mem::align_of::<Context<Sha512>>(),
25+
core::mem::size_of::<Context<Sha512>>(),
26+
) as *mut Context<Sha512>;
2327
(*ctx).sha384_hasher = sha384_mem;
2428
(*ctx).sha512_hasher = sha512_mem;
2529
}

0 commit comments

Comments
 (0)