aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/write.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-24 22:46:41 -0500
committermat <github@matdoes.dev>2022-04-24 22:46:41 -0500
commitf4dd3a9293367fa8f3d839a184e8055b22595204 (patch)
tree3beafa3c8035c69a33b7d0f12779236bf786cf36 /azalea-protocol/src/write.rs
parent4c00bd886578c70f6aeb35400d9d03b355df3155 (diff)
downloadazalea-drasl-f4dd3a9293367fa8f3d839a184e8055b22595204.tar.xz
ENCRYPTION WORKS!!!!!!!!!!!
Diffstat (limited to 'azalea-protocol/src/write.rs')
-rwxr-xr-xazalea-protocol/src/write.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs
index 821ed6e8..e72a74b1 100755
--- a/azalea-protocol/src/write.rs
+++ b/azalea-protocol/src/write.rs
@@ -1,5 +1,6 @@
use crate::{mc_buf::Writable, packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH};
use async_compression::tokio::bufread::ZlibEncoder;
+use azalea_auth::encryption::Aes128Cfb;
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::TcpStream,
@@ -50,14 +51,22 @@ async fn compression_encoder(data: &[u8], compression_threshold: u32) -> Result<
}
}
-pub async fn write_packet<P>(packet: P, stream: &mut TcpStream, compression_threshold: Option<u32>)
-where
+pub async fn write_packet<P>(
+ packet: P,
+ stream: &mut TcpStream,
+ compression_threshold: Option<u32>,
+ cipher: &mut Option<Aes128Cfb>,
+) where
P: ProtocolPacket + std::fmt::Debug,
{
let mut buf = packet_encoder(&packet).unwrap();
if let Some(threshold) = compression_threshold {
buf = compression_encoder(&buf, threshold).await.unwrap();
}
+ // if we were given a cipher, encrypt the packet
+ if let Some(cipher) = cipher {
+ azalea_auth::encryption::encrypt_packet(cipher, &mut buf);
+ }
buf = frame_prepender(&mut buf).unwrap();
stream.write_all(&buf).await.unwrap();
}