Skip to content

Commit

Permalink
Add ComputeHash overload methods in HashProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Jul 4, 2024
1 parent 3e1b22e commit d28a4ee
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/BeeNet.Util/Hasher/HashProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Etherna.BeeNet.Models;
using Nethereum.Util.HashProviders;
using Org.BouncyCastle.Crypto.Digests;
using System;

namespace Etherna.BeeNet.Hasher
{
Expand All @@ -24,12 +25,20 @@ public class HashProvider : IHashProvider
private readonly KeccakDigest hasher = new(256);

// Methods.
public void ComputeHash(byte[] data, Span<byte> output)
{
hasher.BlockUpdate(data);
hasher.DoFinal(output);
}

public byte[] ComputeHash(byte[] data)
{
var result = new byte[SwarmHash.HashSize];
hasher.BlockUpdate(data);
hasher.DoFinal(result);
ComputeHash(data, result);
return result;
}

public byte[] ComputeHash(string data) =>
ComputeHash(System.Text.Encoding.UTF8.GetBytes(data));
}
}

0 comments on commit d28a4ee

Please sign in to comment.