Remove a bunch of (hopefully) unnecessary Pins.
I believe these were introduced previously to solve a problem that we're no longer dealing with; specifically, if I remember correctly, we introduced these to deal with how we were going to implement a trait. However, they don't appear to be necessary any more, so we're going to get rid of them, so we won't need to deal with them any longer.
This commit is contained in:
@@ -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<R: AsyncRead + Send + Unpin>(
|
||||
mut r: Pin<&mut R>,
|
||||
r: &mut R,
|
||||
) -> Result<AuthenticationMethod, DeserializationError> {
|
||||
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)
|
||||
|
||||
@@ -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: AsyncRead + Send + Unpin>(
|
||||
r: Pin<&mut R>,
|
||||
r: &mut R,
|
||||
) -> Result<Self, DeserializationError> {
|
||||
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)
|
||||
|
||||
@@ -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: AsyncRead + Send + Unpin>(
|
||||
r: Pin<&mut R>,
|
||||
r: &mut R,
|
||||
) -> Result<ClientGreeting, DeserializationError> {
|
||||
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)
|
||||
|
||||
@@ -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: AsyncRead + Send + Unpin>(
|
||||
r: Pin<&mut R>,
|
||||
r: &mut R,
|
||||
) -> Result<Self, DeserializationError> {
|
||||
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)
|
||||
|
||||
@@ -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<R: AsyncRead + Send + Unpin>(
|
||||
mut r: Pin<&mut R>,
|
||||
r: &mut R,
|
||||
) -> Result<Self, DeserializationError> {
|
||||
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)
|
||||
|
||||
@@ -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<R: AsyncRead + Send + Unpin>(
|
||||
mut r: Pin<&mut R>,
|
||||
r: &mut R,
|
||||
) -> Result<Self, DeserializationError> {
|
||||
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)
|
||||
|
||||
@@ -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: AsyncRead + Send + Unpin>(
|
||||
r: Pin<&mut R>,
|
||||
r: &mut R,
|
||||
) -> Result<Self, DeserializationError> {
|
||||
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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user