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:
2021-10-09 15:22:10 -07:00
parent a2c57e4c76
commit 0d35f1cdb3
12 changed files with 48 additions and 63 deletions

View File

@@ -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)]

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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()
}
}

View File

@@ -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<R: AsyncRead + Send + Unpin>(
mut r: Pin<&mut R>,
r: &mut R,
) -> Result<Self, DeserializationError> {
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)
}
}

View File

@@ -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<R: AsyncRead + Send + Unpin>(
mut r: Pin<&mut R>,
r: &mut R,
) -> Result<String, DeserializationError> {
let mut length_buffer = [0; 1];
@@ -40,7 +39,7 @@ pub async fn write_string<W: AsyncWrite + Send + Unpin>(
}
pub async fn read_amt<R: AsyncRead + Send + Unpin>(
mut r: Pin<&mut R>,
r: &mut R,
amt: usize,
buffer: &mut [u8],
) -> Result<(), DeserializationError> {

View File

@@ -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<N: Networklike> {
@@ -89,7 +88,7 @@ async fn run_authentication(
addr: SOCKSv5Address,
port: u16,
) -> Option<GenericStream> {
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 => {}