parent
aa35573b44
commit
573a2a44a1
@ -185,33 +185,10 @@ impl Connector {
|
|||||||
loop {
|
loop {
|
||||||
let rx_msg = rx.recv().await;
|
let rx_msg = rx.recv().await;
|
||||||
|
|
||||||
if rx_msg.is_none() {
|
match rx_msg.unwrap() {
|
||||||
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 {
|
|
||||||
Message::ClientReq(name) => {
|
Message::ClientReq(name) => {
|
||||||
let req = match Request::new(name, metadata) {
|
let req = Request::new(name, metadata).unwrap(); // TODO: handle
|
||||||
Some(req) => req,
|
|
||||||
None => return Ok(true),
|
|
||||||
};
|
|
||||||
self.request(conn, req).await?;
|
self.request(conn, req).await?;
|
||||||
Ok(true)
|
|
||||||
}
|
}
|
||||||
Message::Shutdown => {
|
Message::Shutdown => {
|
||||||
let msg = b"DISCONNECT".to_vec();
|
let msg = b"DISCONNECT".to_vec();
|
||||||
@ -223,9 +200,12 @@ impl Connector {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(false)
|
break;
|
||||||
}
|
}
|
||||||
_ => Ok(true),
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,10 +62,7 @@ pub fn aes_encrypt(
|
|||||||
rng: &mut OsRng,
|
rng: &mut OsRng,
|
||||||
) -> Result<Vec<u8>, Box<dyn Error + Send + Sync>> {
|
) -> Result<Vec<u8>, Box<dyn Error + Send + Sync>> {
|
||||||
let nonce = generate_nonce(rng);
|
let nonce = generate_nonce(rng);
|
||||||
let encrypted = match cipher.encrypt(&nonce, data.as_ref()) {
|
let encrypted = cipher.encrypt(&nonce, data.as_ref()).unwrap(); // TODO: handle errors
|
||||||
Ok(d) => d,
|
|
||||||
Err(_) => return Err("AES encryption failed".into()),
|
|
||||||
};
|
|
||||||
let mut data = nonce.to_vec();
|
let mut data = nonce.to_vec();
|
||||||
data.extend_from_slice(&encrypted);
|
data.extend_from_slice(&encrypted);
|
||||||
|
|
||||||
@ -77,10 +74,9 @@ pub fn aes_decrypt(
|
|||||||
cipher: &mut AesGcm<Aes256, U12>,
|
cipher: &mut AesGcm<Aes256, U12>,
|
||||||
) -> Result<Vec<u8>, Box<dyn Error + Send + Sync>> {
|
) -> Result<Vec<u8>, Box<dyn Error + Send + Sync>> {
|
||||||
let (nonce_bytes, data) = data.split_at(AES_NONCE_SIZE);
|
let (nonce_bytes, data) = data.split_at(AES_NONCE_SIZE);
|
||||||
let decrypted = match cipher.decrypt(Nonce::from_slice(nonce_bytes), data.as_ref()) {
|
let decrypted = cipher
|
||||||
Ok(d) => d,
|
.decrypt(Nonce::from_slice(nonce_bytes), data.as_ref())
|
||||||
Err(_) => return Err("AES decryption failed".into()),
|
.unwrap(); // TODO: handle errors
|
||||||
};
|
|
||||||
|
|
||||||
Ok(decrypted)
|
Ok(decrypted)
|
||||||
}
|
}
|
||||||
|
1
src/error.rs
Normal file
1
src/error.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
// placeholder
|
Loading…
Reference in New Issue
Block a user