Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output formats are either inversed or labeled incorrectly. #19

Open
andrewtookay opened this issue Dec 14, 2021 · 0 comments
Open

Output formats are either inversed or labeled incorrectly. #19

andrewtookay opened this issue Dec 14, 2021 · 0 comments

Comments

@andrewtookay
Copy link

In index.js at the end of the digest function where the output format is computed we have the following code:

// output 32-bit array
if (outputFormat === 2) {
    return h.int32Buffer2Bytes(a);
}
// output 8-bit array
else if (outputFormat === 1) {
    return a;
}
// output string
return h.int32ArrayToHexString(a);

and in test.js we have these 2 tests:

    it('buffer outputFormat=1 -> 8 bit', function () {
        expect(x11.digest(buffer, 1, 1)).to.deep.equal([
            25431772,
            2140696654,
            1013368572,
            -1390505884,
            708325244,
            481603428,
            -318219067,
            201326592
        ]);
    });

    it('buffer outputFormat=2 -> 32 bit', function () {
        expect(x11.digest(buffer, 1, 2)).to.deep.equal([
            1,
            132,
            14,
            220,
            127,
            152,
            112,
            78,
            60,
            102,
            198,
            252,
            173,
            30,
            144,
            100,
            42,
            56,
            47,
            124,
            28,
            180,
            175,
            100,
            237,
            8,
            92,
            197,
            12,
            0,
            0,
            0
        ]);
    });

which implies that an inversion has happened. Currently the tests pass so it's hard to say what the intended order was. This function is called in dashcore-lib with the outputFormat parameter 1 and its result is then converted into an 8-bit buffer using Buffer.from() but that causes data loss if the input of the function is a 32-bit array so that points to a mistake in the implementation.

I did notice that these output types have been inverted in this commit history of this repo a few times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant