Skip to content

Commit 3232eab

Browse files
committed
[nscl] Replaced lib/sha256.js with web platform native implementation (thanks Martin for suggested patch).
1 parent d85cc60 commit 3232eab

File tree

4 files changed

+31
-521
lines changed

4 files changed

+31
-521
lines changed

boot.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ try {
2626
let includeFrom = (dir, srcs) => include(srcs.map(name => `${BASE}/${dir}/${name}.js`));
2727

2828
includeFrom("lib", [
29-
"browser-polyfill", "punycode", "sha256"
29+
"browser-polyfill", "punycode",
3030
]);
3131

3232
includeFrom("common", [
@@ -35,6 +35,7 @@ try {
3535
"CSP", "CapsCSP", "NetCSP",
3636
"RequestKey", "Sites", "Permissions", "Policy",
3737
"Storage",
38+
"sha256",
3839
]);
3940

4041
includeFrom("service", [

common/sha256.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* NoScript Commons Library
3+
* Reusable building blocks for cross-browser security/privacy WebExtensions.
4+
* Copyright (C) 2020-2023 Giorgio Maone <https://maone.net>
5+
*
6+
* SPDX-License-Identifier: GPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License as published by the Free Software
10+
* Foundation, either version 3 of the License, or (at your option) any later
11+
* version.
12+
*
13+
* This program is distributed in the hope that it will be useful, but WITHOUT
14+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License along with
18+
* this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
async function sha256(s) {
22+
const bytes = new TextEncoder().encode(s);
23+
const hashBytes = await crypto.subtle.digest("SHA-256", bytes);
24+
return new Uint8Array(hashBytes).reduce(
25+
(s, b) => s + b.toString(16).padStart(2, "0"), ""
26+
);
27+
}

0 commit comments

Comments
 (0)