dust_devil_core/sandstorm/
auth_methods.rs1use std::io::Error;
2
3use tokio::io::{AsyncRead, AsyncWrite};
4
5use crate::{
6 serialize::{ByteRead, ByteWrite, SmallReadList, SmallWriteList},
7 socks5::AuthMethod,
8};
9
10use super::SandstormCommandType;
11
12pub struct ListAuthMethodsRequest;
14
15pub struct ListAuthMethodsResponse(
17 pub Vec<(AuthMethod, bool)>,
19);
20
21pub struct ListAuthMethodsResponseRef<'a>(
23 &'a [(AuthMethod, bool)],
25);
26
27impl ListAuthMethodsResponse {
28 pub fn as_ref(&self) -> ListAuthMethodsResponseRef {
29 ListAuthMethodsResponseRef(&self.0)
30 }
31}
32
33impl ByteRead for ListAuthMethodsRequest {
34 async fn read<R: AsyncRead + Unpin + ?Sized>(_reader: &mut R) -> Result<Self, Error> {
35 Ok(Self)
36 }
37}
38
39impl ByteWrite for ListAuthMethodsRequest {
40 async fn write<W: AsyncWrite + Unpin + ?Sized>(&self, writer: &mut W) -> Result<(), Error> {
41 SandstormCommandType::ListAuthMethods.write(writer).await
42 }
43}
44
45impl ByteRead for ListAuthMethodsResponse {
46 async fn read<R: AsyncRead + Unpin + ?Sized>(reader: &mut R) -> Result<Self, Error> {
47 Ok(Self(<SmallReadList<(AuthMethod, bool)> as ByteRead>::read(reader).await?.0))
48 }
49}
50
51impl ByteWrite for ListAuthMethodsResponse {
52 async fn write<W: AsyncWrite + Unpin + ?Sized>(&self, writer: &mut W) -> Result<(), Error> {
53 self.as_ref().write(writer).await
54 }
55}
56
57impl<'a> ByteWrite for ListAuthMethodsResponseRef<'a> {
58 async fn write<W: AsyncWrite + Unpin + ?Sized>(&self, writer: &mut W) -> Result<(), Error> {
59 (SandstormCommandType::ListAuthMethods, SmallWriteList(self.0)).write(writer).await
60 }
61}
62
63pub struct ToggleAuthMethodRequest(
65 pub AuthMethod,
67 pub bool,
69);
70
71pub struct ToggleAuthMethodResponse(
73 pub bool,
75);
76
77impl ByteRead for ToggleAuthMethodRequest {
78 async fn read<R: AsyncRead + Unpin + ?Sized>(reader: &mut R) -> Result<Self, Error> {
79 Ok(Self(AuthMethod::read(reader).await?, bool::read(reader).await?))
80 }
81}
82
83impl ByteWrite for ToggleAuthMethodRequest {
84 async fn write<W: AsyncWrite + Unpin + ?Sized>(&self, writer: &mut W) -> Result<(), Error> {
85 (SandstormCommandType::ToggleAuthMethod, self.0, self.1).write(writer).await
86 }
87}
88
89impl ByteRead for ToggleAuthMethodResponse {
90 async fn read<R: AsyncRead + Unpin + ?Sized>(reader: &mut R) -> Result<Self, Error> {
91 Ok(Self(bool::read(reader).await?))
92 }
93}
94
95impl ByteWrite for ToggleAuthMethodResponse {
96 async fn write<W: AsyncWrite + Unpin + ?Sized>(&self, writer: &mut W) -> Result<(), Error> {
97 (SandstormCommandType::ToggleAuthMethod, self.0).write(writer).await
98 }
99}