diff --git a/src/client.rs b/src/client.rs index 6c46f1b..dcefcbd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -6,7 +6,6 @@ use crate::messages::{ use crate::network::{Network, SOCKSv5Address}; use async_std::net::IpAddr; use futures::io::{AsyncRead, AsyncWrite}; -use std::pin::Pin; use thiserror::Error; #[derive(Debug, Error)] diff --git a/src/messages/authentication_method.rs b/src/messages/authentication_method.rs index 050d876..72bf8ff 100644 --- a/src/messages/authentication_method.rs +++ b/src/messages/authentication_method.rs @@ -8,7 +8,6 @@ use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; #[cfg(test)] use quickcheck::{quickcheck, Arbitrary, Gen}; use std::fmt; -use std::pin::Pin; #[allow(clippy::upper_case_acronyms)] #[derive(Clone, Debug, Eq, PartialEq)] @@ -48,7 +47,7 @@ impl fmt::Display for AuthenticationMethod { impl AuthenticationMethod { pub async fn read( - mut r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut byte_buffer = [0u8; 1]; let amount_read = r.read(&mut byte_buffer).await?; @@ -123,7 +122,7 @@ standard_roundtrip!(auth_byte_roundtrips, AuthenticationMethod); fn bad_byte() { let no_len = vec![42]; let mut cursor = Cursor::new(no_len); - let ys = AuthenticationMethod::read(Pin::new(&mut cursor)); + let ys = AuthenticationMethod::read(&mut cursor); assert_eq!( Err(DeserializationError::AuthenticationMethodError( AuthenticationDeserializationError::InvalidAuthenticationByte(42) diff --git a/src/messages/client_command.rs b/src/messages/client_command.rs index 2d5456a..a8beabc 100644 --- a/src/messages/client_command.rs +++ b/src/messages/client_command.rs @@ -13,7 +13,6 @@ use futures::io::{AsyncRead, AsyncWrite, AsyncWriteExt}; use quickcheck::{quickcheck, Arbitrary, Gen}; #[cfg(test)] use std::net::Ipv4Addr; -use std::pin::Pin; #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum ClientConnectionCommand { @@ -31,12 +30,11 @@ pub struct ClientConnectionRequest { impl ClientConnectionRequest { pub async fn read( - r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut buffer = [0; 2]; - let raw_r = Pin::into_inner(r); - read_amt(Pin::new(raw_r), 2, &mut buffer).await?; + read_amt(r, 2, &mut buffer).await?; if buffer[0] != 5 { return Err(DeserializationError::InvalidVersion(5, buffer[0])); @@ -49,9 +47,9 @@ impl ClientConnectionRequest { x => return Err(DeserializationError::InvalidClientCommand(x)), }; - let destination_address = SOCKSv5Address::read(Pin::new(raw_r)).await?; + let destination_address = SOCKSv5Address::read(r).await?; - read_amt(Pin::new(raw_r), 2, &mut buffer).await?; + read_amt(r, 2, &mut buffer).await?; let destination_port = ((buffer[0] as u16) << 8) + (buffer[1] as u16); Ok(ClientConnectionRequest { @@ -115,12 +113,12 @@ standard_roundtrip!(client_request_roundtrips, ClientConnectionRequest); fn check_short_reads() { let empty = vec![]; let mut cursor = Cursor::new(empty); - let ys = ClientConnectionRequest::read(Pin::new(&mut cursor)); + let ys = ClientConnectionRequest::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); let no_len = vec![5, 1]; let mut cursor = Cursor::new(no_len); - let ys = ClientConnectionRequest::read(Pin::new(&mut cursor)); + let ys = ClientConnectionRequest::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); } @@ -128,7 +126,7 @@ fn check_short_reads() { fn check_bad_version() { let bad_ver = vec![6, 1, 1]; let mut cursor = Cursor::new(bad_ver); - let ys = ClientConnectionRequest::read(Pin::new(&mut cursor)); + let ys = ClientConnectionRequest::read(&mut cursor); assert_eq!( Err(DeserializationError::InvalidVersion(5, 6)), task::block_on(ys) @@ -139,7 +137,7 @@ fn check_bad_version() { fn check_bad_command() { let bad_cmd = vec![5, 32, 1]; let mut cursor = Cursor::new(bad_cmd); - let ys = ClientConnectionRequest::read(Pin::new(&mut cursor)); + let ys = ClientConnectionRequest::read(&mut cursor); assert_eq!( Err(DeserializationError::InvalidClientCommand(32)), task::block_on(ys) diff --git a/src/messages/client_greeting.rs b/src/messages/client_greeting.rs index be474e4..cb655d7 100644 --- a/src/messages/client_greeting.rs +++ b/src/messages/client_greeting.rs @@ -10,7 +10,6 @@ use futures::io::Cursor; use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; #[cfg(test)] use quickcheck::{quickcheck, Arbitrary, Gen}; -use std::pin::Pin; /// Client greetings are the first message sent in a SOCKSv5 session. They /// identify that there's a client that wants to talk to a server, and that @@ -24,12 +23,11 @@ pub struct ClientGreeting { impl ClientGreeting { pub async fn read( - r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut buffer = [0; 1]; - let raw_r = Pin::into_inner(r); - if raw_r.read(&mut buffer).await? == 0 { + if r.read(&mut buffer).await? == 0 { return Err(DeserializationError::NotEnoughData); } @@ -37,13 +35,13 @@ impl ClientGreeting { return Err(DeserializationError::InvalidVersion(5, buffer[0])); } - if raw_r.read(&mut buffer).await? == 0 { + if r.read(&mut buffer).await? == 0 { return Err(DeserializationError::NotEnoughData); } let mut acceptable_methods = Vec::with_capacity(buffer[0] as usize); for _ in 0..buffer[0] { - acceptable_methods.push(AuthenticationMethod::read(Pin::new(raw_r)).await?); + acceptable_methods.push(AuthenticationMethod::read(r).await?); } Ok(ClientGreeting { acceptable_methods }) @@ -90,17 +88,17 @@ standard_roundtrip!(client_greeting_roundtrips, ClientGreeting); fn check_short_reads() { let empty = vec![]; let mut cursor = Cursor::new(empty); - let ys = ClientGreeting::read(Pin::new(&mut cursor)); + let ys = ClientGreeting::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); let no_len = vec![5]; let mut cursor = Cursor::new(no_len); - let ys = ClientGreeting::read(Pin::new(&mut cursor)); + let ys = ClientGreeting::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); let bad_len = vec![5, 9]; let mut cursor = Cursor::new(bad_len); - let ys = ClientGreeting::read(Pin::new(&mut cursor)); + let ys = ClientGreeting::read(&mut cursor); assert_eq!( Err(DeserializationError::AuthenticationMethodError( AuthenticationDeserializationError::NoDataFound @@ -113,7 +111,7 @@ fn check_short_reads() { fn check_bad_version() { let no_len = vec![6, 1, 1]; let mut cursor = Cursor::new(no_len); - let ys = ClientGreeting::read(Pin::new(&mut cursor)); + let ys = ClientGreeting::read(&mut cursor); assert_eq!( Err(DeserializationError::InvalidVersion(5, 6)), task::block_on(ys) diff --git a/src/messages/client_username_password.rs b/src/messages/client_username_password.rs index d5c7dae..50cd4d0 100644 --- a/src/messages/client_username_password.rs +++ b/src/messages/client_username_password.rs @@ -10,7 +10,6 @@ use futures::io::Cursor; use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; #[cfg(test)] use quickcheck::{quickcheck, Arbitrary, Gen}; -use std::pin::Pin; #[derive(Clone, Debug, Eq, PartialEq)] pub struct ClientUsernamePassword { @@ -20,12 +19,11 @@ pub struct ClientUsernamePassword { impl ClientUsernamePassword { pub async fn read( - r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut buffer = [0; 1]; - let raw_r = Pin::into_inner(r); - if raw_r.read(&mut buffer).await? == 0 { + if r.read(&mut buffer).await? == 0 { return Err(DeserializationError::NotEnoughData); } @@ -33,8 +31,8 @@ impl ClientUsernamePassword { return Err(DeserializationError::InvalidVersion(1, buffer[0])); } - let username = read_string(Pin::new(raw_r)).await?; - let password = read_string(Pin::new(raw_r)).await?; + let username = read_string(r).await?; + let password = read_string(r).await?; Ok(ClientUsernamePassword { username, password }) } @@ -65,12 +63,12 @@ standard_roundtrip!(username_password_roundtrips, ClientUsernamePassword); fn check_short_reads() { let empty = vec![]; let mut cursor = Cursor::new(empty); - let ys = ClientUsernamePassword::read(Pin::new(&mut cursor)); + let ys = ClientUsernamePassword::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); let user_only = vec![1, 3, 102, 111, 111]; let mut cursor = Cursor::new(user_only); - let ys = ClientUsernamePassword::read(Pin::new(&mut cursor)); + let ys = ClientUsernamePassword::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); } @@ -78,7 +76,7 @@ fn check_short_reads() { fn check_bad_version() { let bad_len = vec![5]; let mut cursor = Cursor::new(bad_len); - let ys = ClientUsernamePassword::read(Pin::new(&mut cursor)); + let ys = ClientUsernamePassword::read(&mut cursor); assert_eq!( Err(DeserializationError::InvalidVersion(1, 5)), task::block_on(ys) diff --git a/src/messages/server_auth_response.rs b/src/messages/server_auth_response.rs index ec70af1..7afbf2c 100644 --- a/src/messages/server_auth_response.rs +++ b/src/messages/server_auth_response.rs @@ -7,7 +7,6 @@ use futures::io::Cursor; use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; #[cfg(test)] use quickcheck::{quickcheck, Arbitrary, Gen}; -use std::pin::Pin; #[derive(Clone, Debug, Eq, PartialEq)] pub struct ServerAuthResponse { @@ -16,7 +15,7 @@ pub struct ServerAuthResponse { impl ServerAuthResponse { pub async fn read( - mut r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut buffer = [0; 1]; @@ -62,12 +61,12 @@ standard_roundtrip!(server_auth_response, ServerAuthResponse); fn check_short_reads() { let empty = vec![]; let mut cursor = Cursor::new(empty); - let ys = ServerAuthResponse::read(Pin::new(&mut cursor)); + let ys = ServerAuthResponse::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); let no_len = vec![1]; let mut cursor = Cursor::new(no_len); - let ys = ServerAuthResponse::read(Pin::new(&mut cursor)); + let ys = ServerAuthResponse::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); } @@ -75,7 +74,7 @@ fn check_short_reads() { fn check_bad_version() { let no_len = vec![6, 1]; let mut cursor = Cursor::new(no_len); - let ys = ServerAuthResponse::read(Pin::new(&mut cursor)); + let ys = ServerAuthResponse::read(&mut cursor); assert_eq!( Err(DeserializationError::InvalidVersion(1, 6)), task::block_on(ys) diff --git a/src/messages/server_choice.rs b/src/messages/server_choice.rs index d3fe169..c5e6a98 100644 --- a/src/messages/server_choice.rs +++ b/src/messages/server_choice.rs @@ -10,7 +10,6 @@ use futures::io::Cursor; use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; #[cfg(test)] use quickcheck::{quickcheck, Arbitrary, Gen}; -use std::pin::Pin; #[derive(Clone, Debug, Eq, PartialEq)] pub struct ServerChoice { @@ -19,7 +18,7 @@ pub struct ServerChoice { impl ServerChoice { pub async fn read( - mut r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut buffer = [0; 1]; @@ -60,12 +59,12 @@ standard_roundtrip!(server_choice_roundtrips, ServerChoice); fn check_short_reads() { let empty = vec![]; let mut cursor = Cursor::new(empty); - let ys = ServerChoice::read(Pin::new(&mut cursor)); + let ys = ServerChoice::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); let bad_len = vec![5]; let mut cursor = Cursor::new(bad_len); - let ys = ServerChoice::read(Pin::new(&mut cursor)); + let ys = ServerChoice::read(&mut cursor); assert_eq!( Err(DeserializationError::AuthenticationMethodError( AuthenticationDeserializationError::NoDataFound @@ -78,7 +77,7 @@ fn check_short_reads() { fn check_bad_version() { let no_len = vec![9, 1]; let mut cursor = Cursor::new(no_len); - let ys = ServerChoice::read(Pin::new(&mut cursor)); + let ys = ServerChoice::read(&mut cursor); assert_eq!( Err(DeserializationError::InvalidVersion(5, 9)), task::block_on(ys) diff --git a/src/messages/server_response.rs b/src/messages/server_response.rs index 6127116..f5b8274 100644 --- a/src/messages/server_response.rs +++ b/src/messages/server_response.rs @@ -13,7 +13,6 @@ use log::warn; #[cfg(test)] use quickcheck::{quickcheck, Arbitrary, Gen}; use std::net::Ipv4Addr; -use std::pin::Pin; use thiserror::Error; #[derive(Clone, Debug, Eq, Error, PartialEq)] @@ -57,12 +56,11 @@ impl ServerResponse { impl ServerResponse { pub async fn read( - r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut buffer = [0; 3]; - let raw_r = Pin::into_inner(r); - read_amt(Pin::new(raw_r), 3, &mut buffer).await?; + read_amt(r, 3, &mut buffer).await?; if buffer[0] != 5 { return Err(DeserializationError::InvalidVersion(5, buffer[0])); @@ -85,8 +83,8 @@ impl ServerResponse { x => return Err(DeserializationError::InvalidServerResponse(x)), }; - let bound_address = SOCKSv5Address::read(Pin::new(raw_r)).await?; - read_amt(Pin::new(raw_r), 2, &mut buffer).await?; + let bound_address = SOCKSv5Address::read(r).await?; + read_amt(r, 2, &mut buffer).await?; let bound_port = ((buffer[0] as u16) << 8) + (buffer[1] as u16); Ok(ServerResponse { @@ -162,7 +160,7 @@ standard_roundtrip!(server_response_roundtrips, ServerResponse); fn check_short_reads() { let empty = vec![]; let mut cursor = Cursor::new(empty); - let ys = ServerResponse::read(Pin::new(&mut cursor)); + let ys = ServerResponse::read(&mut cursor); assert_eq!(Err(DeserializationError::NotEnoughData), task::block_on(ys)); } @@ -170,7 +168,7 @@ fn check_short_reads() { fn check_bad_version() { let bad_ver = vec![6, 1, 1]; let mut cursor = Cursor::new(bad_ver); - let ys = ServerResponse::read(Pin::new(&mut cursor)); + let ys = ServerResponse::read(&mut cursor); assert_eq!( Err(DeserializationError::InvalidVersion(5, 6)), task::block_on(ys) @@ -181,7 +179,7 @@ fn check_bad_version() { fn check_bad_command() { let bad_cmd = vec![5, 32, 0x42]; let mut cursor = Cursor::new(bad_cmd); - let ys = ServerResponse::read(Pin::new(&mut cursor)); + let ys = ServerResponse::read(&mut cursor); assert_eq!( Err(DeserializationError::InvalidServerResponse(32)), task::block_on(ys) diff --git a/src/messages/utils.rs b/src/messages/utils.rs index 52a7c61..0ab874b 100644 --- a/src/messages/utils.rs +++ b/src/messages/utils.rs @@ -25,7 +25,7 @@ macro_rules! standard_roundtrip { let mut buffer = vec![]; task::block_on(xs.write(&mut buffer)).unwrap(); let mut cursor = Cursor::new(buffer); - let ys = <$t>::read(Pin::new(&mut cursor)); + let ys = <$t>::read(&mut cursor); xs == task::block_on(ys).unwrap() } } diff --git a/src/network/address.rs b/src/network/address.rs index eeecd6f..9f4b88b 100644 --- a/src/network/address.rs +++ b/src/network/address.rs @@ -13,7 +13,6 @@ use quickcheck::{quickcheck, Arbitrary, Gen}; use std::convert::TryFrom; use std::fmt; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; -use std::pin::Pin; use thiserror::Error; #[derive(Clone, Debug, Eq, Hash, PartialEq)] @@ -114,7 +113,7 @@ impl fmt::Display for SOCKSv5Address { impl SOCKSv5Address { pub async fn read( - mut r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut byte_buffer = [0u8; 1]; let amount_read = r.read(&mut byte_buffer).await?; @@ -228,7 +227,7 @@ quickcheck! { _ => { let buffer = [x, 0, 1, 2, 9, 10]; let mut cursor = Cursor::new(buffer); - let meh = SOCKSv5Address::read(Pin::new(&mut cursor)); + let meh = SOCKSv5Address::read(&mut cursor); Err(DeserializationError::InvalidAddressType(x)) == task::block_on(meh) } } diff --git a/src/serialize.rs b/src/serialize.rs index 5f5e424..0ec7fec 100644 --- a/src/serialize.rs +++ b/src/serialize.rs @@ -1,9 +1,8 @@ use crate::errors::{DeserializationError, SerializationError}; use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; -use std::pin::Pin; pub async fn read_string( - mut r: Pin<&mut R>, + r: &mut R, ) -> Result { let mut length_buffer = [0; 1]; @@ -40,7 +39,7 @@ pub async fn write_string( } pub async fn read_amt( - mut r: Pin<&mut R>, + r: &mut R, amt: usize, buffer: &mut [u8], ) -> Result<(), DeserializationError> { diff --git a/src/server.rs b/src/server.rs index 8105ff8..f991059 100644 --- a/src/server.rs +++ b/src/server.rs @@ -13,7 +13,6 @@ use async_std::io::prelude::WriteExt; use async_std::sync::{Arc, Mutex}; use async_std::task; use log::{error, info, trace, warn}; -use std::pin::Pin; use thiserror::Error; pub struct SOCKSv5Server { @@ -89,7 +88,7 @@ async fn run_authentication( addr: SOCKSv5Address, port: u16, ) -> Option { - match ClientGreeting::read(Pin::new(&mut stream)).await { + match ClientGreeting::read(&mut stream).await { Err(e) => { error!( "Client hello deserialization error from {}:{}: {}", @@ -126,7 +125,7 @@ async fn run_authentication( .contains(&AuthenticationMethod::UsernameAndPassword) && params.check_password.is_some() => { - match ClientUsernamePassword::read(Pin::new(&mut stream)).await { + match ClientUsernamePassword::read(&mut stream).await { Err(e) => { warn!( "Error reading username/password from {}:{}: {}", @@ -194,7 +193,7 @@ where N::Error: 'static, { loop { - let ccr = ClientConnectionRequest::read(Pin::new(&mut stream)).await?; + let ccr = ClientConnectionRequest::read(&mut stream).await?; match ccr.command_code { ClientConnectionCommand::AssociateUDPPort => {}