Skip to content

Commit

Permalink
Enforce clippy::cast_possible_truncation.
Browse files Browse the repository at this point in the history
For now, just put `#[allow(...)]` directives in the places where the
conversions are done. We'll follow up in the future with the correct
replacement for `as` for each case, as several PRs.
  • Loading branch information
briansmith committed Oct 31, 2023
1 parent 6b06550 commit 0ed36a9
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/aead/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn set_encrypt_key(
key: &mut AES_KEY,
) -> Result<(), error::Unspecified> {
// Unusually, in this case zero means success and non-zero means failure.
#[allow(clippy::cast_possible_truncation)]
if 0 == unsafe { f(bytes.as_ptr(), key_bits.as_usize_bits() as c::uint, key) } {
Ok(())
} else {
Expand Down Expand Up @@ -111,6 +112,7 @@ fn ctr32_encrypt_blocks_(
assert_eq!(in_out_len % BLOCK_LEN, 0);

let blocks = in_out_len / BLOCK_LEN;
#[allow(clippy::cast_possible_truncation)]
let blocks_u32 = blocks as u32;
assert_eq!(blocks, polyfill::usize_from_u32(blocks_u32));

Expand Down
1 change: 1 addition & 0 deletions src/aead/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ mod tests {
// behavior of ChaCha20 implementation changes dependent on the
// length of the input.
for len in 0..=input.len() {
#[allow(clippy::cast_possible_truncation)]
chacha20_test_case_inner(
&key,
&nonce,
Expand Down
1 change: 1 addition & 0 deletions src/aead/gcm/gcm_nohw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::polyfill::ArraySplitMap;

#[cfg(target_pointer_width = "64")]
fn gcm_mul64_nohw(a: u64, b: u64) -> (u64, u64) {
#[allow(clippy::cast_possible_truncation)]

Check warning on line 30 in src/aead/gcm/gcm_nohw.rs

View check run for this annotation

Codecov / codecov/patch

src/aead/gcm/gcm_nohw.rs#L30

Added line #L30 was not covered by tests
#[inline(always)]
fn lo(a: u128) -> u64 {
a as u64
Expand Down
2 changes: 2 additions & 0 deletions src/ec/suite_b/ecdsa/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

//! ECDSA Signatures using the P-256 and P-384 curves.
#![allow(clippy::cast_possible_truncation)] // XXX

use super::digest_scalar::digest_scalar;
use crate::{
arithmetic::montgomery::*,
Expand Down
1 change: 1 addition & 0 deletions src/ec/suite_b/ops/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ fn p256_scalar_inv_to_mont(a: &Scalar<Unencoded>) -> Scalar<R> {
// 1011110011100110111110101010110110100111000101111001111010000100
// 1111001110111001110010101100001011111100011000110010010101001111

#[allow(clippy::cast_possible_truncation)]
static REMAINING_WINDOWS: [(u8, u8); 26] = [
(6, B_101111 as u8),
(2 + 3, B_111 as u8),
Expand Down
1 change: 1 addition & 0 deletions src/ec/suite_b/ops/p384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ fn p384_scalar_inv_to_mont(a: &Scalar<Unencoded>) -> Scalar<R> {
// 0101100000011010000011011011001001001000101100001010011101111010
// 1110110011101100000110010110101011001100110001010010100101110001

#[allow(clippy::cast_possible_truncation)]
static REMAINING_WINDOWS: [(u8, u8); 39] = [
(2, B_11 as u8),
(3 + 3, B_111 as u8),
Expand Down
1 change: 1 addition & 0 deletions src/io/der_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub(crate) fn write_all(tag: Tag, write_value: &dyn Fn(&mut dyn Accumulator)) ->
output.into()
}

#[allow(clippy::cast_possible_truncation)]
fn write_tlv<F>(output: &mut dyn Accumulator, tag: Tag, write_value: F)
where
F: Fn(&mut dyn Accumulator),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#![warn(
clippy::unnecessary_cast,
clippy::cast_lossless,
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_precision_loss,
clippy::cast_sign_loss
Expand Down

0 comments on commit 0ed36a9

Please sign in to comment.