[#11] Add Network Snapshot
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
b69d22966f
commit
c988ff3c76
84 changed files with 2238 additions and 933 deletions
54
src/FrostFS.SDK.Cryptography/Extentions.cs
Normal file
54
src/FrostFS.SDK.Cryptography/Extentions.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using Google.Protobuf;
|
||||
using Org.BouncyCastle.Crypto.Digests;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace FrostFS.SDK.Cryptography;
|
||||
|
||||
public static class Extentions
|
||||
{
|
||||
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)
|
||||
{
|
||||
using var sha256 = SHA256.Create();
|
||||
return sha256.ComputeHash(value.ToArray());
|
||||
}
|
||||
|
||||
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 ulong Murmur64(this byte[] value, uint seed)
|
||||
{
|
||||
using var murmur = new Murmur3_128(seed);
|
||||
return BinaryPrimitives.ReadUInt64LittleEndian(murmur.ComputeHash(value));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue