### Fixed

- Incorrect hash for `DataView` input, and for `Int8Array` with negative values in browsers.
- Throws `ArrayBuffer is not defined` in browsers without `ArrayBuffer`.

### Changed
- Multi-byte typed arrays such as `Uint16Array`, `Uint32Array` and `Float32Array` are now hashed by their underlying bytes, the same as Node.js `crypto` and Web Crypto. Previously each element was treated as one byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yi-Cyuan Chen
2026-11-18 13:31:57 +08:00
co-authored by Claude Opus 5.5
parent 9e1e7d1397
commit 4ad1b7a3b2
13 changed files with 65 additions and 26 deletions
+12 -2
View File
@@ -92,8 +92,12 @@ describe('environment detection', function () {
var path = require('path');
var source = fs.readFileSync(path.join(__dirname, '../src/sha1.js'), 'utf8');
function run(sandbox) {
vm.runInContext(source, vm.createContext(sandbox));
function run(sandbox, script) {
var context = vm.createContext(sandbox);
if (script) {
vm.runInContext(script, context);
}
vm.runInContext(source, context);
return sandbox.sha1;
}
@@ -120,6 +124,12 @@ describe('environment detection', function () {
sandbox.self = sandbox;
check(run(sandbox));
});
it('should load in a browser without ArrayBuffer', function () {
var sandbox = {};
sandbox.window = sandbox;
check(run(sandbox, 'delete ArrayBuffer; delete Uint8Array; delete DataView;'));
});
});
// webworker