ektrah/libsodium-core

GenericHash example from the docs not working (ambiguous call)

Closed this issue · 1 comments

If I try the GenericHash without a key example from the docs, it won't compile.

GenericHash without a key

var message = "Arbitrary data to hash";

//returns a 32 byte hash
var generichash = GenericHash.Hash(message, null, 32);

https://bitbeans.gitbooks.io/libsodium-net/content/hashing/generic_hashing.html

I know this lib is ported from the libsodium-net, and I guess its the same issue there.

The issue is the docs are clearly stating the second parameter can be null (for the string and the byte[] overload: /// <param name="key">The key; may be null, otherwise between 16 and 64 bytes.</param>)

But how should those be differentiated then?
public static byte[] Hash(string message, string key, int bytes)
public static byte[] Hash(string message, byte[] key, int bytes)

You can cast null to one of the parameters types to disambiguate the call:

var generichash = GenericHash.Hash(message, (byte[])null, 32);