Skip to content

Commit 37b70f7

Browse files
authored
Update the examples in the README file
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 31ecc73 commit 37b70f7

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

README.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,22 @@ Thanks to our latest design, we can now calculate multiple hashes at once, in ca
205205

206206
### Example using 'System.Type' to compute all non-cryptographic hashes:
207207
``` CSharp
208-
IHashFunctionBase[] functions = HashFactory.CreateHashAlgorithms(HashFunctionType.Noncryptographic, new Dictionary<Type, IHashConfigBase>()
208+
IHashFunctionBase[] functions = HashFactory.CreateHashAlgorithms(HashFunctionType.Noncryptographic, new Dictionary<Type, IHashConfigBase>()
209209
{
210210

211-
// 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.
212-
{ typeof(ICRC), CRCConfig.CRC32 },
213-
{ typeof(IPearson), new WikipediaPearsonConfig() },
214-
{ typeof(IFNV1), FNVConfig.GetPredefinedConfig(32) },
215-
{ typeof(IFNV1a), FNVConfig.GetPredefinedConfig(32) },
216-
{ typeof(IBuzHash), new DefaultBuzHashConfig() },
211+
// 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.
212+
{ typeof(ICRC), new CRCConfigProfileCRC32() },
213+
{ typeof(IPearson), new PearsonConfigProfileWikipedia() },
214+
{ typeof(IFNV1), new FNVConfigProfile32Bits()},
215+
{ typeof(IFNV1a), new FNVConfigProfile32Bits() },
216+
{ typeof(IBuzHash), new BuzHashConfigProfileDefault() },
217217

218218
});
219219

220-
Assert.NotNull(functions);
221-
Assert.NotEmpty(functions);
222-
Assert.All(functions, item => Assert.NotNull(item));
223-
224220
foreach (IHashFunctionBase function in functions)
225221
{
226-
IHashValue hv = function.ComputeHash(TestConstants.FooBar);
227-
Assert.NotNull(hv);
228-
Assert.NotEmpty(hv.Hash);
222+
IHashValue hv = function.ComputeHash("foobar");
223+
// Use the computed hash here...
229224
}
230225
```
231226

@@ -234,22 +229,20 @@ foreach (IHashFunctionBase function in functions)
234229
IHashFunctionBase[] functions = HashFactory.CreateHashAlgorithms(HashFunctionType.Cryptographic, new Dictionary<Type, IHashConfigBase>()
235230
{
236231

237-
// 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.
238-
{ typeof(IArgon2id), Argon2idConfig.OWASP_Standard }
232+
// 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.
233+
{ typeof(IArgon2id), new Argon2idConfigProfileOWASP() }
239234

240235
}, typeof(IBlake3)); // (Example) We do not want Blake3, 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).
241236
242-
Assert.NotNull(functions);
243-
Assert.NotEmpty(functions);
244-
Assert.All(functions, item => Assert.NotNull(item));
245-
246237
foreach (IHashFunctionBase function in functions)
247238
{
248-
IHashValue hv = function.ComputeHash(TestConstants.FooBar);
249-
Assert.NotNull(hv);
250-
Assert.NotEmpty(hv.Hash);
239+
IHashValue hv = function.ComputeHash("foobar");
251240

252-
(function as ICryptographicHashFunctionBase).Dispose();
241+
// This ensures that we only try disposing of cryptographic hashes.
242+
if (function is ICryptographicHashFunctionBase cryptoHash)
243+
{
244+
cryptoHash.Dispose();
245+
}
253246
}
254247
```
255248

@@ -290,3 +283,4 @@ License
290283

291284
HashifyNET is released under the terms of the MIT license. See [LICENSE](https://github.com/deskasoft/HashifyNET/blob/master/LICENSE) for more information or see http://opensource.org/licenses/MIT.
292285

286+

0 commit comments

Comments
 (0)