Revert "less unwraps"

This reverts commit 772644fa5d.
This commit is contained in:
17ms 2023-05-01 04:05:36 +03:00
parent aa35573b44
commit 573a2a44a1
3 changed files with 23 additions and 46 deletions

View File

@ -185,33 +185,10 @@ impl Connector {
loop {
let rx_msg = rx.recv().await;
if rx_msg.is_none() {
continue;
}
match self.msg_handler(rx_msg.unwrap(), conn, metadata).await? {
true => continue,
false => break,
};
}
Ok(())
}
async fn msg_handler(
&self,
msg: Message,
conn: &mut Connection<'_>,
metadata: &HashMap<String, (u64, String)>,
) -> Result<bool, Box<dyn Error + Send + Sync>> {
match msg {
match rx_msg.unwrap() {
Message::ClientReq(name) => {
let req = match Request::new(name, metadata) {
Some(req) => req,
None => return Ok(true),
};
let req = Request::new(name, metadata).unwrap(); // TODO: handle
self.request(conn, req).await?;
Ok(true)
}
Message::Shutdown => {
let msg = b"DISCONNECT".to_vec();
@ -223,9 +200,12 @@ impl Connector {
)
.await?;
Ok(false)
break;
}
_ => Ok(true),
_ => continue,
}
}
Ok(())
}
}

View File

@ -62,10 +62,7 @@ pub fn aes_encrypt(
rng: &mut OsRng,
) -> Result<Vec<u8>, Box<dyn Error + Send + Sync>> {
let nonce = generate_nonce(rng);
let encrypted = match cipher.encrypt(&nonce, data.as_ref()) {
Ok(d) => d,
Err(_) => return Err("AES encryption failed".into()),
};
let encrypted = cipher.encrypt(&nonce, data.as_ref()).unwrap(); // TODO: handle errors
let mut data = nonce.to_vec();
data.extend_from_slice(&encrypted);
@ -77,10 +74,9 @@ pub fn aes_decrypt(
cipher: &mut AesGcm<Aes256, U12>,
) -> Result<Vec<u8>, Box<dyn Error + Send + Sync>> {
let (nonce_bytes, data) = data.split_at(AES_NONCE_SIZE);
let decrypted = match cipher.decrypt(Nonce::from_slice(nonce_bytes), data.as_ref()) {
Ok(d) => d,
Err(_) => return Err("AES decryption failed".into()),
};
let decrypted = cipher
.decrypt(Nonce::from_slice(nonce_bytes), data.as_ref())
.unwrap(); // TODO: handle errors
Ok(decrypted)
}

1
src/error.rs Normal file
View File

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