Skip to content

Commit d05565c

Browse files
authored
Merge pull request BlackDex#1 from BlackDex/update-crates-edition-and-clippy
Update crates, edition, name and clippy fixes * Upgrade to `tokio` 1.44, `rand` 0.9 * Renamed to yubico_ng and published crate * Made edition 2024 compatible * Added several clippy/rust lints and fixed those * Fixed a panic if the `YK_API_HOST` was invalid * Use only the main api server, the others are deprecated * Run cargo fmt * Updated GHA to use hashes and run/fix zizmor * Set MSRV based upon 'cargo msrv find'
2 parents d927c95 + 1b2f538 commit d05565c

18 files changed

+553
-218
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target/
2+
Cargo.lock
3+
Dockerfile**
4+
LICENSE
5+
6+
.dockerignore
7+
*.fmt
8+
*.iml
9+
*.md

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
github: BlackDex
2+
liberapay: BlackDex
3+
custom: ["https://paypal.me/MathijsvVeluw"]

.github/workflows/build.yml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
name: Build
2+
permissions: {}
3+
4+
on:
5+
push:
6+
paths:
7+
- ".github/workflows/build.yml"
8+
- "examples/**"
9+
- "src/**"
10+
- "Cargo.toml"
11+
pull_request:
12+
paths:
13+
- ".github/workflows/build.yml"
14+
- "examples/**"
15+
- "src/**"
16+
- "Cargo.toml"
17+
18+
## To trigger this workflow using `act` (https://github.com/nektos/act) you can do the following.
19+
# act push -j build
20+
21+
jobs:
22+
build:
23+
name: Build and Test
24+
permissions:
25+
contents: read
26+
runs-on: ubuntu-24.04
27+
timeout-minutes: 30
28+
# Make warnings errors, this is to prevent warnings slipping through.
29+
# This is done globally to prevent rebuilds when the RUSTFLAGS env variable changes.
30+
env:
31+
RUSTFLAGS: "-D warnings"
32+
strategy:
33+
fail-fast: false
34+
35+
steps:
36+
# Install dependencies
37+
- name: "Install dependencies Ubuntu"
38+
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends build-essential pkg-config openssl libssl-dev
39+
# End Install dependencies
40+
41+
42+
# Install Rust with clippy
43+
- name: "Install rust-toolchain version"
44+
uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable at Mar 18, 2025, 8:14 PM GMT+1
45+
with:
46+
components: clippy
47+
# End Install Rust with clippy
48+
49+
# Show environment
50+
- name: "Show environment"
51+
run: |
52+
rustc -vV
53+
cargo -vV
54+
# End Show environment
55+
56+
# Checkout the repo
57+
- name: "Checkout"
58+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
59+
with:
60+
persist-credentials: false
61+
# End Checkout the repo
62+
63+
# Enable Rust Caching
64+
- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
65+
# End Enable Rust Caching
66+
67+
# Run cargo commands
68+
- name: "Run cargo update"
69+
id: run_cargo_update
70+
if: ${{ always() }}
71+
run: |
72+
cargo update --verbose
73+
74+
- name: "cargo test"
75+
id: run_cargo_test
76+
if: ${{ always() }}
77+
run: |
78+
cargo test --verbose
79+
80+
- name: "Build all features"
81+
id: build_all_features
82+
if: ${{ always() }}
83+
run: |
84+
cargo build --all-features --verbose
85+
86+
- name: "Build otp example"
87+
id: build_example_otp
88+
if: ${{ always() }}
89+
run: |
90+
cargo build --example otp
91+
92+
- name: "Build otp_async example"
93+
id: build_example_otp_async
94+
if: ${{ always() }}
95+
run: |
96+
cargo build --example otp_async
97+
98+
- name: "Build otp_custom example"
99+
id: build_example_otp_custom
100+
if: ${{ always() }}
101+
run: |
102+
cargo build --example otp_custom
103+
104+
- name: "Build otp_with_proxy example"
105+
id: build_example_otp_with_proxy
106+
if: ${{ always() }}
107+
run: |
108+
cargo build --example otp_with_proxy
109+
# End Run cargo tests
110+
111+
112+
# Run cargo clippy, and fail on warnings
113+
- name: "Run clippy"
114+
id: run_cargo_clippy
115+
if: ${{ always() }}
116+
run: |
117+
cargo clippy --all-features
118+
119+
- name: "Run clippy"
120+
id: run_cargo_clippy_examples
121+
if: ${{ always() }}
122+
run: |
123+
cargo clippy --examples
124+
# End Run cargo clippy
125+
126+
127+
# Check for any previous failures, if there are stop, else continue.
128+
# This is useful so all test/clippy/fmt actions are done, and they can all be addressed
129+
- name: "Some checks failed"
130+
if: ${{ failure() }}
131+
env:
132+
RUN_CARGO_UPDATE: ${{ steps.run_cargo_update.outcome }}
133+
RUN_CARGO_TEST: ${{ steps.run_cargo_test.outcome }}
134+
BUILD_ALL: ${{ steps.build_all_features.outcome }}
135+
EXAMPLE_OTP: ${{ steps.build_example_otp.outcome }}
136+
EXAMPLE_OTP_ASYNC: ${{ steps.build_example_otp_async.outcome }}
137+
EXAMPLE_OTP_CUSTOM: ${{ steps.build_example_otp_custom.outcome }}
138+
EXAMPLE_OTP_WITH_PROXY: ${{ steps.build_example_otp_with_proxy.outcome }}
139+
RUN_CARGO_CLIPPY: ${{ steps.run_cargo_clippy.outcome }}
140+
RUN_CARGO_CLIPPY_EXAMPLES: ${{ steps.run_cargo_clippy_examples.outcome }}
141+
run: |
142+
echo "### :x: Checks Failed!" >> ${GITHUB_STEP_SUMMARY}
143+
echo "" >> ${GITHUB_STEP_SUMMARY}
144+
echo "|Job|Status|" >> ${GITHUB_STEP_SUMMARY}
145+
echo "|---|------|" >> ${GITHUB_STEP_SUMMARY}
146+
echo "|cargo update|${RUN_CARGO_UPDATE}|" >> ${GITHUB_STEP_SUMMARY}
147+
echo "|cargo test|${RUN_CARGO_TEST}|" >> ${GITHUB_STEP_SUMMARY}
148+
echo "|build all features|${BUILD_ALL}|" >> ${GITHUB_STEP_SUMMARY}
149+
echo "|build example otp|${EXAMPLE_OTP}|" >> ${GITHUB_STEP_SUMMARY}
150+
echo "|build example otp_async|${EXAMPLE_OTP_ASYNC}|" >> ${GITHUB_STEP_SUMMARY}
151+
echo "|build example otp_custom|${EXAMPLE_OTP_CUSTOM}|" >> ${GITHUB_STEP_SUMMARY}
152+
echo "|build example otp_with_proxy|${EXAMPLE_OTP_WITH_PROXY}|" >> ${GITHUB_STEP_SUMMARY}
153+
echo "|clippy all features|${RUN_CARGO_CLIPPY}|" >> ${GITHUB_STEP_SUMMARY}
154+
echo "|clippy examples|${RUN_CARGO_CLIPPY_EXAMPLES}|" >> ${GITHUB_STEP_SUMMARY}
155+
echo "" >> ${GITHUB_STEP_SUMMARY}
156+
echo "Please check the failed jobs and fix where needed." >> ${GITHUB_STEP_SUMMARY}
157+
echo "" >> ${GITHUB_STEP_SUMMARY}
158+
exit 1
159+
160+
161+
# If all was ok, then we show this
162+
- name: "All checks passed"
163+
if: ${{ success() }}
164+
run: |
165+
echo "### :tada: Checks Passed!" >> ${GITHUB_STEP_SUMMARY}
166+
echo "" >> ${GITHUB_STEP_SUMMARY}

Cargo.toml

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,103 @@
11
[package]
2-
name = "yubico"
3-
version = "0.11.0"
4-
authors = ["Flavio Oliveira <[email protected]>", "Pierre Larger <[email protected]>"]
5-
edition = "2018"
2+
name = "yubico_ng"
3+
version = "0.13.0"
4+
authors = ["Mathijs van Veluw <[email protected]>"]
5+
edition = "2021"
6+
rust-version = "1.81.0"
67

78
description = "Yubikey client API library"
89
license = "MIT OR Apache-2.0"
910
keywords = ["yubikey", "authentication", "encryption", "OTP", "Challenge-Response"]
1011
categories = ["authentication"]
11-
repository = "https://github.com/wisespace-io/yubico-rs"
12+
repository = "https://github.com/BlackDex/yubico-rs"
1213
readme = "README.md"
1314

14-
[badges]
15-
travis-ci = { repository = "wisespace-io/yubico-rs" }
16-
1715
[lib]
18-
name = "yubico"
16+
name = "yubico_ng"
1917
path = "src/lib.rs"
2018

2119
[dependencies]
22-
base64 = "0.13"
20+
base64 = "0.22"
2321
futures = { version = "0.3", optional = true }
2422
hmac = "0.12"
25-
rand = "0.8"
26-
reqwest = { version = "0.11", features = ["blocking"], default-features = false }
23+
rand = "0.9"
24+
reqwest = { version = "0.12", features = ["blocking"], default-features = false }
2725
sha1 = "0.10"
28-
threadpool = "1.7"
26+
threadpool = "1.8"
2927
form_urlencoded = "1"
3028

3129
[dev-dependencies]
32-
tokio = { version = "1.1", features = ["macros"] }
30+
tokio = { version = "1.44", features = ["macros", "rt-multi-thread"] }
3331
futures = "0.3"
3432

3533
[features]
3634
default = ["online-tokio", "native-tls"]
3735
online-tokio = ["futures"]
38-
rustls-tls = ["reqwest/rustls-tls"]
3936
native-tls = ["reqwest/native-tls"]
37+
rustls-tls = ["reqwest/rustls-tls"]
38+
39+
# Linting config
40+
# https://doc.rust-lang.org/rustc/lints/groups.html
41+
[workspace.lints.rust]
42+
# Forbid
43+
unsafe_code = "forbid"
44+
non_ascii_idents = "forbid"
45+
46+
# Deny
47+
deprecated_in_future = "deny"
48+
future_incompatible = { level = "deny", priority = -1 }
49+
keyword_idents = { level = "deny", priority = -1 }
50+
let_underscore = { level = "deny", priority = -1 }
51+
noop_method_call = "deny"
52+
refining_impl_trait = { level = "deny", priority = -1 }
53+
rust_2018_idioms = { level = "deny", priority = -1 }
54+
rust_2021_compatibility = { level = "deny", priority = -1 }
55+
rust_2024_compatibility = { level = "deny", priority = -1 }
56+
single_use_lifetimes = "deny"
57+
trivial_casts = "deny"
58+
trivial_numeric_casts = "deny"
59+
unused = { level = "deny", priority = -1 }
60+
unused_import_braces = "deny"
61+
unused_lifetimes = "deny"
62+
unused_qualifications = "deny"
63+
variant_size_differences = "deny"
64+
65+
# https://rust-lang.github.io/rust-clippy/stable/index.html
66+
[workspace.lints.clippy]
67+
# Warn
68+
dbg_macro = "warn"
69+
todo = "warn"
70+
71+
# Deny
72+
case_sensitive_file_extension_comparisons = "deny"
73+
cast_lossless = "deny"
74+
clone_on_ref_ptr = "deny"
75+
equatable_if_let = "deny"
76+
filter_map_next = "deny"
77+
float_cmp_const = "deny"
78+
inefficient_to_string = "deny"
79+
iter_on_empty_collections = "deny"
80+
iter_on_single_items = "deny"
81+
linkedlist = "deny"
82+
macro_use_imports = "deny"
83+
manual_assert = "deny"
84+
manual_instant_elapsed = "deny"
85+
manual_string_new = "deny"
86+
match_on_vec_items = "deny"
87+
match_wildcard_for_single_variants = "deny"
88+
mem_forget = "deny"
89+
needless_continue = "deny"
90+
needless_lifetimes = "deny"
91+
option_option = "deny"
92+
string_add_assign = "deny"
93+
string_to_string = "deny"
94+
unnecessary_join = "deny"
95+
unnecessary_self_imports = "deny"
96+
unnested_or_patterns = "deny"
97+
unused_async = "deny"
98+
unused_self = "deny"
99+
verbose_file_reads = "deny"
100+
zero_sized_map_values = "deny"
101+
102+
[lints]
103+
workspace = true

Dockerfile

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1+
# Change to build a different example, like otp_async
2+
ARG EXAMPLE=otp
3+
14
FROM rust:alpine as base
2-
RUN apk update \
3-
&& apk add \
4-
git \
5-
gcc \
6-
g++ \
7-
openssl \
8-
openssl-dev \
9-
pkgconfig
5+
ARG EXAMPLE
6+
7+
RUN apk --no-cache add \
8+
git \
9+
gcc \
10+
g++ \
11+
openssl \
12+
openssl-dev \
13+
pkgconfig
1014

1115
COPY . /src
1216

13-
RUN rustup update 1.64 && rustup default 1.64
17+
WORKDIR /src
1418

15-
RUN cd /src && \
16-
RUSTFLAGS="-C target-feature=-crt-static" cargo build --release --example otp
19+
ENV RUSTFLAGS="-C target-feature=-crt-static"
20+
RUN cargo build \
21+
--release \
22+
--example "${EXAMPLE}"
1723

18-
FROM alpine as tool
24+
FROM alpine:3
25+
ARG EXAMPLE
26+
RUN apk --no-cache add \
27+
libgcc \
28+
pcsc-lite-dev
1929

20-
RUN apk update && \
21-
apk add \
22-
libgcc \
23-
pcsc-lite-dev
30+
COPY --from=base "/src/target/release/examples/${EXAMPLE}" /usr/local/bin/otp
2431

25-
COPY --from=base /src/target/release/examples/otp /usr/local/bin
26-
ENTRYPOINT [ "otp" ]
32+
ENV RUST_BACKTRACE=1
33+
ENTRYPOINT [ "/usr/local/bin/otp" ]

Dockerfile.static

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Change to build a different example, like otp_async
2+
ARG EXAMPLE=otp
3+
4+
FROM rust:alpine as base
5+
ARG EXAMPLE
6+
7+
RUN apk --no-cache add \
8+
git \
9+
gcc \
10+
g++ \
11+
openssl-dev \
12+
openssl-libs-static \
13+
pkgconfig
14+
15+
COPY . /src
16+
17+
WORKDIR /src
18+
19+
# Force a static binary
20+
ENV RUSTFLAGS="-C target-feature=+crt-static"
21+
22+
# Ensure OpenSSL is linked statically
23+
ENV OPENSSL_STATIC=1 \
24+
PKG_CONFIG_ALLOW_CROSS=1 \
25+
PKG_CONFIG_ALL_STATIC=1
26+
27+
RUN cargo build \
28+
--release \
29+
--target=x86_64-unknown-linux-musl \
30+
--example "${EXAMPLE}"
31+
32+
FROM scratch
33+
ARG EXAMPLE
34+
35+
COPY --from=base "/src/target/x86_64-unknown-linux-musl/release/examples/${EXAMPLE}" /otp
36+
37+
# Copy the ca-certificates.crt from base so certificates can be validated
38+
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
39+
40+
ENV RUST_BACKTRACE=1
41+
ENTRYPOINT [ "/otp" ]

0 commit comments

Comments
 (0)