pre-commit hook for fmt & clippy

This commit is contained in:
17ms 2023-04-12 03:42:58 +03:00
parent 66dec81364
commit b8e6f81338
6 changed files with 20 additions and 13 deletions

8
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,8 @@
repos:
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
args: ["--verbose", "--"]
- id: cargo-check
- id: clippy

View File

@ -111,7 +111,7 @@ impl Connector {
let buf = comms::recv(&mut conn.reader, Some(&mut conn.cipher)).await?;
let msg = String::from_utf8(buf)?;
let split: Vec<&str> = msg.split(":").collect();
let split: Vec<&str> = msg.split(':').collect();
let name = split[0].trim().to_string();
let size: u64 = split[1].trim().parse()?;
let hash = split[2].trim().to_string();
@ -149,7 +149,7 @@ impl Connector {
)
.await?;
let mut remaining = req.size.clone();
let mut remaining = req.size;
while remaining != 0 {
let buf = comms::recv(&mut conn.reader, Some(&mut conn.cipher)).await?;
@ -158,14 +158,13 @@ impl Connector {
remaining -= buf.len() as u64;
}
let msg: Vec<u8>;
let new_hash = crypto::try_hash(&path)?;
if new_hash == req.hash {
msg = b"OK".to_vec();
let msg: Vec<u8> = if new_hash == req.hash {
b"OK".to_vec()
} else {
msg = b"ERROR".to_vec();
}
b"ERROR".to_vec()
};
comms::send(
&mut conn.writer,

View File

@ -70,7 +70,7 @@ pub fn aes_encrypt(
}
pub fn aes_decrypt(
data: &Vec<u8>,
data: &[u8],
cipher: &mut AesGcm<Aes256, U12>,
) -> Result<Vec<u8>, Box<dyn Error + Send + Sync>> {
let (nonce_bytes, data) = data.split_at(AES_NONCE_SIZE);

View File

@ -0,0 +1 @@
// placeholder for now

View File

@ -7,7 +7,7 @@ use tokio::{
fs::File,
io::AsyncReadExt,
net::{TcpListener, TcpStream},
sync::mpsc::{self},
sync::mpsc,
};
#[derive(Debug, Clone, Copy)]
@ -73,7 +73,7 @@ impl Listener {
return Ok::<(), Box<dyn Error + Send + Sync>>(());
}
let index = self.metadata_handler(&mut connection, &files).await?;
let index = self.metadata_handler(&mut connection, files).await?;
tx.send(Message::ConnectionReady).await?;
self.request_handler(&mut connection, &index).await?;
tx.send(Message::ClientDisconnect(addr)).await?;
@ -120,7 +120,7 @@ impl Listener {
let mut index = HashMap::new();
for path in files {
let split: Vec<&str> = path.split("/").collect(); // TODO: different path delimiters?
let split: Vec<&str> = path.split('/').collect(); // TODO: different path delimiters?
let name = split[split.len() - 1].to_string();
let handle = File::open(PathBuf::from_str(path)?).await?;
let size = handle.metadata().await?.len();
@ -203,7 +203,7 @@ impl Listener {
)
.await?;
remaining = remaining - n as u64;
remaining -= n as u64;
}
let buf = comms::recv(&mut conn.reader, Some(&mut conn.cipher)).await?;

View File

@ -1,5 +1,4 @@
use std::error::Error;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {