Skip to content

Commit 4661ddf

Browse files
authored
ocb3: enable and fix workspace-level lints (#848)
1 parent c821431 commit 4661ddf

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

ocb3/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ bytes = ["aead/bytes"]
3737
getrandom = ["aead/getrandom"]
3838
rand_core = ["aead/rand_core"]
3939

40+
[lints]
41+
workspace = true
42+
4043
[package.metadata.docs.rs]
4144
all-features = true
42-
rustdoc-args = ["--cfg", "docsrs"]

ocb3/src/lib.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
66
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
77
)]
8-
#![deny(unsafe_code)]
9-
#![warn(missing_docs, rust_2018_idioms)]
8+
#![allow(clippy::explicit_counter_loop)]
109

1110
/// Constants used, reexported for convenience.
1211
pub mod consts {
@@ -28,7 +27,7 @@ use cipher::{
2827
consts::{U2, U12, U16},
2928
typenum::Prod,
3029
};
31-
use core::marker::PhantomData;
30+
use core::{fmt, marker::PhantomData};
3231
use dbl::Dbl;
3332
use subtle::ConstantTimeEq;
3433

@@ -204,7 +203,7 @@ where
204203
) -> aead::Result<aead::Tag<Self>> {
205204
let max_len = 1 << (L_TABLE_SIZE + 4);
206205
if (buffer.len() >= max_len) || (associated_data.len() >= max_len) {
207-
return Err(aead::Error);
206+
return Err(Error);
208207
}
209208

210209
// First, try to process many blocks at once.
@@ -287,7 +286,7 @@ where
287286
) -> aead::Result<aead::Tag<Self>> {
288287
let max_len = 1 << (L_TABLE_SIZE + 4);
289288
if (buffer.len() > max_len) || (associated_data.len() > max_len) {
290-
return Err(aead::Error);
289+
return Err(Error);
291290
}
292291

293292
// First, try to process many blocks at once.
@@ -477,6 +476,18 @@ where
477476
}
478477
}
479478

479+
impl<Cipher, NonceSize, TagSize, const L_TABLE_SIZE: usize> fmt::Debug
480+
for Ocb3<Cipher, NonceSize, TagSize, L_TABLE_SIZE>
481+
where
482+
Cipher: KeySizeUser,
483+
NonceSize: sealed::NonceSizes,
484+
TagSize: sealed::TagSizes,
485+
{
486+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
487+
f.debug_struct("Ocb3").finish_non_exhaustive()
488+
}
489+
}
490+
480491
/// Computes key-dependent variables defined in
481492
/// https://www.rfc-editor.org/rfc/rfc7253.html#section-4.1
482493
fn key_dependent_variables<Cipher, const L_TABLE_SIZE: usize>(
@@ -494,13 +505,14 @@ where
494505
#[allow(clippy::needless_range_loop)]
495506
for i in 0..L_TABLE_SIZE {
496507
ll_i = ll_i.dbl();
497-
ll[i] = ll_i
508+
ll[i] = ll_i;
498509
}
499510
(ll_star, ll_dollar, ll)
500511
}
501512

502513
/// Computes nonce-dependent variables as defined
503514
/// in https://www.rfc-editor.org/rfc/rfc7253.html#section-4.2
515+
#[allow(clippy::cast_possible_truncation, reason = "TODO")]
504516
fn nonce_dependent_variables<
505517
Cipher: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,
506518
NonceSize: sealed::NonceSizes,
@@ -540,6 +552,7 @@ fn nonce_dependent_variables<
540552

541553
/// Computes the initial offset as defined
542554
/// in https://www.rfc-editor.org/rfc/rfc7253.html#section-4.2
555+
#[allow(clippy::unwrap_used)]
543556
fn initial_offset<
544557
Cipher: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,
545558
NonceSize: sealed::NonceSizes,

ocb3/tests/kats.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
//! OCB3 Known Answer Tests (KATs).
2+
13
#![allow(non_snake_case)]
4+
#![allow(clippy::unwrap_used, reason = "tests")]
25

36
use aead::{
47
AeadInOut, KeyInit,
@@ -103,8 +106,8 @@ type Aes256Ocb3Tag96 = Ocb3<Aes256, U12, U12>;
103106
type Aes128Ocb3Tag64 = Ocb3<Aes128, U12, U8>;
104107
type Aes192Ocb3Tag64 = Ocb3<Aes192, U12, U8>;
105108
type Aes256Ocb3Tag64 = Ocb3<Aes256, U12, U8>;
106-
type Aes128Ocb3 = Ocb3<aes::Aes128, U12>;
107-
type Aes256Ocb3 = Ocb3<aes::Aes256, U12>;
109+
type Aes128Ocb3 = Ocb3<Aes128, U12>;
110+
type Aes256Ocb3 = Ocb3<Aes256, U12>;
108111

109112
/// Test vectors from Page 18 of https://www.rfc-editor.org/rfc/rfc7253.html#appendix-A
110113
#[test]

ocb3/tests/len_check.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Length check tests.
2+
13
use aead::{
24
AeadInOut, KeyInit,
35
consts::{U12, U16},

0 commit comments

Comments
 (0)