55 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg" ,
66 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
77) ]
8- #![ warn( rust_2018_idioms, missing_docs) ]
8+ #![ warn(
9+ clippy:: cast_lossless,
10+ clippy:: cast_possible_truncation,
11+ clippy:: cast_possible_wrap,
12+ clippy:: cast_precision_loss,
13+ clippy:: cast_sign_loss,
14+ clippy:: checked_conversions,
15+ clippy:: implicit_saturating_sub,
16+ clippy:: panic,
17+ clippy:: panic_in_result_fn,
18+ clippy:: unwrap_used,
19+ missing_docs,
20+ rust_2018_idioms,
21+ unused_lifetimes,
22+ unused_qualifications
23+ ) ]
924
1025//! ## Usage (simple with default params)
1126//!
5570//! # }
5671//! ```
5772
73+ // Call sites which cast `u32` to `usize` and are annotated with
74+ // allow(clippy::cast_possible_truncation) need this check to avoid truncation.
75+ #[ cfg( not( any( target_pointer_width = "32" , target_pointer_width = "64" ) ) ) ]
76+ compile_error ! ( "this crate builds on 32-bit and 64-bit platforms only" ) ;
77+
5878#[ cfg( feature = "alloc" ) ]
5979#[ macro_use]
6080extern crate alloc;
@@ -63,10 +83,10 @@ extern crate alloc;
6383extern crate std;
6484
6585mod algorithm;
86+ mod blake2b_long;
6687mod block;
6788mod error;
6889mod params;
69- mod variable_hash;
7090mod version;
7191
7292pub use crate :: {
@@ -84,11 +104,8 @@ pub use {
84104 password_hash:: { self , PasswordHash , PasswordHasher , PasswordVerifier } ,
85105} ;
86106
87- use crate :: variable_hash:: blake2b_long;
88- use blake2:: {
89- digest:: { self , Output } ,
90- Blake2b512 , Digest ,
91- } ;
107+ use crate :: blake2b_long:: blake2b_long;
108+ use blake2:: { digest, Blake2b512 , Digest } ;
92109
93110#[ cfg( all( feature = "alloc" , feature = "password-hash" ) ) ]
94111use password_hash:: { Decimal , Ident , ParamsString , Salt } ;
@@ -236,7 +253,7 @@ impl<'key> Argon2<'key> {
236253 self . fill_blocks ( memory_blocks. as_mut ( ) , initial_hash)
237254 }
238255
239- #[ allow( unused_mut) ]
256+ #[ allow( clippy :: cast_possible_truncation , unused_mut) ]
240257 fn fill_blocks (
241258 & self ,
242259 memory_blocks : & mut [ Block ] ,
@@ -248,23 +265,23 @@ impl<'key> Argon2<'key> {
248265 . ok_or ( Error :: MemoryTooLittle ) ?;
249266
250267 let segment_length = self . params . segment_length ( ) ;
251- let iterations = usize :: try_from ( self . params . t_cost ( ) ) . unwrap ( ) ;
268+ let iterations = self . params . t_cost ( ) as usize ;
252269 let lane_length = self . params . lane_length ( ) ;
253270 let lanes = self . params . lanes ( ) ;
254271
255272 // Initialize the first two blocks in each lane
256273 for ( l, lane) in memory_blocks. chunks_exact_mut ( lane_length) . enumerate ( ) {
257274 for ( i, block) in lane[ ..2 ] . iter_mut ( ) . enumerate ( ) {
258- let i = u32 :: try_from ( i ) . unwrap ( ) ;
259- let l = u32 :: try_from ( l ) . unwrap ( ) ;
275+ let i = i as u32 ;
276+ let l = l as u32 ;
260277
261278 let inputs = & [
262279 initial_hash. as_ref ( ) ,
263280 & i. to_le_bytes ( ) [ ..] ,
264281 & l. to_le_bytes ( ) [ ..] ,
265282 ] ;
266283
267- blake2b_long ( inputs, block. as_mut_bytes ( ) ) . unwrap ( ) ;
284+ blake2b_long ( inputs, block. as_mut_bytes ( ) ) ? ;
268285 }
269286 }
270287
@@ -440,7 +457,8 @@ impl<'key> Argon2<'key> {
440457 }
441458
442459 /// Hashes all the inputs into `blockhash[PREHASH_DIGEST_LEN]`.
443- fn initial_hash ( & self , pwd : & [ u8 ] , salt : & [ u8 ] , out : & [ u8 ] ) -> Output < Blake2b512 > {
460+ #[ allow( clippy:: cast_possible_truncation) ]
461+ fn initial_hash ( & self , pwd : & [ u8 ] , salt : & [ u8 ] , out : & [ u8 ] ) -> digest:: Output < Blake2b512 > {
444462 let mut digest = Blake2b512 :: new ( ) ;
445463 digest. update ( & self . params . p_cost ( ) . to_le_bytes ( ) ) ;
446464 digest. update ( & ( out. len ( ) as u32 ) . to_le_bytes ( ) ) ;
0 commit comments