Adds JetBrains.Annotations to reduce amount of false positives by static code analysis

This commit is contained in:
Jonathan Bourdon
2024-08-07 03:29:59 -04:00
parent f3b225d3a8
commit 7baf1146ac
42 changed files with 118 additions and 119 deletions

View File

@@ -2,7 +2,7 @@
/// <summary>
/// Adapted from https://raw.githubusercontent.com/uuidjs/uuid/main/src/v7.ts.
/// to match the uuidv7 generated on the client
/// to match the uuid v7 generated on the client
/// </summary>
public static class GuidHelper
{
@@ -27,14 +27,14 @@ public static class GuidHelper
var values = V7Bytes(randomValues, State.Msecs, State.Seq);
return new(values);
return new Guid(values);
}
private static void UpdateV7State(V7State state, long now, byte[] rnds)
private static void UpdateV7State(V7State state, long now, byte[] randomBytes)
{
if (now > state.Msecs)
{
state.Seq = (rnds[6] << 23) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
state.Seq = (randomBytes[6] << 23) | (randomBytes[7] << 16) | (randomBytes[8] << 8) | randomBytes[9];
state.Msecs = now;
}
else
@@ -47,7 +47,7 @@ public static class GuidHelper
}
}
private static byte[] V7Bytes(byte[] rnds, long? msecs = null, int? seq = null, byte[] buf = null, int offset = 0)
private static byte[] V7Bytes(byte[] randomBytes, long? msecs = null, int? seq = null, byte[]? buf = null, int offset = 0)
{
if (buf == null)
{
@@ -57,7 +57,7 @@ public static class GuidHelper
// Defaults
msecs ??= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
seq ??= ((rnds[6] & 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
seq ??= ((randomBytes[6] & 0x7f) << 24) | (randomBytes[7] << 16) | (randomBytes[8] << 8) | randomBytes[9];
// byte 0-5: timestamp (48 bits)
buf[offset++] = (byte)((msecs.Value / 0x10000000000) & 0xff);
@@ -80,14 +80,14 @@ public static class GuidHelper
buf[offset++] = (byte)((seq.Value >> 6) & 0xff);
// byte 10: sequence bits 0-5 (6 bits) | random (2 bits)
buf[offset++] = (byte)(((seq.Value << 2) & 0xff) | (rnds[10] & 0x03));
buf[offset++] = (byte)(((seq.Value << 2) & 0xff) | (randomBytes[10] & 0x03));
// bytes 11-15: random (40 bits)
buf[offset++] = rnds[11];
buf[offset++] = rnds[12];
buf[offset++] = rnds[13];
buf[offset++] = rnds[14];
buf[offset++] = rnds[15];
buf[offset++] = randomBytes[11];
buf[offset++] = randomBytes[12];
buf[offset++] = randomBytes[13];
buf[offset++] = randomBytes[14];
buf[offset] = randomBytes[15];
return buf;
}

View File

@@ -1,3 +1,5 @@
namespace Hutopy.Web.Common;
public class MissingClaimException(string claimName) : Exception;
public class MissingClaimException(
string claimName)
: Exception;