chore: fix warnings
This commit is contained in:
+31
-33
@@ -1,23 +1,19 @@
|
||||
use std::convert::TryInto;
|
||||
/**
|
||||
*
|
||||
* The MD5 Message-Digest Algorithm, written in Rust.
|
||||
* Implemented by michael dimovich (@mdimovich)
|
||||
*
|
||||
* The purpose of this code is to act as a learning resource
|
||||
* for the md5 message digest algorithm. I wanted to provide
|
||||
* a straightforward walk-through of the md5 algorithm using
|
||||
* Rust.
|
||||
*
|
||||
* This code was implemented using the original md5 message digest
|
||||
* RFC, written by R. Rivest in April 1992.
|
||||
*
|
||||
* For more information about the md5 algorithm, or the original C
|
||||
* source code implementation, please reference RFC 1321.
|
||||
*
|
||||
* (source: https://datatracker.ietf.org/doc/html/rfc1321)
|
||||
*
|
||||
*/
|
||||
// The MD5 Message-Digest Algorithm, written in Rust.
|
||||
// Implemented by michael dimovich (@mdimovich)
|
||||
//
|
||||
// The purpose of this code is to act as a learning resource
|
||||
// for the md5 message digest algorithm. I wanted to provide
|
||||
// a straightforward walk-through of the md5 algorithm using
|
||||
// Rust.
|
||||
//
|
||||
// This code was implemented using the original md5 message digest
|
||||
// RFC, written by R. Rivest in April 1992.
|
||||
//
|
||||
// For more information about the md5 algorithm, or the original C
|
||||
// source code implementation, please reference RFC 1321.
|
||||
//
|
||||
// (source: https://datatracker.ietf.org/doc/html/rfc1321)
|
||||
|
||||
/**
|
||||
* This function is specified in the rfc as a way to generate the
|
||||
@@ -29,7 +25,7 @@ fn table_construction_function(i: u32) -> u32 {
|
||||
let x: f64 = i as f64;
|
||||
let sin_eval = x.sin().abs();
|
||||
// note: 4294967296 == 2^32
|
||||
return (4294967296.0 * sin_eval) as u32;
|
||||
(4294967296.0 * sin_eval) as u32
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +74,8 @@ fn round_one_operations(
|
||||
table: &Vec<u32>,
|
||||
x: &Vec<u32>,
|
||||
) -> [u32; 4] {
|
||||
let _ = x;
|
||||
let _ = table;
|
||||
macro_rules! round1 {
|
||||
( $a:ident, $b:ident, $c:ident, $d:ident, $k:expr, $s:expr, $i: expr ) => {
|
||||
$a = $b.wrapping_add(
|
||||
@@ -109,7 +107,7 @@ fn round_one_operations(
|
||||
round1!(c, d, a, b, 14, 17, 15);
|
||||
round1!(b, c, d, a, 15, 22, 16);
|
||||
|
||||
return [a, b, c, d];
|
||||
[a, b, c, d]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +153,7 @@ fn round_two_operations(
|
||||
round2!(c, d, a, b, 7, 14, 31);
|
||||
round2!(b, c, d, a, 12, 20, 32);
|
||||
|
||||
return [a, b, c, d];
|
||||
[a, b, c, d]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +199,7 @@ fn round_three_operations(
|
||||
round3!(c, d, a, b, 15, 16, 47);
|
||||
round3!(b, c, d, a, 2, 23, 48);
|
||||
|
||||
return [a, b, c, d];
|
||||
[a, b, c, d]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +245,7 @@ fn round_four_operations(
|
||||
round4!(c, d, a, b, 2, 15, 63);
|
||||
round4!(b, c, d, a, 9, 21, 64);
|
||||
|
||||
return [a, b, c, d];
|
||||
[a, b, c, d]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,7 +271,7 @@ fn convert_u8_chunk_to_u32(chunk: &mut [u8]) -> Vec<u32> {
|
||||
temporary_vec.clear();
|
||||
}
|
||||
}
|
||||
return x;
|
||||
x
|
||||
}
|
||||
|
||||
fn compute_md5_digest(mut v: Vec<u8>) -> String {
|
||||
@@ -344,7 +342,7 @@ fn compute_md5_digest(mut v: Vec<u8>) -> String {
|
||||
word_c.swap_bytes(),
|
||||
word_d.swap_bytes()
|
||||
);
|
||||
return message_digest;
|
||||
message_digest
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -372,11 +370,12 @@ fn bit_padding(input: &str) -> Vec<u8> {
|
||||
let length_bits_as_u8_array = split_u64_to_u8_array(bit_length);
|
||||
input_vector.extend(length_bits_as_u8_array);
|
||||
|
||||
return input_vector;
|
||||
input_vector
|
||||
}
|
||||
|
||||
fn split_u64_to_u8_array(s: u64) -> [u8; 8] {
|
||||
let u8_array = [
|
||||
|
||||
[
|
||||
s as u8,
|
||||
(s >> 8) as u8,
|
||||
(s >> 16) as u8,
|
||||
@@ -385,8 +384,7 @@ fn split_u64_to_u8_array(s: u64) -> [u8; 8] {
|
||||
(s >> 40) as u8,
|
||||
(s >> 48) as u8,
|
||||
(s >> 56) as u8,
|
||||
];
|
||||
return u8_array;
|
||||
]
|
||||
}
|
||||
|
||||
fn construct_value_table() -> Vec<u32> {
|
||||
@@ -395,7 +393,7 @@ fn construct_value_table() -> Vec<u32> {
|
||||
for i in 1..=64 {
|
||||
t.push(table_construction_function(i));
|
||||
}
|
||||
return t;
|
||||
t
|
||||
}
|
||||
|
||||
// this should only work with utf-8 encoding and not full unicode support
|
||||
@@ -403,7 +401,7 @@ fn construct_value_table() -> Vec<u32> {
|
||||
fn convert_str_to_vec(input: &str) -> Vec<u8> {
|
||||
let mut byte_vec: Vec<u8> = Vec::new();
|
||||
byte_vec.extend(input.as_bytes());
|
||||
return byte_vec;
|
||||
byte_vec
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,7 +423,7 @@ fn convert_str_to_vec(input: &str) -> Vec<u8> {
|
||||
*/
|
||||
pub fn md5(input: &str) -> String {
|
||||
let input_vec = bit_padding(input);
|
||||
return compute_md5_digest(input_vec);
|
||||
compute_md5_digest(input_vec)
|
||||
}
|
||||
#[test]
|
||||
fn a_correct_hash() {
|
||||
|
||||
Reference in New Issue
Block a user