sjudson / paseto.js

PASETO: Platform-Agnostic Security Tokens
MIT License
271 stars 16 forks source link

Use writeInt32LE instead of writeIntLE #7

Closed sloonz closed 5 years ago

sloonz commented 5 years ago

In Node 10, using writeIntLE without a length argument implies length = 1. Thus, signing a message longer than 127 bytes throws an error :

async function main() {
        const key = new Paseto.SymmetricKey.V2();
        const data = Buffer.alloc(256);
        await key.generate();
        console.log(await key.protocol().sign(data, key));
}

main().catch(console.log);
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -128 and <= 127. Received 256
    at writeU_Int8 (internal/buffer.js:559:11)
    at Buffer.writeIntLE (internal/buffer.js:676:12)
    at pieces.forEach (/opt/data/simon/tmp/paseto.js/lib/utils.js:162:9)
    at Array.forEach (<anonymous>)
    at Object.pae (/opt/data/simon/tmp/paseto.js/lib/utils.js:160:10)
    at sodium.ready.then (/opt/data/simon/tmp/paseto.js/lib/protocol/V2.js:246:30)

In Node 11, it is an error (issue #6)