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
23 changes: 10 additions & 13 deletions src/Neo.FileStorage.API/Neo.FileStorage.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Company>The Neo Project</Company>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<VersionPrefix>3.7.5</VersionPrefix>
<VersionPrefix>3.8.1</VersionPrefix>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<AnalysisLevel>latest</AnalysisLevel>
Expand Down Expand Up @@ -52,17 +52,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.3" />
<PackageReference Include="Grpc.Net.Client" Version="2.67.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.67.0" />
<PackageReference Include="Grpc.Tools" Version="2.69.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="BouncyCastle.NetCore" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Sprache" Version="2.3.1" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="Google.Protobuf" Version="3.32.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.71.0" />
<PackageReference Include="Grpc.Tools" Version="2.72.0" PrivateAssets="all" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.*" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.*" />
<PackageReference Include="Sprache" Version="2.3.*" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.*" />
</ItemGroup>

</Project>
</Project>
163 changes: 82 additions & 81 deletions src/Neo.FileStorage.API/cryptography/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,100 +17,101 @@
using System.Buffers.Binary;
using System.Security.Cryptography;

namespace Neo.FileStorage.API.Cryptography;

public static class Helper
namespace Neo.FileStorage.API.Cryptography
{
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)
public static class Helper
{
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 const int Sha256HashLength = 32;

public static ByteString Sha256(this ByteString data)
{
return ByteString.CopyFrom(data.ToByteArray().Sha256());
}
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);
}

public static Checksum Sha256Checksum(this IMessage data)
{
return new Checksum
internal static byte[] Sha256(this byte[] value, int offset, int count)
{
Type = ChecksumType.Sha256,
Sum = data.Sha256()
};
}
using var sha256 = SHA256.Create();
return sha256.ComputeHash(value, offset, count);
}

public static Checksum Sha256Checksum(this ByteString data)
{
return new Checksum
internal static byte[] Sha256(this ReadOnlySpan<byte> value)
{
Type = ChecksumType.Sha256,
Sum = data.Sha256()
};
}
var buffer = new byte[32];
using var sha256 = SHA256.Create();
sha256.TryComputeHash(value, buffer, out _);
return buffer;
}

public static ByteString TzHash(this IMessage data)
{
return ByteString.CopyFrom(new TzHash().ComputeHash(data.ToByteArray()));
}
public static ByteString Sha256(this IMessage data)
{
return ByteString.CopyFrom(data.ToByteArray().Sha256());
}

public static ByteString TzHash(this ByteString data)
{
return ByteString.CopyFrom(new TzHash().ComputeHash(data.ToByteArray()));
}
public static ByteString Sha256(this ByteString data)
{
return ByteString.CopyFrom(data.ToByteArray().Sha256());
}

public static Checksum TzChecksum(this IMessage data)
{
return new Checksum
public static Checksum Sha256Checksum(this IMessage data)
{
Type = ChecksumType.Sha256,
Sum = data.TzHash()
};
}
return new Checksum
{
Type = ChecksumType.Sha256,
Sum = data.Sha256()
};
}

public static Checksum Sha256Checksum(this ByteString data)
{
return new Checksum
{
Type = ChecksumType.Sha256,
Sum = data.Sha256()
};
}

public static ByteString TzHash(this IMessage data)
{
return ByteString.CopyFrom(new TzHash().ComputeHash(data.ToByteArray()));
}

public static Checksum TzChecksum(this ByteString data)
{
return new Checksum
public static ByteString TzHash(this ByteString data)
{
Type = ChecksumType.Sha256,
Sum = data.TzHash()
};
}
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));
public static Checksum TzChecksum(this IMessage data)
{
return new Checksum
{
Type = ChecksumType.Sha256,
Sum = data.TzHash()
};
}

public static Checksum TzChecksum(this ByteString data)
{
return new Checksum
{
Type = ChecksumType.Sha256,
Sum = data.TzHash()
};
}

public static ulong Murmur64(this byte[] value, uint seed)
{
using var murmur = new Murmur3_128(seed);
return BinaryPrimitives.ReadUInt64LittleEndian(murmur.ComputeHash(value));
}
}
}
Loading