@@ -104,17 +104,10 @@ public static void PerformSocks5Handshake(Stream stream, EndPoint endPoint, stri
104
104
// | 1 | 1 | 1 to 255 | 1 | 1 to 255 |
105
105
// +----+------+----------+------+----------+
106
106
buffer [ 0 ] = SubnegotiationVersion ;
107
- #if NET472
108
107
var usernameLength = EncodeString ( proxyUsername , buffer , 2 , nameof ( proxyUsername ) ) ;
109
108
buffer [ 1 ] = ( byte ) usernameLength ;
110
109
var passwordLength = EncodeString ( proxyPassword , buffer , 3 + usernameLength , nameof ( proxyPassword ) ) ;
111
110
buffer [ 2 + usernameLength ] = ( byte ) passwordLength ;
112
- #else
113
- usernameLength = EncodeString ( proxyUsername . AsSpan ( ) , buffer . AsSpan ( 2 ) , nameof ( proxyUsername ) ) ;
114
- buffer [ 1 ] = ( byte ) usernameLength ;
115
- passwordLength = EncodeString ( proxyPassword . AsSpan ( ) , buffer . AsSpan ( 3 + usernameLength ) , nameof ( proxyPassword ) ) ;
116
- buffer [ 2 + usernameLength ] = ( byte ) passwordLength ;
117
- #endif
118
111
119
112
var authLength = 3 + usernameLength + passwordLength ;
120
113
stream . Write ( buffer , 0 , authLength ) ;
@@ -178,11 +171,8 @@ public static void PerformSocks5Handshake(Stream stream, EndPoint endPoint, stri
178
171
else
179
172
{
180
173
buffer [ 3 ] = AddressTypeDomain ;
181
- #if NET472
182
174
var hostLength = EncodeString ( targetHost , buffer , 5 , nameof ( targetHost ) ) ;
183
- #else
184
- var hostLength = EncodeString ( targetHost , buffer . AsSpan ( 5 ) , nameof ( targetHost ) ) ;
185
- #endif
175
+
186
176
buffer [ 4 ] = hostLength ;
187
177
addressLength = hostLength + 1 ;
188
178
}
@@ -230,7 +220,6 @@ private static void VerifyProtocolVersion(byte version)
230
220
}
231
221
}
232
222
233
- #if NET472
234
223
private static byte EncodeString ( string input , byte [ ] buffer , int offset , string parameterName )
235
224
{
236
225
try
@@ -243,18 +232,5 @@ private static byte EncodeString(string input, byte[] buffer, int offset, string
243
232
throw new IOException ( $ "The { parameterName } could not be encoded as UTF-8.") ;
244
233
}
245
234
}
246
- #else
247
- private static byte EncodeString ( ReadOnlySpan < char > chars , Span < byte > buffer , string parameterName )
248
- {
249
- try
250
- {
251
- return checked ( ( byte ) Encoding . UTF8 . GetBytes ( chars , buffer ) ) ;
252
- }
253
- catch
254
- {
255
- throw new IOException ( $ "The { parameterName } could not be encoded as UTF-8.") ;
256
- }
257
- }
258
- #endif
259
235
}
260
236
}
0 commit comments