Skip to content

Commit ac7309c

Browse files
authored
Use Encoding.ASCII.GetBytes instead of open-coded loop in CreateSecKeyAndSecWebSocketAccept (#75130)
1 parent 6253a18 commit ac7309c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ private static KeyValuePair<string, string> CreateSecKeyAndSecWebSocketAccept()
494494
string secKey = Convert.ToBase64String(bytes.Slice(0, 16 /*sizeof(Guid)*/));
495495

496496
// Get the corresponding ASCII bytes for seckey+wsServerGuidBytes
497-
for (int i = 0; i < secKey.Length; i++) bytes[i] = (byte)secKey[i];
498-
wsServerGuidBytes.CopyTo(bytes.Slice(secKey.Length));
497+
int encodedSecKeyLength = Encoding.ASCII.GetBytes(secKey, bytes);
498+
wsServerGuidBytes.CopyTo(bytes.Slice(encodedSecKeyLength));
499499

500500
// Hash the seckey+wsServerGuidBytes bytes
501501
SHA1.TryHashData(bytes, bytes, out int bytesWritten);

0 commit comments

Comments
 (0)