sharp-chat/SharpChatCommon/ByteArrayExtensions.cs

23 lines
524 B
C#
Raw Permalink Normal View History

using System.Text;
namespace SharpChat;
public static class ByteArrayExtensions {
public static string GetUtf8String(this byte[] buffer) {
return Encoding.UTF8.GetString(buffer);
}
public static bool SlowEquals(this byte[] buffer, byte[] other) {
if(buffer.Length != other.Length)
return false;
int i = 0;
int result = 0;
while(i < buffer.Length) {
result |= buffer[i] ^ other[i];
++i;
}
return result == 0;
}
}