Skip to content

Commit b5fc7d1

Browse files
committed
error: replace num_enum with minimal macro rule.
The `num_enum` dependency brings with it a large number of transitive dependencies. Some of those transitive deps now have an aggressive MSRV of 1.64+. The existing usage of `num_enum` is very minimal: just one derived trait for the `rustls_result` enum to provide it with a `From` impl for u32 primitive values. This commit replaces the `num_enum` crate with a small `u32_enum_builder!` macro rule loosely based on the Rustls `enum_builder` macro. Since our use case is narrower, I've simplified the macro and tailored it to the rustls-ffi use-case. With the new implementation we can also drop the use of `try_from`. In each case where we're converting from code -> result we're happy for the default `from` impl's `InvalidParameter` variant to be used when given an unknown code, making the use of `try_from` unnecessary. This approach adds one complication related to `cbindgen`: it now has to be instructed to expand the `rustls-ffi` crate before generating bindings in order to find the `rustls_result` enum. Doing this requires tweaking the `cbindgen.toml` to add a `parse.expand` configuration setting. Notably this also means `cbindgen` now has to be run with a nightly `rustc`. Since this is a developer only workflow it shouldn't be too onerous a requirement. We're now happily building with Rust 1.60 again and can also breathe easy knowing we have a slimmer dependency profile! tidy: replace rustls_result::try_from -> from.
1 parent ee4c5ea commit b5fc7d1

File tree

6 files changed

+183
-147
lines changed

6 files changed

+183
-147
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ jobs:
7777
- uses: actions/checkout@v2
7878
with:
7979
persist-credentials: false
80+
- name: Install nightly rust toolchain
81+
uses: actions-rs/toolchain@v1
82+
with:
83+
toolchain: nightly
84+
override: true
85+
default: true
8086
- name: Configure CMake
8187
run: cmake -S . -B build
8288
- name: Build, debug configuration
@@ -93,6 +99,12 @@ jobs:
9399
- uses: actions/checkout@v2
94100
with:
95101
persist-credentials: false
102+
- name: Install nightly rust toolchain
103+
uses: actions-rs/toolchain@v1
104+
with:
105+
toolchain: nightly
106+
override: true
107+
default: true
96108
- name: Configure CMake
97109
run: cmake -S . -B build
98110
- name: Build, release configuration
@@ -106,6 +118,12 @@ jobs:
106118
- uses: actions/checkout@v2
107119
with:
108120
persist-credentials: false
121+
- name: Install nightly rust toolchain
122+
uses: actions-rs/toolchain@v1
123+
with:
124+
toolchain: nightly
125+
override: true
126+
default: true
109127
- run: touch src/lib.rs
110128
- run: cbindgen --version
111129
- run: make src/rustls.h

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ libc = "0.2"
2929
sct = "0.7"
3030
rustls-pemfile = "0.2.1"
3131
log = "0.4.17"
32-
num_enum = "0.5.10"
3332

3433
[lib]
3534
name = "rustls_ffi"

cbindgen.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ include = ["rustls_tls_version"]
1111

1212
[defines]
1313
"feature = read_buf" = "DEFINE_READ_BUF"
14+
15+
[parse.expand]
16+
crates = ["rustls-ffi"]
17+
features = ["read_buf"]

src/client.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::borrow::Cow;
2-
use std::convert::{TryFrom, TryInto};
2+
use std::convert::TryInto;
33
use std::ffi::{CStr, OsStr};
44
use std::fs::File;
55
use std::io::BufReader;
@@ -263,9 +263,7 @@ impl rustls::client::ServerCertVerifier for Verifier {
263263
rustls::Error::General("internal error with thread-local storage".to_string())
264264
})?;
265265
let result: u32 = unsafe { cb(userdata, &params) };
266-
let result: rustls_result =
267-
rustls_result::try_from(result).unwrap_or(rustls_result::General);
268-
match result {
266+
match rustls_result::from(result) {
269267
rustls_result::Ok => Ok(ServerCertVerified::assertion()),
270268
r => Err(error::cert_result_to_error(r)),
271269
}

0 commit comments

Comments
 (0)