frostfs-sdk-csharp/src/FrostFS.SDK.Cryptography/UUID.cs
p.gross 0c4723c705 [#3] Move to netstandard 2.0
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-05-30 11:47:51 +03:00

24 lines
569 B
C#

using Google.Protobuf;
using System;
namespace FrostFS.SDK.Cryptography;
public static class UUIDExtension
{
public static Guid ToUuid(this ByteString id)
{
return Guid.Parse(BitConverter.ToString(id.ToByteArray()).Replace("-", ""));
}
public static byte[] ToBytes(this Guid id)
{
var str = id.ToString("N");
var len = str.Length;
var bytes = new byte[len/2];
for (int i = 0; i < len; i += 2)
bytes[i/2] = Convert.ToByte(str.Substring(i, 2), 16);
return bytes;
}
}