@@ -122,7 +122,7 @@ public class Program
122122{
123123 static void Main ()
124124 {
125- IAdler32 adler32 = HashFactory <IAdler32 >.Instance . Create ();
125+ IAdler32 adler32 = HashFactory <IAdler32 >.Create ();
126126 IHashValue computedHash = adler32 .ComputeHash (" foobar" );
127127
128128 Console .WriteLine (computedHash .AsHexString ());
@@ -140,14 +140,67 @@ public class Program
140140{
141141 static void Main ()
142142 {
143- IHashFunctionBase adler32 = HashFactory .Instance . Create (typeof (IAdler32 ));
143+ IHashFunctionBase adler32 = HashFactory .Create (typeof (IAdler32 ));
144144 IHashValue computedHash = adler32 .ComputeHash (" foobar" );
145145
146146 Console .WriteLine (computedHash .AsHexString ());
147147 }
148148}
149149```
150150
151+ ## Batch Computation Examples
152+ Thanks to our latest design, we can now calculate multiple hashes at once, in case, for some reason, they need all cryptographic or non-cryptographic hashes.
153+
154+ ### Example using 'System.Type' to compute all non-cryptographic hashes:
155+ ``` CSharp
156+ IHashFunctionBase [] functions = HashFactory .GetHashFunctions (HashFunctionType .Noncryptographic , new Dictionary <Type , IHashConfigBase >()
157+ {
158+
159+ // Only adding configs that require us to pick or define one, for the rest of the hash algorithms, the default provided configs will be used instead.
160+ { typeof (ICRC ), CRCConfig .CRC32 },
161+ { typeof (IPearson ), new WikipediaPearsonConfig () },
162+ { typeof (IFNV1 ), FNVConfig .GetPredefinedConfig (32 ) },
163+ { typeof (IFNV1a ), FNVConfig .GetPredefinedConfig (32 ) },
164+ { typeof (IBuzHash ), new DefaultBuzHashConfig () },
165+
166+ });
167+
168+ Assert .NotNull (functions );
169+ Assert .NotEmpty (functions );
170+ Assert .All (functions , item => Assert .NotNull (item ));
171+
172+ foreach (IHashFunctionBase function in functions )
173+ {
174+ IHashValue hv = function .ComputeHash (TestConstants .FooBar );
175+ Assert .NotNull (hv );
176+ Assert .NotEmpty (hv .Hash );
177+ }
178+ ```
179+
180+ ### Example using 'System.Type' to compute all cryptographic hashes except ` IHashAlgorithmWrapper ` :
181+ ``` CSharp
182+ IHashFunctionBase [] functions = HashFactory .GetHashFunctions (HashFunctionType .Cryptographic , new Dictionary <Type , IHashConfigBase >()
183+ {
184+
185+ // Only adding configs that require us to pick or define one, for the rest of the hash algorithms, the default provided configs will be used instead.
186+ { typeof (IArgon2id ), Argon2idConfig .OWASP_Standard }
187+
188+ }, typeof (IHashAlgorithmWrapper )); // We do not want IHashAlgorithmWrapper, though you can add as many as you want to ignore, including base interfaces to ignore all derived interfaces (such as IFNV to also ignore IFNV1 and IFNV1a).
189+
190+ Assert .NotNull (functions );
191+ Assert .NotEmpty (functions );
192+ Assert .All (functions , item => Assert .NotNull (item ));
193+
194+ foreach (IHashFunctionBase function in functions )
195+ {
196+ IHashValue hv = function .ComputeHash (TestConstants .FooBar );
197+ Assert .NotNull (hv );
198+ Assert .NotEmpty (hv .Hash );
199+
200+ (function as ICryptographicHashFunctionBase ).Dispose ();
201+ }
202+ ```
203+
151204There are a lot more changes made to the library, and feel free to explore them by adding to your project.
152205We'd love to see what you are going to do or have done with our library, so feel free to share them with us at https://discord.gg/PrKery9 .
153206
@@ -191,3 +244,4 @@ HashifyNET is released under the terms of the MIT license. See [LICENSE](https:/
191244
192245
193246
247+
0 commit comments