diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-10-07 20:12:36 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 20:12:36 -0500 |
| commit | bc3aa9467ae1e2d0ea1727093af9b0af14965e69 (patch) | |
| tree | 8db3b735daed484507129eb0683db88ddec14210 /azalea-protocol/src/packets/login | |
| parent | 695efef66fdf1e08f0cb6d8783c085875100fa2d (diff) | |
| download | azalea-drasl-bc3aa9467ae1e2d0ea1727093af9b0af14965e69.tar.xz | |
Replace impl Read with Cursor<&[u8]> (#26)
* Start getting rid of Cursor
* try to make the tests pass and fail
* make the tests pass
* remove unused uses
* fix clippy warnings
* fix potential OOM exploits
* fix OOM in az-nbt
* fix nbt benchmark
* fix a test
* start replacing it with Cursor<Vec<u8>>
* wip
* fix all the issues
* fix all tests
* fix nbt benchmark
* fix warnings
Diffstat (limited to 'azalea-protocol/src/packets/login')
3 files changed, 11 insertions, 31 deletions
diff --git a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs index 6ecbfb66..6976298a 100755 --- a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs @@ -1,31 +1,9 @@ -use super::ClientboundLoginPacket; -use azalea_buf::{BufReadError, McBufVarReadable, McBufVarWritable}; -use std::{ - hash::Hash, - io::{Read, Write}, -}; +use azalea_buf::McBuf; +use azalea_protocol_macros::ClientboundLoginPacket; +use std::hash::Hash; -#[derive(Hash, Clone, Debug)] +#[derive(Hash, Clone, Debug, ClientboundLoginPacket, McBuf)] pub struct ClientboundLoginCompressionPacket { + #[var] pub compression_threshold: i32, } - -impl ClientboundLoginCompressionPacket { - pub fn get(self) -> ClientboundLoginPacket { - ClientboundLoginPacket::LoginCompression(self) - } - - pub fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { - self.compression_threshold.var_write_into(buf)?; - Ok(()) - } - - pub fn read(buf: &mut impl Read) -> Result<ClientboundLoginPacket, BufReadError> { - let compression_threshold = i32::var_read_from(buf)?; - - Ok(ClientboundLoginCompressionPacket { - compression_threshold, - } - .get()) - } -} diff --git a/azalea-protocol/src/packets/login/serverbound_hello_packet.rs b/azalea-protocol/src/packets/login/serverbound_hello_packet.rs index 4d94092e..5e1422fb 100755 --- a/azalea-protocol/src/packets/login/serverbound_hello_packet.rs +++ b/azalea-protocol/src/packets/login/serverbound_hello_packet.rs @@ -18,6 +18,8 @@ pub struct ProfilePublicKeyData { #[cfg(test)] mod tests { + use std::io::Cursor; + use super::*; use azalea_buf::{McBufReadable, McBufWritable}; @@ -28,9 +30,9 @@ mod tests { public_key: None, profile_id: Some(Uuid::from_u128(0)), }; - let mut buf = Vec::new(); + let mut buf: Vec<u8> = Vec::new(); packet.write_into(&mut buf).unwrap(); - let packet2 = ServerboundHelloPacket::read_from(&mut buf.as_slice()).unwrap(); + let packet2 = ServerboundHelloPacket::read_from(&mut Cursor::new(&buf)).unwrap(); assert_eq!(packet, packet2); } } diff --git a/azalea-protocol/src/packets/login/serverbound_key_packet.rs b/azalea-protocol/src/packets/login/serverbound_key_packet.rs index ba4bcb8a..23b3659b 100644 --- a/azalea-protocol/src/packets/login/serverbound_key_packet.rs +++ b/azalea-protocol/src/packets/login/serverbound_key_packet.rs @@ -1,7 +1,7 @@ use azalea_buf::{BufReadError, McBuf}; use azalea_crypto::SaltSignaturePair; use azalea_protocol_macros::ServerboundLoginPacket; -use std::io::{Read, Write}; +use std::io::{Cursor, Write}; use azalea_buf::{McBufReadable, McBufWritable}; @@ -18,7 +18,7 @@ pub enum NonceOrSaltSignature { } impl McBufReadable for NonceOrSaltSignature { - fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let is_nonce = bool::read_from(buf)?; if is_nonce { Ok(NonceOrSaltSignature::Nonce(Vec::<u8>::read_from(buf)?)) |
