Skip to content

Commit d92139e

Browse files
authored
aead: enable and fix workspace-level lints (#2306)
Added in #2270. See also: #2279, #2298
1 parent 593a0ea commit d92139e

4 files changed

Lines changed: 50 additions & 3 deletions

File tree

aead/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ dev = ["blobby", "alloc"]
3131
getrandom = ["common/getrandom"]
3232
rand_core = ["common/rand_core"]
3333

34+
[lints]
35+
workspace = true
36+
3437
[package.metadata.docs.rs]
3538
all-features = true

aead/src/dev.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//! Development-related functionality
2+
3+
#![allow(clippy::missing_errors_doc, reason = "dev module")]
4+
#![allow(clippy::missing_panics_doc, reason = "dev module")]
5+
#![allow(clippy::unwrap_in_result, reason = "dev module")]
6+
27
use crate::{
38
Aead, AeadInOut, Payload, Tag, TagPosition, array::typenum::Unsigned, inout::InOutBuf,
49
};
@@ -21,6 +26,7 @@ pub struct TestVector {
2126
}
2227

2328
/// Run AEAD test for the provided passing test vector
29+
#[allow(clippy::cast_possible_truncation)]
2430
pub fn pass_test<C: AeadInOut + KeyInit>(
2531
&TestVector {
2632
key,

aead/src/lib.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ pub trait Aead: AeadCore {
158158
/// AES-GCM-SIV, ChaCha20Poly1305). [`Aead`] implementations which do not
159159
/// use a postfix tag will need to override this to correctly assemble the
160160
/// ciphertext message.
161+
///
162+
/// # Errors
163+
/// AEAD algorithm implementations may return an error if the plaintext or AAD are too long.
161164
fn encrypt<'msg, 'aad>(
162165
&self,
163166
nonce: &Nonce<Self>,
@@ -181,6 +184,11 @@ pub trait Aead: AeadCore {
181184
/// AES-GCM-SIV, ChaCha20Poly1305). [`Aead`] implementations which do not
182185
/// use a postfix tag will need to override this to correctly parse the
183186
/// ciphertext message.
187+
///
188+
/// # Errors
189+
/// - if the `ciphertext` is inauthentic (i.e. tag verification failure)
190+
/// - if the `ciphertext` is too long
191+
/// - if the `aad` is too long
184192
fn decrypt<'msg, 'aad>(
185193
&self,
186194
nonce: &Nonce<Self>,
@@ -217,6 +225,9 @@ impl<T: AeadInOut> Aead for T {
217225
/// In-place and inout AEAD trait which handles the authentication tag as a return value/separate parameter.
218226
pub trait AeadInOut: AeadCore {
219227
/// Encrypt the data in the provided [`InOutBuf`], returning the authentication tag.
228+
///
229+
/// # Errors
230+
/// AEAD algorithm implementations may return an error if the plaintext or AAD are too long.
220231
fn encrypt_inout_detached(
221232
&self,
222233
nonce: &Nonce<Self>,
@@ -226,7 +237,12 @@ pub trait AeadInOut: AeadCore {
226237

227238
/// Decrypt the data in the provided [`InOutBuf`], returning an error in the event the
228239
/// provided authentication tag is invalid for the given ciphertext (i.e. ciphertext
229-
/// is modified/unauthentic)
240+
/// is modified/unauthentic).
241+
///
242+
/// # Errors
243+
/// - if the `ciphertext` is inauthentic (i.e. tag verification failure)
244+
/// - if the `ciphertext` is too long
245+
/// - if the `aad` is too long
230246
fn decrypt_inout_detached(
231247
&self,
232248
nonce: &Nonce<Self>,
@@ -242,6 +258,7 @@ pub trait AeadInOut: AeadCore {
242258
/// The exact size needed is cipher-dependent, but generally includes
243259
/// the size of an authentication tag.
244260
///
261+
/// # Errors
245262
/// Returns an error if the buffer has insufficient capacity to store the
246263
/// resulting ciphertext message.
247264
fn encrypt_in_place(
@@ -275,6 +292,9 @@ pub trait AeadInOut: AeadCore {
275292
///
276293
/// The buffer will be truncated to the length of the original plaintext
277294
/// message upon success.
295+
///
296+
/// # Errors
297+
/// - if the `ciphertext` is inauthentic (i.e. tag verification failure)
278298
fn decrypt_in_place(
279299
&self,
280300
nonce: &Nonce<Self>,
@@ -306,6 +326,7 @@ pub trait AeadInOut: AeadCore {
306326
///
307327
/// NOTE: deprecated! Please migrate to [`AeadInOut`].
308328
#[deprecated(since = "0.6.0", note = "use `AeadInOut` instead")]
329+
#[allow(clippy::missing_errors_doc)]
309330
pub trait AeadInPlace: AeadCore {
310331
/// Encrypt the given buffer containing a plaintext message in-place.
311332
#[deprecated(since = "0.6.0", note = "use `AeadInOut::encrypt_in_place` instead")]
@@ -435,10 +456,13 @@ pub trait Buffer: AsRef<[u8]> + AsMut<[u8]> {
435456
self.as_ref().is_empty()
436457
}
437458

438-
/// Extend this buffer from the given slice
459+
/// Extend this buffer from the given slice.
460+
///
461+
/// # Errors
462+
/// If the buffer has insufficient capacity.
439463
fn extend_from_slice(&mut self, other: &[u8]) -> Result<()>;
440464

441-
/// Truncate this buffer to the given size
465+
/// Truncate this buffer to the given size.
442466
fn truncate(&mut self, len: usize);
443467
}
444468

aead/tests/dummy.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
//! This module defines dummy (horribly insecure!) AEAD implementations
22
//! to test implementation of the AEAD traits and helper macros in the `dev` module.
3+
34
#![cfg(feature = "dev")]
5+
#![allow(missing_docs, reason = "tests")]
6+
#![allow(clippy::trivially_copy_pass_by_ref, reason = "tests")]
7+
#![allow(clippy::unwrap_used, reason = "tests")]
8+
49
use aead::{
510
AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser, Nonce, Result, Tag, TagPosition,
611
array::Array, consts::U8,
712
};
13+
use core::fmt;
814
use inout::InOutBuf;
915

1016
struct DummyAead {
1117
key: [u8; 8],
1218
}
1319

20+
impl fmt::Debug for DummyAead {
21+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22+
f.debug_struct("DummyAead").finish_non_exhaustive()
23+
}
24+
}
25+
1426
impl DummyAead {
1527
fn process_aad(&self, nonce: &[u8; 8], aad: &[u8]) -> u64 {
1628
let mut tag = u64::from_le_bytes(*nonce);
@@ -92,6 +104,7 @@ impl DummyAead {
92104
}
93105
}
94106

107+
#[derive(Debug)]
95108
pub struct PrefixDummyAead(DummyAead);
96109

97110
impl KeySizeUser for PrefixDummyAead {
@@ -131,6 +144,7 @@ impl AeadInOut for PrefixDummyAead {
131144
}
132145
}
133146

147+
#[derive(Debug)]
134148
pub struct PostfixDummyAead(DummyAead);
135149

136150
impl KeySizeUser for PostfixDummyAead {

0 commit comments

Comments
 (0)