Skip to content

Inconsistent result between 0.17.2 and 0.18.0 #2

@mratsim

Description

@mratsim

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:

  1. 0.18.0 defines a $ operator on arrays
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions