-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
crypto.subtle.digest()
for "sha-1" and "sha-256"
- Loading branch information
1 parent
95d9a3f
commit 8510c75
Showing
6 changed files
with
490 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'nxjs-runtime': patch | ||
--- | ||
|
||
Implement `crypto.subtle.digest()` for "sha-1" and "sha-256" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { suite } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
|
||
const test = suite('crypto'); | ||
|
||
function toHex(a: ArrayBuffer) { | ||
const u = new Uint8Array(a); | ||
const s = []; | ||
for (let i = 0; i < u.length; i++) { | ||
s.push(u[i].toString(16).padStart(2, '0')); | ||
} | ||
return s.join(''); | ||
} | ||
|
||
test('`crypto.getRandomValues()`', () => { | ||
const arr = new Uint8Array(5); | ||
assert.equal(toHex(arr.buffer), '0000000000'); | ||
crypto.getRandomValues(arr); | ||
assert.not.equal(toHex(arr.buffer), '0000000000'); | ||
}); | ||
|
||
test("`crypto.subtle.digest('sha-1')`", async () => { | ||
const data = new TextEncoder().encode('hello'); | ||
const digest = await crypto.subtle.digest('sha-1', data); | ||
assert.equal(toHex(digest), 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'); | ||
}); | ||
|
||
test("`crypto.subtle.digest('sha-256')`", async () => { | ||
const data = new TextEncoder().encode('hello'); | ||
const digest = await crypto.subtle.digest('sha-256', data); | ||
assert.equal( | ||
toHex(digest), | ||
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824' | ||
); | ||
}); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import './canvas'; | ||
import './crypto'; | ||
import './error'; | ||
import './fetch'; | ||
import './form-data'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.