Skip to content

Commit 7293e2f

Browse files
committed
Add Utility.EmptyByteArray.
1 parent b324d4d commit 7293e2f

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/MySqlConnector/Protocol/Payloads/AuthenticationMethodSwitchRequestPayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static AuthenticationMethodSwitchRequestPayload Create(ReadOnlySpan<byte>
2323
// if the packet is just the header byte (0xFE), it's an "Old Authentication Method Switch Request Packet"
2424
// (possibly sent by a server that doesn't support CLIENT_PLUGIN_AUTH)
2525
name = "mysql_old_password";
26-
data = new byte[0];
26+
data = Utility.EmptyByteArray;
2727
}
2828
else
2929
{
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using MySqlConnector.Utilities;
2+
13
namespace MySqlConnector.Protocol.Payloads
24
{
35
internal static class EmptyPayload
46
{
5-
public static PayloadData Instance { get; } = new PayloadData(new byte[0]);
7+
public static PayloadData Instance { get; } = new PayloadData(Utility.EmptyByteArray);
68
}
79
}

src/MySqlConnector/Protocol/Serialization/AuthenticationUtility.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
using System;
33
using System.Security.Cryptography;
44
using System.Text;
5+
using MySqlConnector.Utilities;
56

67
namespace MySqlConnector.Protocol.Serialization
78
{
89
internal static class AuthenticationUtility
910
{
1011
public static byte[] CreateAuthenticationResponse(byte[] challenge, int offset, string password) =>
11-
string.IsNullOrEmpty(password) ? s_emptyArray : HashPassword(challenge, offset, password);
12+
string.IsNullOrEmpty(password) ? Utility.EmptyByteArray : HashPassword(challenge, offset, password);
1213

1314
/// <summary>
1415
/// Hashes a password with the "Secure Password Authentication" method.
@@ -39,12 +40,10 @@ public static byte[] HashPassword(byte[] challenge, int offset, string password)
3940
}
4041
}
4142

42-
static readonly byte[] s_emptyArray = new byte[0];
43-
4443
public static byte[] CreateScrambleResponse(byte[] nonce, string password)
4544
{
4645
var scrambleResponse = string.IsNullOrEmpty(password)
47-
? s_emptyArray
46+
? Utility.EmptyByteArray
4847
: HashPasswordWithNonce(nonce, password);
4948

5049
return scrambleResponse;

src/MySqlConnector/Utilities/Utility.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,13 @@ public static Task<T> TaskFromException<T>(Exception exception)
347347
tcs.SetException(exception);
348348
return tcs.Task;
349349
}
350+
351+
public static byte[] EmptyByteArray { get; } = new byte[0];
350352
#else
351353
public static Task CompletedTask => Task.CompletedTask;
352354
public static Task TaskFromException(Exception exception) => Task.FromException(exception);
353355
public static Task<T> TaskFromException<T>(Exception exception) => Task.FromException<T>(exception);
356+
public static byte[] EmptyByteArray { get; } = Array.Empty<byte>();
354357
#endif
355358

356359
#if !NETSTANDARD2_1 && !NETCOREAPP3_0

0 commit comments

Comments
 (0)