[#1] Define SDK structure

TODO: Вынести маппинг модель -> grpc в отдельный слой

Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
Ivan Pchelintsev 2024-05-02 11:18:44 +03:00
parent 905f683bf1
commit 2800fff041
57 changed files with 5760 additions and 0 deletions

View file

@ -0,0 +1,69 @@
using System.Buffers.Binary;
using System.Security.Cryptography;
using FrostFS.SDK.Cryptography.Tz;
using Google.Protobuf;
using Org.BouncyCastle.Crypto.Digests;
namespace FrostFS.SDK.Cryptography;
public static class Helper
{
public const int Sha256HashLength = 32;
internal static byte[] RIPEMD160(this byte[] value)
{
var hash = new byte[20];
var digest = new RipeMD160Digest();
digest.BlockUpdate(value, 0, value.Length);
digest.DoFinal(hash, 0);
return hash;
}
public static byte[] Sha256(this byte[] value)
{
using var sha256 = SHA256.Create();
return sha256.ComputeHash(value);
}
internal static byte[] Sha256(this byte[] value, int offset, int count)
{
using var sha256 = SHA256.Create();
return sha256.ComputeHash(value, offset, count);
}
internal static byte[] Sha256(this ReadOnlySpan<byte> value)
{
var buffer = new byte[32];
using var sha256 = SHA256.Create();
sha256.TryComputeHash(value, buffer, out _);
return buffer;
}
public static ByteString Sha256(this IMessage data)
{
return ByteString.CopyFrom(data.ToByteArray().Sha256());
}
public static ByteString Sha256(this ByteString data)
{
return ByteString.CopyFrom(data.ToByteArray().Sha256());
}
public static ByteString TzHash(this IMessage data)
{
return ByteString.CopyFrom(new TzHash().ComputeHash(data.ToByteArray()));
}
public static ByteString TzHash(this ByteString data)
{
return ByteString.CopyFrom(new TzHash().ComputeHash(data.ToByteArray()));
}
public static ulong Murmur64(this byte[] value, uint seed)
{
using var murmur = new Murmur3_128(seed);
return BinaryPrimitives.ReadUInt64LittleEndian(murmur.ComputeHash(value));
}
}