diff --git a/src/messages.rs b/src/messages.rs index 8856a18..07fc1b6 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -41,13 +41,14 @@ macro_rules! standard_roundtrip { tokio::runtime::Runtime::new().unwrap().block_on(async { use std::io::Cursor; + let originals = xs.clone(); let buffer = vec![]; let mut write_cursor = Cursor::new(buffer); xs.write(&mut write_cursor).await.unwrap(); let serialized_form = write_cursor.into_inner(); let mut read_cursor = Cursor::new(serialized_form); let ys = <$t>::read(&mut read_cursor); - assert_eq!(xs, ys.await.unwrap()); + assert_eq!(originals, ys.await.unwrap()); }) } } diff --git a/src/messages/authentication_method.rs b/src/messages/authentication_method.rs index 292bf0b..acf4e6a 100644 --- a/src/messages/authentication_method.rs +++ b/src/messages/authentication_method.rs @@ -118,7 +118,7 @@ impl AuthenticationMethod { } pub async fn write( - &self, + self, w: &mut W, ) -> Result<(), AuthenticationMethodWriteError> { let value = match self { @@ -131,9 +131,9 @@ impl AuthenticationMethod { AuthenticationMethod::NDS => 7, AuthenticationMethod::MultiAuthenticationFramework => 8, AuthenticationMethod::JSONPropertyBlock => 9, - AuthenticationMethod::PrivateMethod(pm) if (0x80..=0xfe).contains(pm) => *pm, + AuthenticationMethod::PrivateMethod(pm) if (0x80..=0xfe).contains(&pm) => pm, AuthenticationMethod::PrivateMethod(pm) => { - return Err(AuthenticationMethodWriteError::InvalidAuthMethod(*pm)) + return Err(AuthenticationMethodWriteError::InvalidAuthMethod(pm)) } AuthenticationMethod::NoAcceptableMethods => 0xff, }; diff --git a/src/messages/client_command.rs b/src/messages/client_command.rs index 021d0f9..08bd74c 100644 --- a/src/messages/client_command.rs +++ b/src/messages/client_command.rs @@ -55,7 +55,7 @@ impl ClientConnectionCommand { } pub async fn write( - &self, + self, w: &mut W, ) -> Result<(), std::io::Error> { match self { @@ -125,7 +125,7 @@ impl ClientConnectionRequest { } pub async fn write( - &self, + self, w: &mut W, ) -> Result<(), ClientConnectionCommandWriteError> { w.write_u8(5).await?; diff --git a/src/messages/client_greeting.rs b/src/messages/client_greeting.rs index af8faec..5bda77a 100644 --- a/src/messages/client_greeting.rs +++ b/src/messages/client_greeting.rs @@ -72,7 +72,7 @@ impl ClientGreeting { } pub async fn write( - &self, + mut self, w: &mut W, ) -> Result<(), ClientGreetingWriteError> { if self.acceptable_methods.len() > 255 { @@ -85,7 +85,7 @@ impl ClientGreeting { buffer.push(5); buffer.push(self.acceptable_methods.len() as u8); w.write_all(&buffer).await?; - for authmeth in self.acceptable_methods.iter() { + for authmeth in self.acceptable_methods.drain(..) { authmeth.write(w).await?; } Ok(()) diff --git a/src/messages/client_username_password.rs b/src/messages/client_username_password.rs index c2fe5b3..2c4f629 100644 --- a/src/messages/client_username_password.rs +++ b/src/messages/client_username_password.rs @@ -81,7 +81,7 @@ impl ClientUsernamePassword { } pub async fn write( - &self, + self, w: &mut W, ) -> Result<(), ClientUsernamePasswordWriteError> { w.write_u8(1).await?; diff --git a/src/messages/server_auth_response.rs b/src/messages/server_auth_response.rs index a527ef5..25a3ece 100644 --- a/src/messages/server_auth_response.rs +++ b/src/messages/server_auth_response.rs @@ -59,7 +59,7 @@ impl ServerAuthResponse { } pub async fn write( - &self, + self, w: &mut W, ) -> Result<(), ServerAuthResponseWriteError> { w.write_all(&[1]).await?; diff --git a/src/messages/server_choice.rs b/src/messages/server_choice.rs index e6d089c..b2868a5 100644 --- a/src/messages/server_choice.rs +++ b/src/messages/server_choice.rs @@ -72,7 +72,7 @@ impl ServerChoice { } pub async fn write( - &self, + self, w: &mut W, ) -> Result<(), ServerChoiceWriteError> { w.write_u8(5).await?; diff --git a/src/messages/server_response.rs b/src/messages/server_response.rs index 5de5d58..3cb68b1 100644 --- a/src/messages/server_response.rs +++ b/src/messages/server_response.rs @@ -111,7 +111,7 @@ impl ServerResponse { } pub async fn write( - &self, + self, w: &mut W, ) -> Result<(), ServerResponseWriteError> { w.write_u8(5).await?; diff --git a/src/messages/string.rs b/src/messages/string.rs index 7af0fe7..d0f376f 100644 --- a/src/messages/string.rs +++ b/src/messages/string.rs @@ -5,7 +5,7 @@ use std::string::FromUtf8Error; use thiserror::Error; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; -#[derive(Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub struct SOCKSv5String(String); #[cfg(test)] @@ -75,7 +75,7 @@ impl SOCKSv5String { } pub async fn write( - &self, + self, w: &mut W, ) -> Result<(), SOCKSv5StringWriteError> { let bytestring = self.0.as_bytes();