Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ jobs:

strategy:
matrix:
dotnet: [ '8.0.x' ]
dotnet: [ '10.0.x' ]
name: .NET ${{ matrix.dotnet }}

steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
- name: Set up JDK 25
uses: actions/setup-java@v6
with:
java-version: 17
java-version: 25
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup .NET
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Cache SonarQube Cloud packages
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarQube Cloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
Expand All @@ -58,7 +58,7 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal --collect "XPlat Code Coverage;Format=opencover"
run: dotnet run --project TensionDev.UUID.Tests/TensionDev.UUID.Tests.csproj --no-build -- --coverlet --coverlet-output-format opencover
- name: SonarCloudAnalyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
Expand All @@ -69,24 +69,24 @@ jobs:

strategy:
matrix:
dotnet: [ '8.0.x' ]
dotnet: [ '10.0.x' ]
os: [macos-latest, ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}

name: .NET ${{ matrix.dotnet }} on ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup .NET
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal --collect "XPlat Code Coverage;Format=opencover"
run: dotnet run --project TensionDev.UUID.Tests/TensionDev.UUID.Tests.csproj --no-build -- --coverlet --coverlet-output-format opencover
10 changes: 4 additions & 6 deletions TensionDev.UUID.Tests/TensionDev.UUID.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<TargetFramework>net10.0</TargetFramework>

<IsPackable>false</IsPackable>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.MTP" Version="10.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="10.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions TensionDev.UUID/TensionDev.UUID.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0;net8.0;net10.0</TargetFrameworks>
<AssemblyName>TensionDev.UUID</AssemblyName>
<RootNamespace>TensionDev.UUID</RootNamespace>
<NuGetAuditMode>all</NuGetAuditMode>
Expand All @@ -10,15 +10,15 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageId>TensionDev.UUID</PackageId>
<Version>2.4.0</Version>
<Version>2.5.0</Version>
<Authors>TensionDev amsga</Authors>
<Company>TensionDev</Company>
<Product>TensionDev.UUID</Product>
<Description>TensionDev.UUID is a .NET library that supports multiple UUID versions (v1, v3, v4, v5, v6, v7) with strict RFC compliance.</Description>
<Copyright>Copyright (c) TensionDev 2021 - 2026</Copyright>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/TensionDev/UUIDUtil</PackageProjectUrl>
<RepositoryUrl>https://github.com/TensionDev/UUIDUtil</RepositoryUrl>
<PackageProjectUrl>https://github.com/TensionDev/UUID</PackageProjectUrl>
<RepositoryUrl>https://github.com/TensionDev/UUID</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>UUID GUID</PackageTags>
<PackageReleaseNotes>Change in license to Apache License 2.0.
Expand Down
22 changes: 22 additions & 0 deletions TensionDev.UUID/UUIDv1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
/// <summary>
/// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 1 (date-time and MAC address).
/// </summary>
public static class UUIDv1

Check warning on line 25 in TensionDev.UUID/UUIDv1.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv1' to match pascal case naming rules, consider using 'UuiDv1'.

Check warning on line 25 in TensionDev.UUID/UUIDv1.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv1' to match pascal case naming rules, consider using 'UuiDv1'.
{
private static System.Net.NetworkInformation.PhysicalAddress s_physicalAddress = System.Net.NetworkInformation.PhysicalAddress.None;
private static Int32 s_clock = Int32.MinValue;
private static readonly DateTime s_epoch = new DateTime(1582, 10, 15, 0, 0, 0, DateTimeKind.Utc);

#if NET9_0_OR_GREATER
private static readonly System.Threading.Lock s_initLock = new System.Threading.Lock();
private static readonly System.Threading.Lock s_clockLock = new System.Threading.Lock();
#else
private static readonly Object s_initLock = new Object();
private static readonly Object s_clockLock = new Object();
#endif

/// <summary>
/// Initialises a new GUID/UUID based on Version 1 (date-time and MAC address)
Expand Down Expand Up @@ -73,14 +78,14 @@
/// <exception cref="ArgumentException"></exception>
public static Uuid NewUUIDv1(DateTime dateTime, Byte[] clockSequence, Byte[] nodeID)
{
if (clockSequence == null)
throw new ArgumentNullException(nameof(clockSequence));

Check warning on line 82 in TensionDev.UUID/UUIDv1.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=TensionDev_UUIDUtil&issues=AaEWghEiVi_oXLD67lIB&open=AaEWghEiVi_oXLD67lIB&pullRequest=81

if (clockSequence.Length < 2)
throw new ArgumentException(String.Format("Clock Sequence contains less than 16-bit: {0} bytes", clockSequence.Length), nameof(clockSequence));

if (nodeID == null)
throw new ArgumentNullException(nameof(nodeID));

Check warning on line 88 in TensionDev.UUID/UUIDv1.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=TensionDev_UUIDUtil&issues=AaEWghEiVi_oXLD67lIC&open=AaEWghEiVi_oXLD67lIC&pullRequest=81

if (nodeID.Length < 6)
throw new ArgumentException(String.Format("Node ID contains less than 48-bit: {0} bytes", nodeID.Length), nameof(nodeID));
Expand Down Expand Up @@ -140,6 +145,14 @@
}
if (s_physicalAddress.Equals(System.Net.NetworkInformation.PhysicalAddress.None))
{
#if NET6_0_OR_GREATER
// Fallback to random
using var randomNumberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
Byte[] fakeNode = new Byte[6];
randomNumberGenerator.GetBytes(fakeNode);
fakeNode[0] = (Byte)(fakeNode[0] | 0x01);
s_physicalAddress = new System.Net.NetworkInformation.PhysicalAddress(fakeNode);
#else
// Fallback to random
using (var cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
Expand All @@ -148,6 +161,7 @@
fakeNode[0] = (Byte)(fakeNode[0] | 0x01);
s_physicalAddress = new System.Net.NetworkInformation.PhysicalAddress(fakeNode);
}
#endif
}
}

Expand All @@ -165,13 +179,21 @@
{
if (s_clock < 0)
{
#if NET6_0_OR_GREATER
using var randomNumberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
Byte[] clockInit = new Byte[4];
randomNumberGenerator.GetBytes(clockInit);
s_clock = BitConverter.ToInt32(clockInit, 0) & 0x3FFF;
s_clock |= 0x8000;
#else
using (System.Security.Cryptography.RNGCryptoServiceProvider cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
Byte[] clockInit = new Byte[4];
cryptoServiceProvider.GetBytes(clockInit);
s_clock = BitConverter.ToInt32(clockInit, 0) & 0x3FFF;
s_clock |= 0x8000;
}
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions TensionDev.UUID/UUIDv3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/// <summary>
/// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 3 (MD5 namespace name-based).
/// </summary>
public static class UUIDv3

Check warning on line 26 in TensionDev.UUID/UUIDv3.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv3' to match pascal case naming rules, consider using 'UuiDv3'.

Check warning on line 26 in TensionDev.UUID/UUIDv3.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv3' to match pascal case naming rules, consider using 'UuiDv3'.
{
/// <summary>
/// Initialises a new GUID/UUID based on Version 3 (MD5 namespace name-based)
Expand All @@ -39,10 +39,14 @@
Buffer.BlockCopy(nArray, 0, buffer, nsArray.Length, nArray.Length);

Byte[] hash;
#if NET6_0_OR_GREATER
hash = MD5.HashData(buffer);

Check failure on line 43 in TensionDev.UUID/UUIDv3.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a stronger hashing algorithm.

See more on https://sonarcloud.io/project/issues?id=TensionDev_UUIDUtil&issues=AaEWghGRVi_oXLD67lID&open=AaEWghGRVi_oXLD67lID&pullRequest=81
#else
using (MD5 md5 = MD5.Create())

Check warning on line 45 in TensionDev.UUID/UUIDv3.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Use a stronger hashing algorithm.
{
hash = md5.ComputeHash(buffer);
}
#endif

Byte[] hex = new Byte[16];

Expand Down
8 changes: 8 additions & 0 deletions TensionDev.UUID/UUIDv4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/// <summary>
/// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 4 (random).
/// </summary>
public static class UUIDv4

Check warning on line 24 in TensionDev.UUID/UUIDv4.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv4' to match pascal case naming rules, consider using 'UuiDv4'.

Check warning on line 24 in TensionDev.UUID/UUIDv4.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv4' to match pascal case naming rules, consider using 'UuiDv4'.
{
/// <summary>
/// Initialises a new GUID/UUID based on Version 4 (random)
Expand All @@ -33,12 +33,20 @@
Byte[] clockSequence = new Byte[2];
Byte[] nodeID = new Byte[6];

#if NET6_0_OR_GREATER
// Fallback to random
using var randomNumberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
randomNumberGenerator.GetBytes(time);
randomNumberGenerator.GetBytes(clockSequence);
randomNumberGenerator.GetBytes(nodeID);
#else
using (System.Security.Cryptography.RNGCryptoServiceProvider cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
cryptoServiceProvider.GetBytes(time);
cryptoServiceProvider.GetBytes(clockSequence);
cryptoServiceProvider.GetBytes(nodeID);
}
#endif

Byte[] hex = new Byte[16];

Expand Down
4 changes: 4 additions & 0 deletions TensionDev.UUID/UUIDv5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/// <summary>
/// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 5 (SHA-1 namespace name-based).
/// </summary>
public static class UUIDv5

Check warning on line 26 in TensionDev.UUID/UUIDv5.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv5' to match pascal case naming rules, consider using 'UuiDv5'.

Check warning on line 26 in TensionDev.UUID/UUIDv5.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv5' to match pascal case naming rules, consider using 'UuiDv5'.
{
/// <summary>
/// Initialises a new GUID/UUID based on Version 5 (SHA-1 namespace name-based)
Expand All @@ -39,10 +39,14 @@
Buffer.BlockCopy(nArray, 0, buffer, nsArray.Length, nArray.Length);

Byte[] hash;
#if NET6_0_OR_GREATER
hash = SHA1.HashData(buffer);

Check failure on line 43 in TensionDev.UUID/UUIDv5.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a stronger hashing algorithm.

See more on https://sonarcloud.io/project/issues?id=TensionDev_UUIDUtil&issues=AaEWghBnVi_oXLD67lH8&open=AaEWghBnVi_oXLD67lH8&pullRequest=81
#else
using (SHA1 sha1 = SHA1.Create())

Check warning on line 45 in TensionDev.UUID/UUIDv5.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Use a stronger hashing algorithm.

Check warning on line 45 in TensionDev.UUID/UUIDv5.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Use a stronger hashing algorithm.
{
hash = sha1.ComputeHash(buffer);
}
#endif

Byte[] hex = new Byte[16];

Expand Down
20 changes: 20 additions & 0 deletions TensionDev.UUID/UUIDv6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
/// <summary>
/// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 6 (date-time).
/// </summary>
public static class UUIDv6

Check warning on line 24 in TensionDev.UUID/UUIDv6.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv6' to match pascal case naming rules, consider using 'UuiDv6'.

Check warning on line 24 in TensionDev.UUID/UUIDv6.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv6' to match pascal case naming rules, consider using 'UuiDv6'.
{
private static Int32 s_clock = Int32.MinValue;
private static readonly DateTime s_epoch = new DateTime(1582, 10, 15, 0, 0, 0, DateTimeKind.Utc);

#if NET9_0_OR_GREATER
private static readonly System.Threading.Lock s_initLock = new System.Threading.Lock();
private static readonly System.Threading.Lock s_clockLock = new System.Threading.Lock();
#else
private static readonly Object s_initLock = new Object();
private static readonly Object s_clockLock = new Object();
#endif

/// <summary>
/// Initialises a new GUID/UUID based on Version 6 (date-time)
Expand Down Expand Up @@ -71,14 +76,14 @@
/// <exception cref="ArgumentException"></exception>
public static Uuid NewUUIDv6(DateTime dateTime, Byte[] clockSequence, Byte[] nodeID)
{
if (clockSequence == null)
throw new ArgumentNullException(nameof(clockSequence));

Check warning on line 80 in TensionDev.UUID/UUIDv6.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=TensionDev_UUIDUtil&issues=AaEWghClVi_oXLD67lH9&open=AaEWghClVi_oXLD67lH9&pullRequest=81

if (clockSequence.Length < 2)
throw new ArgumentException(String.Format("Clock Sequence contains less than 16-bit: {0} bytes", clockSequence.Length), nameof(clockSequence));

if (nodeID == null)
throw new ArgumentNullException(nameof(nodeID));

Check warning on line 86 in TensionDev.UUID/UUIDv6.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=TensionDev_UUIDUtil&issues=AaEWghClVi_oXLD67lH-&open=AaEWghClVi_oXLD67lH-&pullRequest=81

if (nodeID.Length < 6)
throw new ArgumentException(String.Format("Node ID contains less than 48-bit: {0} bytes", nodeID.Length), nameof(nodeID));
Expand Down Expand Up @@ -123,12 +128,19 @@
/// <returns>A byte-array representing the 48-bit Node ID</returns>
public static Byte[] GetNodeID()
{
#if NET6_0_OR_GREATER
using var randomNumberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
Byte[] fakeNode = new Byte[6];
randomNumberGenerator.GetBytes(fakeNode);
return fakeNode;
#else
using (System.Security.Cryptography.RNGCryptoServiceProvider cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
Byte[] fakeNode = new Byte[6];
cryptoServiceProvider.GetBytes(fakeNode);
return fakeNode;
}
#endif
}

/// <summary>
Expand All @@ -142,13 +154,21 @@
{
if (s_clock < 0)
{
#if NET6_0_OR_GREATER
using var randomNumberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
Byte[] clockInit = new Byte[4];
randomNumberGenerator.GetBytes(clockInit);
s_clock = BitConverter.ToInt32(clockInit, 0) & 0x3FFF;
s_clock |= 0x8000;
#else
using (System.Security.Cryptography.RNGCryptoServiceProvider cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
Byte[] clockInit = new Byte[4];
cryptoServiceProvider.GetBytes(clockInit);
s_clock = BitConverter.ToInt32(clockInit, 0) & 0x3FFF;
s_clock |= 0x8000;
}
#endif
}
}

Expand Down
23 changes: 23 additions & 0 deletions TensionDev.UUID/UUIDv7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@
/// <summary>
/// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 7 (date-time).
/// </summary>
public static class UUIDv7

Check warning on line 25 in TensionDev.UUID/UUIDv7.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv7' to match pascal case naming rules, consider using 'UuiDv7'.

Check warning on line 25 in TensionDev.UUID/UUIDv7.cs

View workflow job for this annotation

GitHub Actions / .NET 10.0.x

Rename class 'UUIDv7' to match pascal case naming rules, consider using 'UuiDv7'.
{
#if NETCOREAPP2_1_OR_GREATER
private static readonly DateTime s_epoch = DateTime.UnixEpoch;
#else
private static readonly DateTime s_epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
#endif

private static UInt16 s_counter = 0;

#if NET9_0_OR_GREATER
private static readonly System.Threading.Lock s_counterLock = new System.Threading.Lock();
#else
private static readonly Object s_counterLock = new Object();
#endif

/// <summary>
/// The method of generating the clock sequence and Node ID.
Expand Down Expand Up @@ -92,14 +101,14 @@
/// <exception cref="ArgumentException"></exception>
public static Uuid NewUUIDv7(DateTime dateTime, Byte[] randomA, Byte[] randomB)
{
if (randomA == null)
throw new ArgumentNullException(nameof(randomA));

Check warning on line 105 in TensionDev.UUID/UUIDv7.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=TensionDev_UUIDUtil&issues=AaEWghDiVi_oXLD67lH_&open=AaEWghDiVi_oXLD67lH_&pullRequest=81

if (randomA.Length < 2)
throw new ArgumentException(String.Format("rand_a contains less than 16-bit: {0} bytes", randomA.Length), nameof(randomA));

if (randomB == null)
throw new ArgumentNullException(nameof(randomB));

Check warning on line 111 in TensionDev.UUID/UUIDv7.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance

See more on https://sonarcloud.io/project/issues?id=TensionDev_UUIDUtil&issues=AaEWghDiVi_oXLD67lIA&open=AaEWghDiVi_oXLD67lIA&pullRequest=81

if (randomB.Length < 8)
throw new ArgumentException(String.Format("rand_b contains less than 64-bit: {0} bytes", randomB.Length), nameof(randomB));
Expand Down Expand Up @@ -143,12 +152,19 @@
/// <returns>A byte-array representing the 16-bit rand_a</returns>
public static Byte[] GetRandomA()
{
#if NET6_0_OR_GREATER
using var randomNumberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
Byte[] fakeNode = new Byte[2];
randomNumberGenerator.GetBytes(fakeNode);
return fakeNode;
#else
using (System.Security.Cryptography.RNGCryptoServiceProvider cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
Byte[] fakeNode = new Byte[2];
cryptoServiceProvider.GetBytes(fakeNode);
return fakeNode;
}
#endif
}

/// <summary>
Expand Down Expand Up @@ -197,12 +213,19 @@
/// <returns>A byte-array representing the 64-bit rand_b</returns>
public static Byte[] GetRandomB()
{
#if NET6_0_OR_GREATER
using var randomNumberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create();
Byte[] fakeNode = new Byte[8];
randomNumberGenerator.GetBytes(fakeNode);
return fakeNode;
#else
using (System.Security.Cryptography.RNGCryptoServiceProvider cryptoServiceProvider = new System.Security.Cryptography.RNGCryptoServiceProvider())
{
Byte[] fakeNode = new Byte[8];
cryptoServiceProvider.GetBytes(fakeNode);
return fakeNode;
}
#endif
}

/// <summary>
Expand Down
Loading
Loading