Skip to content

Commit d2432cf

Browse files
committed
Add testing, fix clippy lints
1 parent 471582d commit d2432cf

5 files changed

Lines changed: 147 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUSTFLAGS: -D warnings
12+
13+
jobs:
14+
test:
15+
name: Test
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Install Rust toolchain
22+
uses: dtolnay/rust-toolchain@stable
23+
24+
- name: Cache cargo registry
25+
uses: actions/cache@v4
26+
with:
27+
path: ~/.cargo/registry
28+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
29+
30+
- name: Cache cargo index
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.cargo/git
34+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
35+
36+
- name: Cache cargo build
37+
uses: actions/cache@v4
38+
with:
39+
path: target
40+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
41+
42+
- name: Run tests (default features)
43+
run: cargo test
44+
45+
- name: Run tests (all features)
46+
run: cargo test --all-features
47+
48+
- name: Run tests (no default features)
49+
run: cargo test --no-default-features
50+
51+
clippy:
52+
name: Clippy
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Install Rust toolchain
59+
uses: dtolnay/rust-toolchain@stable
60+
with:
61+
components: clippy
62+
63+
- name: Run clippy
64+
run: cargo clippy --all-targets --all-features -- -D warnings
65+
66+
fmt:
67+
name: Formatting
68+
runs-on: ubuntu-latest
69+
70+
steps:
71+
- uses: actions/checkout@v4
72+
73+
- name: Install Rust toolchain
74+
uses: dtolnay/rust-toolchain@stable
75+
with:
76+
components: rustfmt
77+
78+
- name: Check formatting
79+
run: cargo fmt --all -- --check
80+
81+
doc:
82+
name: Documentation
83+
runs-on: ubuntu-latest
84+
85+
steps:
86+
- uses: actions/checkout@v4
87+
88+
- name: Install Rust toolchain
89+
uses: dtolnay/rust-toolchain@stable
90+
91+
- name: Build documentation
92+
run: cargo doc --all-features --no-deps
93+
env:
94+
RUSTDOCFLAGS: -D warnings
95+
96+
miri:
97+
name: Miri
98+
runs-on: ubuntu-latest
99+
100+
steps:
101+
- uses: actions/checkout@v4
102+
103+
- name: Install Rust toolchain
104+
uses: dtolnay/rust-toolchain@nightly
105+
with:
106+
components: miri
107+
108+
- name: Run Miri
109+
run: cargo miri test
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Security Audit
2+
3+
on:
4+
schedule:
5+
# Run weekly on Sunday at 00:00 UTC
6+
- cron: '0 0 * * 0'
7+
push:
8+
paths:
9+
- '**/Cargo.toml'
10+
- '**/Cargo.lock'
11+
pull_request:
12+
paths:
13+
- '**/Cargo.toml'
14+
- '**/Cargo.lock'
15+
16+
jobs:
17+
security-audit:
18+
name: Cargo Audit
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Install Rust toolchain
25+
uses: dtolnay/rust-toolchain@stable
26+
27+
- name: Install cargo-audit
28+
run: cargo install cargo-audit
29+
30+
- name: Run cargo audit
31+
run: cargo audit

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ let result = hasher.finalize();
9393

9494
Licensed under either of:
9595

96-
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
97-
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
96+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
97+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
9898

9999
at your option.
100100

src/hash_impl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ impl Hasher {
144144
// Full buffer, absorb it.
145145
if self.buffer_len == RATE {
146146
let state_bytes = self.state.as_bytes_mut();
147-
for i in 0..RATE {
148-
state_bytes[i] ^= self.buffer[i];
147+
for (i, byte) in self.buffer.iter().enumerate().take(RATE) {
148+
state_bytes[i] ^= byte;
149149
}
150150
gimli(&mut self.state);
151151

@@ -158,8 +158,8 @@ impl Hasher {
158158
pub fn finalize(mut self) -> [u8; HASH_SIZE] {
159159
// Process buffered data with padding.
160160
let state_bytes = self.state.as_bytes_mut();
161-
for i in 0..self.buffer_len {
162-
state_bytes[i] ^= self.buffer[i];
161+
for (i, byte) in self.buffer.iter().enumerate().take(self.buffer_len) {
162+
state_bytes[i] ^= byte;
163163
}
164164

165165
// Padding: domain separation at current position, padding marker at end of rate.

src/rustcrypto_aead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mod tests {
134134
let plaintext = *b"Hello, RustCrypto AEAD!";
135135
let aad = b"associated data";
136136

137-
let mut ciphertext = plaintext.clone();
137+
let mut ciphertext = plaintext;
138138
let tag = cipher
139139
.encrypt_in_place_detached(&nonce, aad, &mut ciphertext)
140140
.expect("encryption failed");

0 commit comments

Comments
 (0)