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

[Fix] return valid values on multi-byte-wide TypedArray input #19

Open
wants to merge 4 commits into
base: v3.0
Choose a base branch
from

Conversation

ChALkeR
Copy link

@ChALkeR ChALkeR commented Nov 19, 2024

Port of browserify/cipher-base#23 to hash-base with minor code cleanup

This technically would have been a Feat, but Node.js handles it, and this module declares support for the same API as Node.js crypto in the readme

So, a Fix

.update input is converted to Buffer for all supported types and is passed to ._update as a buffer, so this doesn't require any changes in the libraries using hash-base to just work

Changes an error message but it's also like that in Node.js

@ChALkeR ChALkeR force-pushed the chalker/fixes/3.0.x/1 branch 7 times, most recently from 50d3575 to 8640bef Compare November 20, 2024 15:38
index.js Outdated Show resolved Hide resolved
* Makes sense only on engines with full TypedArray support -- let Buffer detect that
*/
if (useArrayBuffer && ArrayBuffer.isView(data)) {
if (data.byteLength === 0) return Buffer.alloc(0) // Bug in Node.js <6.3.1, which treats this as out-of-bounds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean it breaks in these versions?

Copy link
Author

@ChALkeR ChALkeR Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a fix for those versions
They are only problematic on zero-length arraybuffers, so a check helps

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
t.test('handle UInt16Array', function (t) {
beforeEach(t, createHashBase)

if (ArrayBuffer.isView && (Buffer.prototype instanceof Uint8Array || Buffer.TYPED_ARRAY_SUPPORT)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these checks can go in a { skip: } options arg to the test. Often i do { skip: condition && 'explanation' } and it displays nicely.

ChALkeR and others added 3 commits November 21, 2024 09:14
Co-authored-by: Jordan Harband <[email protected]>
Co-authored-by: Jordan Harband <[email protected]>
Co-authored-by: Jordan Harband <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants