frostfs-sdk-csharp/src/FrostFS.SDK.Cryptography/Tz/Helper.cs
p.gross 4ea24e958c
Some checks failed
DCO / DCO (pull_request) Failing after 42s
Move to netstandard 2.0
2024-05-29 13:19:12 +03:00

30 lines
615 B
C#

using System;
using System.Security.Cryptography;
namespace FrostFS.SDK.Cryptography.Tz;
public static class Helper
{
public static ulong NextUlong(this RandomNumberGenerator rng)
{
var buff = new byte[8];
rng.GetBytes(buff);
return BitConverter.ToUInt64(buff, 0);
}
public static int GetLeadingZeros(ulong value)
{
var i = 64;
while (value != 0)
{
value >>= 1;
i--;
}
return i;
}
public static int GetNonZeroLength(this ulong value)
{
return 64 - GetLeadingZeros(value);
}
}