chore: fix warnings
This commit is contained in:
+8
-8
@@ -79,19 +79,19 @@ impl Client {
|
||||
println!("Logging in as {}", self.username);
|
||||
if let Some(server) = &self.server {
|
||||
let result = server.login(&self.username, &self.password);
|
||||
if result.unwrap() == true {
|
||||
return Ok(true);
|
||||
if result.unwrap() {
|
||||
Ok(true)
|
||||
} else {
|
||||
return Err(std::io::Error::new(
|
||||
Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"Error logging in",
|
||||
));
|
||||
))
|
||||
}
|
||||
} else {
|
||||
return Err(std::io::Error::new(
|
||||
Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"Not connected to server",
|
||||
));
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ impl Client {
|
||||
println!("Searching for {}", query);
|
||||
if let Some(server) = &self.server {
|
||||
let hash = md5::md5(query);
|
||||
let token = i32::from_str_radix(&hash[0..5].to_string(), 16).unwrap();
|
||||
server.file_search(token, &query);
|
||||
let token = i32::from_str_radix(&hash[0..5], 16).unwrap();
|
||||
server.file_search(token, query);
|
||||
} else {
|
||||
eprintln!("Not connected to server");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{fmt::Display, str};
|
||||
use std::str;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Message {
|
||||
@@ -42,7 +42,7 @@ impl Message {
|
||||
// Print the ASCII part
|
||||
let mut i = 0;
|
||||
for &byte in chunk {
|
||||
i = i + 1;
|
||||
i += 1;
|
||||
if byte.is_ascii_graphic() || byte.is_ascii_whitespace() {
|
||||
print!("{}", byte as char);
|
||||
} else {
|
||||
@@ -166,7 +166,7 @@ impl Message {
|
||||
.map(|byte| format!("{:02x}", byte))
|
||||
.collect::<String>();
|
||||
self.pointer += size;
|
||||
return hex_str;
|
||||
hex_str
|
||||
}
|
||||
|
||||
pub fn read_int8(&mut self) -> i8 {
|
||||
|
||||
@@ -74,7 +74,7 @@ impl MessageReader {
|
||||
}
|
||||
|
||||
let message_buffer: Vec<u8> = self.buffer.drain(..total_size).collect();
|
||||
return Ok(Some(Message::new_with_data(message_buffer)));
|
||||
Ok(Some(Message::new_with_data(message_buffer)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ impl MessageFactory {
|
||||
pub fn build_watch_user(token: &str) -> Message {
|
||||
Message::new()
|
||||
.write_raw_bytes([5, 0, 0, 0, 0].to_vec())
|
||||
.write_raw_hex_string(&token)
|
||||
.write_raw_hex_string(token)
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -355,10 +355,10 @@ impl Server {
|
||||
}
|
||||
|
||||
{
|
||||
logged_in = context.lock().unwrap().logged_in.clone()
|
||||
logged_in = context.lock().unwrap().logged_in
|
||||
}
|
||||
|
||||
if !logged_in.is_none() {
|
||||
if logged_in.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+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() {
|
||||
|
||||
@@ -2,4 +2,3 @@ pub mod md5;
|
||||
pub mod zlib;
|
||||
|
||||
pub use md5::*;
|
||||
pub use zlib::*;
|
||||
|
||||
+5
-10
@@ -1,7 +1,5 @@
|
||||
//https://www.rfc-editor.org/rfc/rfc1950
|
||||
|
||||
use flate2::bufread::ZlibDecoder;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ZlibHeader {
|
||||
cm: u8,
|
||||
@@ -32,13 +30,13 @@ pub fn extract_header(data: &Vec<u8>) -> Result<ZlibHeader, String> {
|
||||
if cm != 8 {
|
||||
return Err(format!("ZLIB compression method not supported: {}", cmf));
|
||||
}
|
||||
return Ok(ZlibHeader {
|
||||
Ok(ZlibHeader {
|
||||
cm,
|
||||
cinfo,
|
||||
fcheck,
|
||||
fdict,
|
||||
flevel,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
pub fn extract_block_header(data: &Vec<u8>) -> BlockHeader {
|
||||
@@ -114,7 +112,7 @@ fn find_symbol(current_code: u32, code_len: u32) -> Option<u32> {
|
||||
// Range for symbols 256-279: 0b0000000 to 0b0010111
|
||||
if (0..=0b0010111).contains(&reversed_code) {
|
||||
// Symbol = base_symbol + (code - base_code)
|
||||
let symbol = 256 + (reversed_code - 0b0000000);
|
||||
let symbol = 256 + reversed_code;
|
||||
return Some(symbol);
|
||||
}
|
||||
}
|
||||
@@ -122,7 +120,7 @@ fn find_symbol(current_code: u32, code_len: u32) -> Option<u32> {
|
||||
let reversed_code = reverse_bits(current_code, 8);
|
||||
// Range for symbols 0-143: 0b00110000 to 0b10111111
|
||||
if (0b00110000..=0b10111111).contains(&reversed_code) {
|
||||
let symbol = 0 + (reversed_code - 0b00110000);
|
||||
let symbol = reversed_code - 0b00110000;
|
||||
return Some(symbol);
|
||||
}
|
||||
// Range for symbols 280-287: 0b11000000 to 0b11000111
|
||||
@@ -148,7 +146,7 @@ fn find_symbol(current_code: u32, code_len: u32) -> Option<u32> {
|
||||
// If we checked a valid length but the code wasn't in any range for that length.
|
||||
None
|
||||
}
|
||||
pub fn decode_fixed_huffman_symbol(reader: &mut BitReader) -> Result<u32, &'static str> {
|
||||
fn decode_fixed_huffman_symbol(reader: &mut BitReader) -> Result<u32, &'static str> {
|
||||
let mut current_code = 0u32;
|
||||
let mut code_len = 0u32;
|
||||
loop {
|
||||
@@ -355,14 +353,11 @@ impl HuffmanTable {
|
||||
}
|
||||
}
|
||||
|
||||
// --- New Generic Symbol Decoder ---
|
||||
/// Decodes one symbol from the stream using the provided Huffman table.
|
||||
fn decode_symbol(
|
||||
reader: &mut BitReader,
|
||||
huffman_table: &HuffmanTable,
|
||||
) -> Result<u32, &'static str> {
|
||||
let mut code = 0;
|
||||
let mut len = 0;
|
||||
|
||||
// The maximum length for DEFLATE codes is 15 bits.
|
||||
for i in 0..15 {
|
||||
|
||||
Reference in New Issue
Block a user