From b1aa46a5a366c3e4684a94f424d0b3adc86e5d61 Mon Sep 17 00:00:00 2001 From: DJGosnell Date: Mon, 15 Mar 2021 19:46:11 -0400 Subject: [PATCH] Added documentation. Fixed the internal modifiers on the hashes. --- src/DtronixHash/DtronixHash.csproj | 2 +- src/DtronixHash/MurMur3/MurMur3Hash128.cs | 18 ++++++++++++ src/DtronixHash/MurMur3/MurMur3Hash128X64.cs | 2 +- src/DtronixHash/MurMur3/MurMur3Hash128X86.cs | 2 +- src/DtronixHash/NcHashAlgorithm.cs | 31 ++++++++++++++++++++ src/DtronixHash/NcHashBuffer.cs | 23 +++++++++++++-- 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/src/DtronixHash/DtronixHash.csproj b/src/DtronixHash/DtronixHash.csproj index 84e4f25..39136c7 100644 --- a/src/DtronixHash/DtronixHash.csproj +++ b/src/DtronixHash/DtronixHash.csproj @@ -3,7 +3,7 @@ netstandard2.1;net5.0 true - 0.1.0 + 0.1.1 DtronixHash contains hashing algorithms utilizing modern .NET methodologies for simple and efficient usage. $(ProjectDir)..\..\artifacts\ Dtronix diff --git a/src/DtronixHash/MurMur3/MurMur3Hash128.cs b/src/DtronixHash/MurMur3/MurMur3Hash128.cs index 7df238b..bda5713 100644 --- a/src/DtronixHash/MurMur3/MurMur3Hash128.cs +++ b/src/DtronixHash/MurMur3/MurMur3Hash128.cs @@ -4,30 +4,48 @@ namespace DtronixHash.MurMur3 { + /// public abstract class MurMur3Hash128 : NcHashAlgorithm { + /// + /// Seed of this instance. + /// public uint Seed { get; } + + /// + /// Length of the read data. + /// public int Length { get; private set; } + + /// public override int HashSize => 128; + + /// public override int InputBlockSize => 128; + + /// public override int OutputBlockSize => 128; + /// protected MurMur3Hash128(uint seed) { Seed = seed; } + /// public override void Initialize() { Length = 0; } + /// public override void TransformBlock(ReadOnlyMemory memory) { // store the length of the hash (for use later) Length += memory.Length; } + /// public override Memory ComputeHash(Memory block) { Initialize(); diff --git a/src/DtronixHash/MurMur3/MurMur3Hash128X64.cs b/src/DtronixHash/MurMur3/MurMur3Hash128X64.cs index 6aaf4db..dfd150e 100644 --- a/src/DtronixHash/MurMur3/MurMur3Hash128X64.cs +++ b/src/DtronixHash/MurMur3/MurMur3Hash128X64.cs @@ -26,7 +26,7 @@ public class MurMur3Hash128X64 : MurMur3Hash128 - internal MurMur3Hash128X64(uint seed = 0) + public MurMur3Hash128X64(uint seed = 0) : base(seed) { Reset(); diff --git a/src/DtronixHash/MurMur3/MurMur3Hash128X86.cs b/src/DtronixHash/MurMur3/MurMur3Hash128X86.cs index 4892373..af3a883 100644 --- a/src/DtronixHash/MurMur3/MurMur3Hash128X86.cs +++ b/src/DtronixHash/MurMur3/MurMur3Hash128X86.cs @@ -22,7 +22,7 @@ public class MurMur3Hash128X86 : MurMur3Hash128 const uint C2 = 0xab0e9789; const uint C3 = 0x38b34ae5; const uint C4 = 0xa1e38b93; - internal MurMur3Hash128X86(uint seed = 0) + public MurMur3Hash128X86(uint seed = 0) : base(seed) { Reset(); diff --git a/src/DtronixHash/NcHashAlgorithm.cs b/src/DtronixHash/NcHashAlgorithm.cs index 147e99e..9702db6 100644 --- a/src/DtronixHash/NcHashAlgorithm.cs +++ b/src/DtronixHash/NcHashAlgorithm.cs @@ -7,12 +7,43 @@ namespace DtronixHash /// public abstract class NcHashAlgorithm { + /// + /// Size of the hash in bits. + /// public abstract int HashSize { get; } + + /// + /// Size of the full input blocks. + /// public abstract int InputBlockSize { get; } + + /// + /// Size of the hash result. + /// public abstract int OutputBlockSize { get; } + + /// + /// Resets the hash to its initial state. + /// public abstract void Initialize(); + + /// + /// Transforms the passed block of data into the hash. + /// + /// Data to hash. public abstract void TransformBlock(ReadOnlyMemory block); + + /// + /// Completes the input transformation and returns the block's hash. + /// + /// Hash of data. public abstract Memory FinalizeHash(); + + /// + /// Hashes the entire passed block and finalizes the output. + /// + /// Complete data to hash. + /// Hash of passed data. public abstract Memory ComputeHash(Memory block); } } \ No newline at end of file diff --git a/src/DtronixHash/NcHashBuffer.cs b/src/DtronixHash/NcHashBuffer.cs index fcac227..7f0f419 100644 --- a/src/DtronixHash/NcHashBuffer.cs +++ b/src/DtronixHash/NcHashBuffer.cs @@ -1,10 +1,10 @@ using System; -using System.Collections.Generic; -using System.Text; -using DtronixHash.MurMur3; namespace DtronixHash { + /// + /// Non Cryptographic Hash Buffer. + /// public class NcHashBuffer { private readonly NcHashAlgorithm _algorithm; @@ -12,6 +12,15 @@ public class NcHashBuffer private int _bufferPosition; private readonly int _blockSizeBytes; + /// + /// Algorithm used by the buffer. + /// + public NcHashAlgorithm Algorithm => _algorithm; + + /// + /// Creates a new instance of the Non Cryptographic Hash Buffer. + /// + /// Algorithm to use while hashing. public NcHashBuffer(NcHashAlgorithm algorithm) { _algorithm = algorithm; @@ -19,6 +28,10 @@ public NcHashBuffer(NcHashAlgorithm algorithm) _buffer = new Memory(new byte[_blockSizeBytes]); } + /// + /// Writes data to the managed hash algorithm. + /// + /// Data to hash. public void Write(ReadOnlyMemory data) { var remainder = data.Length & (_blockSizeBytes - 1); @@ -75,6 +88,10 @@ public void Write(ReadOnlyMemory data) } } + /// + /// Flushes any buffered data and returns the final hash result. + /// + /// Hash bytes public Memory FinalizeHash() { if(_bufferPosition > 0)