@@ -128,23 +128,21 @@ where
128
128
methods : Vec < AuthenticationMethod > ,
129
129
) -> Result < Vec < AuthenticationMethod > > {
130
130
debug ! (
131
- "Send version and method len [{}, {}]" ,
131
+ "Client's version and method len [{}, {}]" ,
132
132
consts:: SOCKS5_VERSION ,
133
133
methods. len( )
134
134
) ;
135
- // write the first 2 bytes which contains the SOCKS version and the methods len()
136
- self . socket
137
- . write ( & [ consts:: SOCKS5_VERSION , methods. len ( ) as u8 ] )
138
- . await
139
- . context ( "Couldn't write SOCKS version & methods len" ) ?;
135
+ // the first 2 bytes which contains the SOCKS version and the methods len()
136
+ let mut packet = vec ! [ consts:: SOCKS5_VERSION , methods. len( ) as u8 ] ;
140
137
141
138
let auth = methods. iter ( ) . map ( |l| l. as_u8 ( ) ) . collect :: < Vec < _ > > ( ) ;
142
-
143
139
debug ! ( "client auth methods supported: {:?}" , & auth) ;
140
+ packet. extend ( auth) ;
141
+
144
142
self . socket
145
- . write ( & auth )
143
+ . write_all ( & packet )
146
144
. await
147
- . context ( "Couldn't write supported auth methods" ) ?;
145
+ . context ( "Couldn't write SOCKS version & methods len & supported auth methods" ) ?;
148
146
149
147
// Return methods available
150
148
Ok ( methods)
@@ -218,23 +216,13 @@ where
218
216
let user_bytes = username. as_bytes ( ) ;
219
217
let pass_bytes = password. as_bytes ( ) ;
220
218
221
- // send username len
222
- self . socket
223
- . write ( & [ 1 , user_bytes. len ( ) as u8 ] )
224
- . await
225
- . context ( "Can't send username len" ) ?;
226
- self . socket
227
- . write ( user_bytes)
228
- . await
229
- . context ( "Can't send username" ) ?;
219
+ let mut packet: Vec < u8 > = vec ! [ 1 , user_bytes. len( ) as u8 ] ;
220
+ packet. extend ( user_bytes) ;
221
+ packet. push ( pass_bytes. len ( ) as u8 ) ;
222
+ packet. extend ( pass_bytes) ;
230
223
231
- // send password len
232
- self . socket
233
- . write ( & [ pass_bytes. len ( ) as u8 ] )
234
- . await
235
- . context ( "Can't send password len" ) ?;
236
224
self . socket
237
- . write ( pass_bytes )
225
+ . write_all ( & packet )
238
226
. await
239
227
. context ( "Can't send password" ) ?;
240
228
0 commit comments