style: crank clippy to pedantic+nursery and fix all lints
Enable the full clippy all + pedantic + nursery groups as workspace warnings, with a small documented allow-list for the pedantic/nursery lints this project intentionally does not follow (rustdoc-style requirements, deliberate numeric casts in the protocol/UI layers, and a few noisy nursery lints). Also enable the rust unused_lifetimes and unsafe_op_in_unsafe_fn lints. Fixed every resulting warning (527 -> 0) mechanically per clippy's suggestions: inline format args, const fns, item ordering, let-else, redundant clones, map_or, cast_lossless, Eq derives, associated-fn conversions for methods that never used self, and removing unnecessary Result wrappers whose call sites could never propagate an error. No runtime behavior changed; cargo fmt applied. cargo clippy --workspace --all-targets: 0 warnings. All tests pass.
This commit is contained in:
@@ -22,7 +22,7 @@ use std::convert::TryInto;
|
||||
* K[i] = floor(2^32 * abs(sin(i+1)))
|
||||
*/
|
||||
fn table_construction_function(i: u32) -> u32 {
|
||||
let x: f64 = i as f64;
|
||||
let x: f64 = f64::from(i);
|
||||
let sin_eval = x.sin().abs();
|
||||
// note: 4294967296 == 2^32
|
||||
(4294967296.0 * sin_eval) as u32
|
||||
@@ -36,19 +36,19 @@ fn table_construction_function(i: u32) -> u32 {
|
||||
* algorithm, and they are performed a number of times to end
|
||||
* up with our final result.
|
||||
*/
|
||||
fn f(x: u32, y: u32, z: u32) -> u32 {
|
||||
const fn f(x: u32, y: u32, z: u32) -> u32 {
|
||||
x & y | !x & z
|
||||
}
|
||||
|
||||
fn g(x: u32, y: u32, z: u32) -> u32 {
|
||||
const fn g(x: u32, y: u32, z: u32) -> u32 {
|
||||
x & z | y & !z
|
||||
}
|
||||
|
||||
fn h(x: u32, y: u32, z: u32) -> u32 {
|
||||
const fn h(x: u32, y: u32, z: u32) -> u32 {
|
||||
x ^ y ^ z
|
||||
}
|
||||
|
||||
fn i(x: u32, y: u32, z: u32) -> u32 {
|
||||
const fn i(x: u32, y: u32, z: u32) -> u32 {
|
||||
y ^ (x | !z)
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ fn vec_to_array<T, const N: usize>(v: Vec<T>) -> [T; N] {
|
||||
* table[i] is an entry generated by our sine function, s is an unsigned
|
||||
* integer, and a,b,c,d are our 32 bit registers we perform operations on.
|
||||
*/
|
||||
fn round_one_operations(
|
||||
const fn round_one_operations(
|
||||
mut a: u32,
|
||||
mut b: u32,
|
||||
mut c: u32,
|
||||
@@ -115,7 +115,7 @@ fn round_one_operations(
|
||||
* Round 2 is equivalent to round 1, except we swap out our f function for g as such:
|
||||
* a = b + ((a + g(b,c,d) + x[k] + table[i]) <<< s);
|
||||
*/
|
||||
fn round_two_operations(
|
||||
const fn round_two_operations(
|
||||
mut a: u32,
|
||||
mut b: u32,
|
||||
mut c: u32,
|
||||
@@ -161,7 +161,7 @@ fn round_two_operations(
|
||||
* Round 3 is equivalent to round 1, except we swap out our f function for h as such:
|
||||
* a = b + ((a + h(b,c,d) + x[k] + table[i]) <<< s);
|
||||
*/
|
||||
fn round_three_operations(
|
||||
const fn round_three_operations(
|
||||
mut a: u32,
|
||||
mut b: u32,
|
||||
mut c: u32,
|
||||
@@ -207,7 +207,7 @@ fn round_three_operations(
|
||||
* Round 4 is equivalent to round 1, except we swap out our f function for h as such:
|
||||
* a = b + ((a + i(b,c,d) + x[k] + table[i]) <<< s);
|
||||
*/
|
||||
fn round_four_operations(
|
||||
const fn round_four_operations(
|
||||
mut a: u32,
|
||||
mut b: u32,
|
||||
mut c: u32,
|
||||
@@ -287,7 +287,7 @@ fn compute_md5_digest(mut v: Vec<u8>) -> String {
|
||||
let table = construct_value_table();
|
||||
|
||||
// let M[0 .. N-1] = words of resulting message, where N is multiple of 16
|
||||
for chunk in v.chunks_exact_mut(64) {
|
||||
for chunk in v.as_chunks_mut::<64>().0 {
|
||||
let x = convert_u8_chunk_to_u32(chunk);
|
||||
|
||||
// set all values of a,b,c,d to aa,bb,cc, and dd respectively.
|
||||
@@ -378,7 +378,7 @@ fn bit_padding(input: &str) -> Vec<u8> {
|
||||
input_vector
|
||||
}
|
||||
|
||||
fn split_u64_to_u8_array(s: u64) -> [u8; 8] {
|
||||
const fn split_u64_to_u8_array(s: u64) -> [u8; 8] {
|
||||
[
|
||||
s as u8,
|
||||
(s >> 8) as u8,
|
||||
@@ -425,6 +425,7 @@ fn convert_str_to_vec(input: &str) -> Vec<u8> {
|
||||
* during our bitwise operations to retrieve our message digest.
|
||||
* (This is a simplification, but describes the core functionality)
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn md5(input: &str) -> String {
|
||||
let input_vec = bit_padding(input);
|
||||
compute_md5_digest(input_vec)
|
||||
@@ -454,7 +455,7 @@ fn lowercase_alphabet_correct_hash() {
|
||||
assert_eq!(
|
||||
"c3fcd3d76192e4007dfb496cca67e13b",
|
||||
md5("abcdefghijklmnopqrstuvwxyz")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user