GithubHelp home page GithubHelp logo

xoofx / blake3.net Goto Github PK

View Code? Open in Web Editor NEW
134.0 2.0 15.0 7.63 MB

Blake3.NET is a fast managed wrapper around the SIMD Rust implementations of the BLAKE3 cryptographic hash function.

License: Other

Shell 5.24% Rust 7.35% C# 87.41%
blake3 cryptography hash dotnet

blake3.net's Introduction

Blake3.NET Build Status Build Status NuGet

Blake3.NET is a fast managed wrapper around the SIMD Rust implementations of the BLAKE3 cryptographic hash function.

The current native version of BLAKE3 used by Blake3.NET is 1.4.1

Features

  • Compatible with .NET7.0+.
  • Fast interop with Span friendly API.
  • API similar to the Blake3 Rust API.
  • CPU SIMD Hardware accelerated with dynamic CPU feature detection.
  • Incremental update API via Hasher.
  • Support for multi-threading hashing via Hasher.UpdateWithJoin.

Usage

Hash a buffer directly:

var hash = Blake3.Hasher.Hash(Encoding.UTF8.GetBytes("BLAKE3"));
Console.WriteLine(hash);
// Prints f890484173e516bfd935ef3d22b912dc9738de38743993cfedf2c9473b3216a4

Or use the Hasher struct for incremental updates:

// Hasher is a disposable struct!
using var hasher = Blake3.Hasher.New();
hasher.Update(Encoding.UTF8.GetBytes("BLAKE3"));
var hash = hasher.Finalize();

Or seek in the output "stream" to any position:

using var hasher = Blake3.Hasher.New();
hasher.Update(Encoding.UTF8.GetBytes("BLAKE3"));
var hashAtPosition = new byte[1024];
var hash = hasher.Finalize(4242, hashAtPosition);

Or hash a stream on the go with Blake3Stream:

using var blake3Stream = new Blake3Stream(new MemoryStream());
blake3Stream.Write(Encoding.UTF8.GetBytes("BLAKE3"));
var hash = blake3Stream.ComputeHash();

Or produce a message authentication code using a 256-bit key:

using var blake3 = Hasher.NewKeyed(macKey);
blake3.UpdateWithJoin(message);
var tag = blake3.Finalize();
byte[] authenticationTag = tag.AsSpan().ToArray();

Or derive a subkey from a master key:

const string context = "[application] [commit timestamp] [purpose]";
using var blake3 = Hasher.NewDeriveKey(Encoding.UTF8.GetBytes(context));
blake3.Update(inputKeyingMaterial);
var derivedKey = blake3.Finalize();
byte[] subkey = derivedKey.AsSpan().ToArray();

Platforms

Blake3.NET is supported on the following platforms:

  • win-x64, win-x86, win-arm64, win-arm
  • linux-x64, linux-arm64, linux-arm
  • osx-x64, osx-arm64

Benchmarks

The benchmarks are running with BenchmarkDotNet .NET 5.0 and done on multiple different sizes compared with the following implementations:

  • Blake3.NET (Blake3 Native Version: 0.3.7)
  • Blake2Fast 2.0.0
  • System.Security.Cryptography.SHA256 of .NET 5.0

For the 1,000,000 bytes test, Blake3 is using the multi-threading version provided by Blake3 (Hasher.UpdateWithJoin method).

Results

  • In general, Blake3 is much faster than SHA256 which is depending on whether your CPU supports Intel SHA Extensions.
    • Blake3 can be from 2x to 10x times faster than SHA256
  • The multi-threading version can give a significant boost if the data to hash is big enough
  • Blake3 is usually working best on large input.

Results

The CPU before Intel Ice Lake or AMD Zen don't have the Intel SHA CPU extensions.

In that case, Blake3 is around 5x to 10x times faster than the built-in SHA256.

The following benchmark was ran on an Intel Core i7-4980HQ CPU 2.80GHz (Haswell):

Benchmarks

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.1139 (1909/November2018Update/19H2)
Intel Core i7-4980HQ CPU 2.80GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=5.0.100
  [Host]     : .NET Core 5.0 (CoreCLR 5.0.20.51904, CoreFX 5.0.20.51904), X64 RyuJIT
  DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.51904, CoreFX 5.0.20.51904), X64 RyuJIT
Method N Mean Error StdDev Median
Blake3 4 85.06 ns 1.704 ns 2.154 ns 83.55 ns
Blake2Fast 4 138.30 ns 0.755 ns 0.670 ns 138.36 ns
SHA256 4 531.82 ns 0.842 ns 0.788 ns 531.85 ns
Blake3 100 145.12 ns 2.899 ns 4.064 ns 142.56 ns
Blake2Fast 100 153.41 ns 3.057 ns 4.760 ns 150.66 ns
SHA256 100 803.32 ns 11.420 ns 8.916 ns 797.37 ns
Blake3 1000 999.01 ns 19.658 ns 26.908 ns 984.60 ns
Blake2Fast 1000 789.41 ns 15.814 ns 18.825 ns 784.82 ns
SHA256 1000 4,489.81 ns 84.032 ns 78.603 ns 4,525.27 ns
Blake3 10000 4,099.92 ns 49.985 ns 46.756 ns 4,121.94 ns
Blake2Fast 10000 7,593.55 ns 127.193 ns 112.753 ns 7,609.07 ns
SHA256 10000 40,799.82 ns 769.102 ns 1,386.850 ns 41,460.32 ns
Blake3 100000 28,491.58 ns 394.692 ns 369.195 ns 28,498.05 ns
Blake2Fast 100000 78,732.84 ns 648.124 ns 606.255 ns 78,887.56 ns
SHA256 100000 408,581.45 ns 2,359.416 ns 2,207.000 ns 409,059.91 ns
Blake3 1000000 138,481.22 ns 1,300.797 ns 1,216.767 ns 138,460.16 ns
Blake2Fast 1000000 724,092.30 ns 6,995.547 ns 6,543.639 ns 720,115.33 ns
SHA256 1000000 3,699,812.03 ns 37,739.460 ns 35,301.514 ns 3,678,276.17 ns

Results with SHA CPU extensions

If your CPU has Intel SHA CPU extensions, then Blake3 is on average ~2x times faster than SHA256.

The following benchmarks was ran on a AMD Ryzen 9 3900X:

Benchmarks

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19041.630 (2004/?/20H1)
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
.NET Core SDK=5.0.100
  [Host]     : .NET Core 5.0 (CoreCLR 5.0.20.51904, CoreFX 5.0.20.51904), X64 RyuJIT
  DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.51904, CoreFX 5.0.20.51904), X64 RyuJIT

Method N Mean Error StdDev
Blake3 4 77.86 ns 0.332 ns 0.310 ns
Blake2Fast 4 123.57 ns 0.939 ns 0.879 ns
SHA256 4 244.31 ns 1.157 ns 1.082 ns
Blake3 100 125.60 ns 0.497 ns 0.440 ns
Blake2Fast 100 124.48 ns 1.053 ns 0.985 ns
SHA256 100 279.82 ns 1.853 ns 1.734 ns
Blake3 1000 888.90 ns 0.873 ns 0.681 ns
Blake2Fast 1000 790.85 ns 4.364 ns 3.645 ns
SHA256 1000 700.81 ns 2.078 ns 1.842 ns
Blake3 10000 3,508.37 ns 23.411 ns 21.899 ns
Blake2Fast 10000 7,569.91 ns 40.661 ns 38.034 ns
SHA256 10000 4,922.90 ns 14.360 ns 13.432 ns
Blake3 100000 22,109.48 ns 47.699 ns 39.830 ns
Blake2Fast 100000 75,937.97 ns 223.972 ns 209.503 ns
SHA256 100000 48,655.78 ns 102.273 ns 95.666 ns
Blake3 1000000 117,936.94 ns 263.454 ns 246.435 ns
Blake2Fast 1000000 768,752.03 ns 1,836.783 ns 1,718.128 ns
SHA256 1000000 485,944.26 ns 1,326.657 ns 1,240.956 ns

How to Build?

You need to install the .NET 7 SDK or latest Visual Studio 2022. Then from the root folder:

$ dotnet build src -c Release

In order to rebuild the native binaries, you need to run the build scripts from lib/blake3_dotnet

License

This software is released under the BSD-Clause 2 license.

Author

Alexandre Mutel aka xoofx.

blake3.net's People

Contributors

rfrfrf avatar samuel-lucas6 avatar wegel avatar xoofx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

blake3.net's Issues

Support output size 512 bit?

Does this library support to generate hash BLAKE3 with 512 bit size, other any other size differ from 256 bit?

Enhancement: Support for older versions of .NET

I was wondering if it would possible to support .NET Core 3.1 by targeting .NET Standard 2.1. Forgive me if I missed something in the code that's .NET 5 only, but I think a lot of people are sticking with LTS versions of .NET. Awesome job on this library.

Blake3Extensions.AsSpan() Extension Method is error-prone

First of all, awesome project! I'm currently using it for file checksums, and it's going great.

I just want to report some unexpected behaviour.

I had a sub-method that called the AsSpan() extension method on a Hash. This sub-method returned the Span to other code.

I found that the data in this Span would change on its own. I think the expectation is that when you are returned a hash, that hash is somewhat immutable.

I have inspected the source code and noticed that the extension method returns a reference to the struct's backing memory at that point in time.

In my case, the reason this data changes is because the stack unwinds after returning from the sub-method, meaning the referenced data is no longer valid; but equally if this Hash were boxed, the garbage collector can move managed heap memory unless it is pinned.

In my case, it seems to function fine if the Span is consumed immediately after being obtained. This should be true if the Hash exists on the stack, and I believe should even survive further stack allocations as they are placed after the end of that memory region; but if it is on the heap, the GC could move it at any time.

I think there should be a warning when using this method, and in its current state, perhaps Hash should be restricted to the stack, e.g. make it a ref struct. I don't think this Span is guaranteed to be correct at any point in time if the Hash is heap-allocated, e.g. as a member of an object.

You could then have a warning along the lines of "The data in this span is short-lived. If you are not consuming it immediately, please copy it to another memory location".

I did read the documentation that I could find, and saw no mention of this. I feel it needs addressing, at minimum with a warning.

Can't compile blake3 in VS2019

hi
i am a student and my research is on blake3 hash function
i download your source code of blake3 in c# from github
and use visual studio 2019 to run the code and install [NET 5 SDK] as you say
But unfortunately the code not executed and the following error appear

"the debug profile "Blake3"is missing the path to the executable to debug"
Note that I did change the properties of project to executable

image

could you help me and guide me what can i do else to run the code , please ?
Best Regards

How can this be used with HMAC?

Excuse my ignored question but I just couldn't figure it out. From what I can tell, the cryptographic utilities of the standard library of dotnet appears to have an HMAC interface, but only a few solid implementations without much a way to derive yours using a custom hashing function. I can't quite tell why. I tried to look up a generic HMAC library on GitHub but I also failed to find one there. Is there something I am missing? Why is this appears to be quite difficult?

P.S.: I'm not a well-seasoned C# developer.

Error - Unable to load DLL 'blake3_dotnet' in .NET Framework 4.8

Hi!

First, thanks for the blake3 implementation for .NET.

I've setup a .netstandard 2.0 lib that uses Blake3 and published it in my private package feed.

But when I try to use that lib in my ASP.NET MVC 4,8 Web App, I got the following error: "Unable to load DLL 'blake3_dotnet': The specified module could not be found."

The dependency goes like these MyAspNet48WebApp -> MyNetStandard20Lib -> Blake3.Net.

The blake3.dll file is copied to the bin folder correctly, but what intrigues me is that the error message says that it's looking for a "blake3_dotnet" dll.

Do you have any thoughts here?

Thanks!

Q: Use with (binary) File (Stream)

Why are
hash1Str
and
hash2Str
not equal?

   class Program {
      static void Main(string[] args) {
         string hash1Str;
         using (BinaryReader reader = new BinaryReader(File.Open(args[0], FileMode.Open))) {
            using (var blake3Stream = new Blake3Stream(reader.BaseStream)) {
               blake3Stream.Seek(0, SeekOrigin.Begin);
               blake3Stream.ResetHash();
               Hash hash = blake3Stream.ComputeHash();
               hash1Str = hash.ToString();
            }
         }

         byte[] b = File.ReadAllBytes(args[0]);
         string hash2Str = Hasher.Hash(b).ToString();

         if (hash1Str != hash2Str) {
            Console.WriteLine("WHY?");
         }
      }
   }

It seems that the original blake3 exe (Windows) produces the hash2Str.

How can I use a stream to get the same result as hash2Str?

Q: How to output in 64 bytes

I am attempting to hash a string with a 64 byte output. Using var hash = Blake3.Hasher.Hash(Encoding.UTF8.GetBytes("BLAKE3"), 64); returned the hash in 32 bytes.
my code is simple but here it is:

                    Dim NStatus As String
                    NStatus = jResults("status")
                    Dim NDiff As String
                    NDiff = jResults("data")("difficulty")
                    Dim NBlock As String
                    NBlock = jResults("data")("block")
                    Dim NHeight As String
                    NHeight = jResults("data")("height")
                    Dim NTestnet As String
                    NTestnet = jResults("data")("testnet")
                    Dim NRecom As String
                    NRecom = jResults("data")("recommendation")
                    Dim NCoin As String
                    NCoin = jResults("coin")
                    Dim Walletb As String
                    Walletb = Wallet.Text
                    Dim NBase = String.Concat(Walletb, "-", Nonce, "-", NBlock, "-", NDiff)

                    Dim blakehash = Blake3.Hasher.Hash(Encoding.UTF8.GetBytes($"{Wallet.Text}-{Nonce}-{jResults("data")("block")}-{jResults("data")("difficulty")}")).ToString

Thank you for your time.

Getting blake3_dotnet.dll missing error

Hi,

I have installed the latest Blake3.NET package 0.5.1 in my application. But while running the code, getting an error like blake3_dotnet.dll is missing. Could you please help me on this issue?

Thanks,
Niyas

Hasher reports that it is not initalized or destroyed, or segfaults

I am using the 1.0.0 package from Nuget and compiling on a Debian bookworm x86_64 system. If I run the following code:

class Program
{
    static void Main()
    {
        var data = new byte[] { 1, 2, 3};
        Hash1(data);
        Hash2(data);
    }

    static void Hash1(byte[] data)
    {
        var hash = Blake3.Hasher.Hash(data);
        System.Console.WriteLine($"Hash 1 completed: {hash}");
    }

    static void Hash2(byte[] data)
    {
        var hasher = new Blake3.Hasher();
        hasher.Update(data);
        var hash = hasher.Finalize();
        System.Console.WriteLine($"Hash 2 completed: {hash}");
    }
}

I get this error:

Unhandled exception. System.NullReferenceException: The Hasher is not initialized or already destroyed.
   at Blake3.Hasher.ThrowNullReferenceException()
   at Blake3.Hasher.Update(ReadOnlySpan`1 data)
   at Program.Hash2(Byte[] data) in /home/fpr/fast_block_upload/c_sharp/main.cs:line 19
   at Program.Main() in /home/fpr/fast_block_upload/c_sharp/main.cs:line 7

Prior to attempting to simplify this example, I was encountering segmentation faults which in gdb pointed to blake3_finalize. Invoking Blake3.Hasher.Hash seems to work fine though.

Using LibraryImport instead of DllImport?

I ran a few benchmarks on my system, found the summaries interesting. I rebuilt the code with .NET Core 9.0-Preview 2, then ran these benchmarks:

  • Default with no changes
  • Removing the SuppressGCTransition attribute
  • Switching to LibraryImport
  • Setting DisableRuntimeMarshalling attribute

Short version: LibraryImport won handily on the 1,000,000 byte test

Summary default.txt
Summary with GC.txt
Summary with LibraryImport.txt
Summary with LibraryImport_DisableRuntimeMarshalling.txt

Unable to run a program with Blake3.NET on CentOS 7

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'blake3_dotnet' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
/app/bin/Debug/net7.0/runtimes/linux-x64/native/blake3_dotnet.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.13/blake3_dotnet.so: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/blake3_dotnet.so: cannot open shared object file: No such file or directory
/lib64/libc.so.6: version `GLIBC_2.28' not found (required by /app/bin/Debug/net7.0/runtimes/linux-x64/native/libblake3_dotnet.so)
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.13/libblake3_dotnet.so: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/libblake3_dotnet.so: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/runtimes/linux-x64/native/blake3_dotnet: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.13/blake3_dotnet: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/blake3_dotnet: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/runtimes/linux-x64/native/libblake3_dotnet: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.13/libblake3_dotnet: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/libblake3_dotnet: cannot open shared object file: No such file or directory

   at Blake3.Hasher.Hash(ReadOnlySpan`1 input)
   at Program.<Main>$(String[] args) in /app/Program.cs:line 3

I have built an asp.net core program with your Blake3.NET already and it work well on Ubuntu 22. But our costumers' machines are use CentOS 7. I noted that glibc used in Blake3.NET is higher than CentOS 7 and I also find issue #21. Some of my colleagues are Rust developers. They said that you could fix it by changing the compile target to x86_64-unknown-linux-musl. Is there any plan to change target to x86_64-unknown-linux-musl?

any easy way to expose keyed_hash() and derive_key()?

I heard from a programmer who went looking for .NET bindings that exposed those features, and they weren't able to find anything. I'm not up to speed on .NET myself, but if there's any way I can help with this (including making upstream changes) please let me know.

Not able to hash files

I'm using the code below. No matter which file name I pass, it keeps returning the same hash = af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262. I used the MemoryStream example from the main GitHub page for this project. Why is this not working? I know the file exists, so not an issue with that.

My project type is a .NET Core 6.0 Console App in Visual Studio 2022.

public static string Blake3(string filename)
{
    using var blake3Stream = new Blake3Stream(File.OpenRead(filename));

    var hash = blake3Stream.ComputeHash();

    return hash.ToString();
}

Docker Linux Container: System.DllNotFoundException: Unable to load shared library 'blake3_dotnet' or one of its dependencies.

Entire error msg:

System.DllNotFoundException: Unable to load shared library 'blake3_dotnet' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
/app/bin/Debug/net7.0/runtimes/linux-x64/native/blake3_dotnet.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.11/blake3_dotnet.so: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/blake3_dotnet.so: cannot open shared object file: No such file or directory
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /app/bin/Debug/net7.0/runtimes/linux-x64/native/libblake3_dotnet.so)
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.11/libblake3_dotnet.so: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/libblake3_dotnet.so: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/runtimes/linux-x64/native/blake3_dotnet: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.11/blake3_dotnet: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/blake3_dotnet: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/runtimes/linux-x64/native/libblake3_dotnet: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.11/libblake3_dotnet: cannot open shared object file: No such file or directory
/app/bin/Debug/net7.0/libblake3_dotnet: cannot open shared object file: No such file or directory

   at Blake3.Hasher.blake3_new()
   at Blake3.Hasher.New()
   at Blake3.Blake3Stream..ctor(Stream backendStream, Boolean dispose)
   at [SENSORED_PROJECT_NAME].Commons.Utilities.HashHelper.ComputeBlake3HashFile(String filePath) in [SENSORED_SOLUTION_PATH]\[SENSORED_PROJECT_NAME]\[SENSORED_PROJECT_NAME].Commons\Utilities\HashHelper.cs:line 47
   at [SENSORED_PROJECT_NAME].Services.UploadService.ValidateHash(String tempFilePath, FileInfoDTO fileInfo) in [SENSORED_SOLUTION_PATH]\[SENSORED_PROJECT_NAME]\[SENSORED_PROJECT_NAME]\Services\UploadService.cs:line 143
   at [SENSORED_PROJECT_NAME].Services.UploadService.UploadMultipleFileAsync(UploadMultipleFileDTO dto, Int32 clientId) in [SENSORED_SOLUTION_PATH]\[SENSORED_PROJECT_NAME]\[SENSORED_PROJECT_NAME]\Services\UploadService.cs:line 236
   at [SENSORED_PROJECT_NAME].Controllers.UploaderApiController.UploadMultipleFileAsync(UploadMultipleFileDTO dto) in [SENSORED_SOLUTION_PATH]\[SENSORED_PROJECT_NAME]\[SENSORED_PROJECT_NAME]\Controllers\UploaderApiController.cs:line 103
   at Blake3.Hasher.blake3_new()
   at Blake3.Hasher.New()
   at Blake3.Blake3Stream..ctor(Stream backendStream, Boolean dispose)
   at [SENSORED_PROJECT_NAME].Commons.Utilities.HashHelper.ComputeBlake3HashFile(String filePath) in [SENSORED_SOLUTION_PATH]\[SENSORED_PROJECT_NAME]\[SENSORED_PROJECT_NAME].Commons\Utilities\HashHelper.cs:line 47
   at [SENSORED_PROJECT_NAME].Services.UploadService.ValidateHash(String tempFilePath, FileInfoDTO fileInfo) in [SENSORED_SOLUTION_PATH]\[SENSORED_PROJECT_NAME]\[SENSORED_PROJECT_NAME]\Services\UploadService.cs:line 143
   at [SENSORED_PROJECT_NAME].Services.UploadService.UploadMultipleFileAsync(UploadMultipleFileDTO dto, Int32 clientId) in [SENSORED_SOLUTION_PATH]\[SENSORED_PROJECT_NAME]\[SENSORED_PROJECT_NAME]\Services\UploadService.cs:line 236
   at [SENSORED_PROJECT_NAME].Controllers.UploaderApiController.UploadMultipleFileAsync(UploadMultipleFileDTO dto) in [SENSORED_SOLUTION_PATH]\[SENSORED_PROJECT_NAME]\[SENSORED_PROJECT_NAME]\Controllers\UploaderApiController.cs:line 103

DOCKERFILE:

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["[SENSORED_PROJECT_NAME]/[SENSORED_PROJECT_NAME].csproj", "[SENSORED_PROJECT_NAME]/"]
RUN dotnet restore "[SENSORED_PROJECT_NAME]/[SENSORED_PROJECT_NAME].csproj"
COPY . .
WORKDIR "/src/[SENSORED_PROJECT_NAME]"
RUN dotnet build "[SENSORED_PROJECT_NAME].csproj" -c Release -o /app/build --os linux --arch x64

FROM build AS publish
RUN dotnet publish "[SENSORED_PROJECT_NAME].csproj" -c Release -o /app/publish /p:UseAppHost=false --os linux --arch x64

FROM base AS final
WORKDIR /app/bin/Release/net7.0-linux-x64/publish
COPY --from=publish /app/publish .
RUN apt-get update && apt-get install -y vim
ENTRYPOINT ["dotnet", "[SENSORED_PROJECT_NAME].dll"]

Container Directory:

/app# ls
Constants    Dockerfile  [SENSORED].csproj       Interfaces        MetalamaAspects  Program.cs  Repositories  Startup.cs  appsettings.Development.json  bin          obj
Controllers  Filters     [SENSORED].csproj.user  MapperProfile.cs  Migrations       Properties  Services      Utilities   appsettings.json              nlog.config
root@84faf2aed7ec:/app# cls 
bash: cls: command not found
root@84faf2aed7ec:/app# clear
root@84faf2aed7ec:/app# ls -la
total 36
drwxrwxrwx 1 root root 4096 Sep 29 11:26 .
drwxr-xr-x 1 root root 4096 Sep 29 11:54 ..
drwxrwxrwx 1 root root 4096 Sep 28 20:14 Constants
drwxrwxrwx 1 root root 4096 Sep 29 11:54 Controllers
-rwxrwxrwx 1 root root  989 Sep 29 10:28 Dockerfile
drwxrwxrwx 1 root root 4096 Sep 28 18:44 Filters
-rwxrwxrwx 1 root root 3750 Sep 28 18:44 [SENSORED].csproj
-rwxrwxrwx 1 root root  580 Sep 28 09:03 [SENSORED].csproj.user
drwxrwxrwx 1 root root 4096 Sep 24 15:05 Interfaces
-rwxrwxrwx 1 root root 1843 Sep 28 18:44 MapperProfile.cs
drwxrwxrwx 1 root root 4096 Sep 14 05:29 MetalamaAspects
drwxrwxrwx 1 root root 4096 Sep 28 18:44 Migrations
-rwxrwxrwx 1 root root  848 Sep 28 20:33 Program.cs
drwxrwxrwx 1 root root 4096 Sep 28 18:44 Properties
drwxrwxrwx 1 root root 4096 Sep 28 18:44 Repositories
drwxrwxrwx 1 root root 4096 Sep 28 18:44 Services
-rwxrwxrwx 1 root root 4808 Sep 29 11:26 Startup.cs
drwxrwxrwx 1 root root 4096 Sep 28 18:44 Utilities
-rwxrwxrwx 1 root root  127 Sep 28 18:44 appsettings.Development.json
-rwxrwxrwx 1 root root  323 Sep 28 20:39 appsettings.json
drwxrwxrwx 1 root root 4096 Sep 28 20:16 bin
-rwxrwxrwx 1 root root 1891 Sep 28 19:52 nlog.config
drwxrwxrwx 1 root root 4096 Sep 28 18:17 obj

Addition:

It works well if launch on windows 11.

[Question] What is the purpose of the methods 'HashResult.CopyFromBytes(Span<byte>)' and 'Blake3Hasher.ComputerHash(Span<byte>)'?

Hello!

First of all, amazing library! Thank you so much for this, this is the best Blake3 library in the C# world, and its very nice to be able to use the benefits of Blake3.

I have some questions about the API, I reviewed the Rust API, and could not find a solution.

What is the 'use-case' / reason why someone would use these methods? What do these methods do?

1.) CopyFromBytes

    public string ComputeHash(Span<byte> buffer)
    {
        // I compute a hash from bytes that I have gathered from other methods using .Write()....
        var hashResult = this._blake3Hasher.ComputeHash();
        
        // What is the purpose of this method? What would it 'do'?
        hashResult.CopyFromBytes(buffer);
        // ^^^^

        return hashResult.ToString();
    }

2.) ComputeHash(Bytes)

       //   I have gather some bytes to hash...
        this._blake3Hasher.Write(buffer);

        // Why would someone want to pass in 'bytes' to the compute hash?
        // They have already gatehred bytes from the .Write() method. What is the purpose 
        // of passing in the Span<byte> to ComputeHash(Span<byte>)?
        this._blake3Hasher.ComputeHash(buffer);

If anyone can point me to some more learning materials that would be great. the API on the readme is great, but it does not cover all of the methods of the library.

Thanks all

Is Hasher reentrant?

This is just a question:

Are the methods of the Hasher class reentrant, thus can we use a singleton (AddSingleton()) Hasher to pass it with dependency injection for the needs of processing many concurrent web requests?

Or, should we create a new instance (AddScoped()) for each request?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.