Inconsistent result between 0.17.2 and 0.18.0
mratsim opened this issue · comments
The library is inconsistent between 0.17.2 and 0.18.0 versions:
Test case:
import nimSHA2
var a: SHA256Digest
a[0] = 'a'
a[1] = 'b'
a[10] = 'c'
echo system.`$`(a)
echo nimsha2.`$`(a)
echo $a
echo a.len
O.17.2
ab
ab
ab
32
0.18.0
['a', 'b', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 'c', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00']
abc
abc
32
I suspect there are at least 2 reasons for this:
- 0.18.0 defines a
$
operator on arrays - I don't know why but seems like
$
in 0.17.2 was not iterating for the full length, stopping at the first 0 and this was fixed.
Recommandation: To avoid the $
issue it might be needed to wrap the digest array in an object like what is done in keccak_tiny
Any updates on this?