hono 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,28 +18,12 @@ const auth = (req) => {
|
|
|
18
18
|
if (!match) {
|
|
19
19
|
return undefined;
|
|
20
20
|
}
|
|
21
|
-
const userPass = USER_PASS_REGEXP.exec(decodeBase64(match[1]));
|
|
21
|
+
const userPass = USER_PASS_REGEXP.exec((0, buffer_1.decodeBase64)(match[1]));
|
|
22
22
|
if (!userPass) {
|
|
23
23
|
return undefined;
|
|
24
24
|
}
|
|
25
25
|
return { username: userPass[1], password: userPass[2] };
|
|
26
26
|
};
|
|
27
|
-
function decodeBase64(str) {
|
|
28
|
-
if (atob) {
|
|
29
|
-
const text = atob(str);
|
|
30
|
-
const length = text.length;
|
|
31
|
-
const bytes = new Uint8Array(length);
|
|
32
|
-
for (let i = 0; i < length; i++) {
|
|
33
|
-
bytes[i] = text.charCodeAt(i);
|
|
34
|
-
}
|
|
35
|
-
const decoder = new TextDecoder();
|
|
36
|
-
return decoder.decode(bytes);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const { Buffer } = require('buffer');
|
|
40
|
-
return Buffer.from(str, 'base64').toString();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
27
|
const basicAuth = (options) => {
|
|
44
28
|
if (!options.realm) {
|
|
45
29
|
options.realm = 'Secure Area';
|
package/dist/utils/buffer.d.ts
CHANGED
package/dist/utils/buffer.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timingSafeEqual = exports.equal = void 0;
|
|
22
|
+
exports.timingSafeEqual = exports.sha256 = exports.decodeBase64 = exports.equal = void 0;
|
|
4
23
|
const equal = (a, b) => {
|
|
5
24
|
if (a === b) {
|
|
6
25
|
return true;
|
|
@@ -19,13 +38,50 @@ const equal = (a, b) => {
|
|
|
19
38
|
return true;
|
|
20
39
|
};
|
|
21
40
|
exports.equal = equal;
|
|
41
|
+
const decodeBase64 = (str) => {
|
|
42
|
+
try {
|
|
43
|
+
const text = atob(str);
|
|
44
|
+
const length = text.length;
|
|
45
|
+
const bytes = new Uint8Array(length);
|
|
46
|
+
for (let i = 0; i < length; i++) {
|
|
47
|
+
bytes[i] = text.charCodeAt(i);
|
|
48
|
+
}
|
|
49
|
+
const decoder = new TextDecoder();
|
|
50
|
+
return decoder.decode(bytes);
|
|
51
|
+
}
|
|
52
|
+
catch (_a) { }
|
|
53
|
+
try {
|
|
54
|
+
const { Buffer } = require('buffer');
|
|
55
|
+
return Buffer.from(str, 'base64').toString();
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error('If you want to do "decodeBase64", polyfill "buffer" module.');
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.decodeBase64 = decodeBase64;
|
|
63
|
+
const sha256 = async (a) => {
|
|
64
|
+
if (crypto && crypto.subtle) {
|
|
65
|
+
const buffer = await crypto.subtle.digest({
|
|
66
|
+
name: 'SHA-256',
|
|
67
|
+
}, new TextEncoder().encode(String(a)));
|
|
68
|
+
const hash = Array.prototype.map.call(new Uint8Array(buffer), (x) => ('00' + x.toString(16)).slice(-2)).join('');
|
|
69
|
+
return hash;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const crypto = await Promise.resolve().then(() => __importStar(require('crypto')));
|
|
73
|
+
const hash = crypto.createHash('sha256').update(a).digest('hex');
|
|
74
|
+
return hash;
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
console.error('If you want to do "sha256", polyfill "crypto" module.');
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.sha256 = sha256;
|
|
22
82
|
const timingSafeEqual = async (a, b) => {
|
|
23
|
-
const sa = await
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const sb = await crypto.subtle.digest({
|
|
27
|
-
name: 'SHA-256',
|
|
28
|
-
}, new TextEncoder().encode(String(b)));
|
|
29
|
-
return (0, exports.equal)(sa, sb) && a === b;
|
|
83
|
+
const sa = await (0, exports.sha256)(a);
|
|
84
|
+
const sb = await (0, exports.sha256)(b);
|
|
85
|
+
return sa === sb && a === b;
|
|
30
86
|
};
|
|
31
87
|
exports.timingSafeEqual = timingSafeEqual;
|