Skip to content

Commit 97fe17e

Browse files
committed
KnownHeader, AuthenticationHelper.Digest: Compatibility with .NET Standard 2.0
1 parent c7b4254 commit 97fe17e

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

StandardSocketsHttpHandler/Net/Http/Headers/KnownHeader.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public KnownHeader(string name, HttpHeaderType headerType, HttpHeaderParser pars
3434
_knownValues = knownValues;
3535

3636
_asciiBytesWithColonSpace = new byte[name.Length + 2]; // + 2 for ':' and ' '
37-
int asciiBytes = Encoding.ASCII.GetBytes(name, _asciiBytesWithColonSpace);
38-
Debug.Assert(asciiBytes == name.Length);
37+
Array.Copy(Encoding.ASCII.GetBytes(name), _asciiBytesWithColonSpace, name.Length);
3938
_asciiBytesWithColonSpace[_asciiBytesWithColonSpace.Length - 2] = (byte)':';
4039
_asciiBytesWithColonSpace[_asciiBytesWithColonSpace.Length - 1] = (byte)' ';
4140
}

StandardSocketsHttpHandler/Net/Http/SocketsHttpHandler/AuthenticationHelper.Digest.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ public static bool IsServerNonceStale(DigestResponse digestResponse)
190190
private static string GetRandomAlphaNumericString()
191191
{
192192
const int Length = 16;
193-
Span<byte> randomNumbers = stackalloc byte[Length * 2];
194-
RandomNumberGenerator.Fill(randomNumbers);
193+
byte[] randomNumbers = new byte[Length * 2];
194+
RandomNumberGenerator.Create().GetBytes(randomNumbers);
195195

196196
StringBuilder sb = StringBuilderCache.Acquire(Length);
197197
for (int i = 0; i < randomNumbers.Length;)
@@ -213,17 +213,13 @@ private static string ComputeHash(string data, string algorithm)
213213
#pragma warning restore CA5351
214214
{
215215
Span<byte> result = stackalloc byte[hash.HashSize / 8]; // HashSize is in bits
216-
bool hashComputed = hash.TryComputeHash(Encoding.UTF8.GetBytes(data), result, out int bytesWritten);
217-
Debug.Assert(hashComputed && bytesWritten == result.Length);
216+
result = hash.ComputeHash(Encoding.UTF8.GetBytes(data));
218217

219218
StringBuilder sb = StringBuilderCache.Acquire(result.Length * 2);
220219

221-
Span<char> byteX2 = stackalloc char[2];
222220
for (int i = 0; i < result.Length; i++)
223221
{
224-
bool formatted = result[i].TryFormat(byteX2, out int charsWritten, "x2");
225-
Debug.Assert(formatted && charsWritten == 2);
226-
sb.Append(byteX2);
222+
sb.Append(result[i].ToString("x2"));
227223
}
228224

229225
return StringBuilderCache.GetStringAndRelease(sb);

0 commit comments

Comments
 (0)