Skip to content

Commit fad7d42

Browse files
committed
Simplification
1 parent 83cace4 commit fad7d42

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

src/MongoDB.Driver/Core/Connections/Socks5Helper.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,10 @@ public static void PerformSocks5Handshake(Stream stream, EndPoint endPoint, stri
104104
// | 1 | 1 | 1 to 255 | 1 | 1 to 255 |
105105
// +----+------+----------+------+----------+
106106
buffer[0] = SubnegotiationVersion;
107-
#if NET472
108107
var usernameLength = EncodeString(proxyUsername, buffer, 2, nameof(proxyUsername));
109108
buffer[1] = (byte)usernameLength;
110109
var passwordLength = EncodeString(proxyPassword, buffer, 3 + usernameLength, nameof(proxyPassword));
111110
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
118111

119112
var authLength = 3 + usernameLength + passwordLength;
120113
stream.Write(buffer, 0, authLength);
@@ -178,11 +171,8 @@ public static void PerformSocks5Handshake(Stream stream, EndPoint endPoint, stri
178171
else
179172
{
180173
buffer[3] = AddressTypeDomain;
181-
#if NET472
182174
var hostLength = EncodeString(targetHost, buffer, 5, nameof(targetHost));
183-
#else
184-
var hostLength = EncodeString(targetHost, buffer.AsSpan(5), nameof(targetHost));
185-
#endif
175+
186176
buffer[4] = hostLength;
187177
addressLength = hostLength + 1;
188178
}
@@ -230,7 +220,6 @@ private static void VerifyProtocolVersion(byte version)
230220
}
231221
}
232222

233-
#if NET472
234223
private static byte EncodeString(string input, byte[] buffer, int offset, string parameterName)
235224
{
236225
try
@@ -243,18 +232,5 @@ private static byte EncodeString(string input, byte[] buffer, int offset, string
243232
throw new IOException($"The {parameterName} could not be encoded as UTF-8.");
244233
}
245234
}
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
259235
}
260236
}

0 commit comments

Comments
 (0)