Skip to content

Commit 3dc18af

Browse files
author
Konstantina Chremmou
committed
CP-308539 Replaced obsolete code.
Signed-off-by: Konstantina Chremmou <[email protected]>
1 parent 7f812a7 commit 3dc18af

File tree

1 file changed

+10
-18
lines changed
  • ocaml/sdk-gen/csharp/autogen/src

1 file changed

+10
-18
lines changed

ocaml/sdk-gen/csharp/autogen/src/HTTP.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
using System.Security.Authentication;
3939
using System.Security.Cryptography;
4040
using System.Security.Cryptography.X509Certificates;
41-
4241
#if !(NET8_0_OR_GREATER)
4342
using System.Runtime.Serialization;
4443
#endif
@@ -303,7 +302,8 @@ private static bool ValidateServerCertificate(
303302
/// <returns>The secure hash as a hex string.</returns>
304303
private static string _MD5Hash(string str)
305304
{
306-
return ComputeHash(str, "MD5");
305+
using (var hasher = MD5.Create())
306+
return ComputeHash(hasher, str);
307307
}
308308

309309
/// <summary>
@@ -313,32 +313,24 @@ private static string _MD5Hash(string str)
313313
/// <returns>The secure hash as a hex string.</returns>
314314
private static string Sha256Hash(string str)
315315
{
316-
return ComputeHash(str, "SHA256");
316+
using (var hasher = SHA256.Create())
317+
return ComputeHash(hasher, str);
317318
}
318319

319-
private static string ComputeHash(string input, string method)
320+
private static string ComputeHash(HashAlgorithm hasher, string input)
320321
{
321-
if (input == null)
322+
if (hasher == null || input == null)
322323
return null;
323324

324325
var enc = new UTF8Encoding();
325326
byte[] bytes = enc.GetBytes(input);
326-
327-
using (var hasher = HashAlgorithm.Create(method))
328-
{
329-
if (hasher != null)
330-
{
331-
byte[] hash = hasher.ComputeHash(bytes);
332-
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
333-
}
334-
}
335-
336-
return null;
327+
byte[] hash = hasher.ComputeHash(bytes);
328+
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
337329
}
338330

339331
private static string GenerateNonce()
340332
{
341-
using (var rngCsProvider = new RNGCryptoServiceProvider())
333+
using (var rngCsProvider = RandomNumberGenerator.Create())
342334
{
343335
var nonceBytes = new byte[NONCE_LENGTH];
344336
rngCsProvider.GetBytes(nonceBytes);
@@ -492,7 +484,7 @@ public static Stream ConnectStream(Uri uri, IWebProxy proxy, bool nodelay, int t
492484
if (UseSSL(uri))
493485
{
494486
SslStream sslStream = new SslStream(stream, false, ValidateServerCertificate, null);
495-
sslStream.AuthenticateAsClient("", null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12, true);
487+
sslStream.AuthenticateAsClient("", null, SslProtocols.Tls12, true);
496488

497489
stream = sslStream;
498490
}

0 commit comments

Comments
 (0)