jose 4.9.2 → 4.9.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.
- package/dist/browser/lib/check_key_type.js +7 -7
- package/dist/browser/lib/invalid_key_input.js +7 -2
- package/dist/browser/runtime/check_cek_length.js +3 -2
- package/dist/node/cjs/lib/check_key_type.js +6 -6
- package/dist/node/cjs/lib/invalid_key_input.js +9 -2
- package/dist/node/cjs/runtime/check_cek_length.js +6 -4
- package/dist/node/esm/lib/check_key_type.js +7 -7
- package/dist/node/esm/lib/invalid_key_input.js +7 -2
- package/dist/node/esm/runtime/check_cek_length.js +6 -4
- package/dist/types/types.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import invalidKeyInput from './invalid_key_input.js';
|
|
1
|
+
import { withAlg as invalidKeyInput } from './invalid_key_input.js';
|
|
2
2
|
import isKeyLike, { types } from '../runtime/is_key_like.js';
|
|
3
|
-
const symmetricTypeCheck = (key) => {
|
|
3
|
+
const symmetricTypeCheck = (alg, key) => {
|
|
4
4
|
if (key instanceof Uint8Array)
|
|
5
5
|
return;
|
|
6
6
|
if (!isKeyLike(key)) {
|
|
7
|
-
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
|
7
|
+
throw new TypeError(invalidKeyInput(alg, key, ...types, 'Uint8Array'));
|
|
8
8
|
}
|
|
9
9
|
if (key.type !== 'secret') {
|
|
10
10
|
throw new TypeError(`${types.join(' or ')} instances for symmetric algorithms must be of type "secret"`);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
const asymmetricTypeCheck = (key, usage) => {
|
|
13
|
+
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
14
14
|
if (!isKeyLike(key)) {
|
|
15
|
-
throw new TypeError(invalidKeyInput(key, ...types));
|
|
15
|
+
throw new TypeError(invalidKeyInput(alg, key, ...types));
|
|
16
16
|
}
|
|
17
17
|
if (key.type === 'secret') {
|
|
18
18
|
throw new TypeError(`${types.join(' or ')} instances for asymmetric algorithms must not be of type "secret"`);
|
|
@@ -36,10 +36,10 @@ const checkKeyType = (alg, key, usage) => {
|
|
|
36
36
|
alg.startsWith('PBES2') ||
|
|
37
37
|
/^A\d{3}(?:GCM)?KW$/.test(alg);
|
|
38
38
|
if (symmetric) {
|
|
39
|
-
symmetricTypeCheck(key);
|
|
39
|
+
symmetricTypeCheck(alg, key);
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
|
-
asymmetricTypeCheck(key, usage);
|
|
42
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
export default checkKeyType;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
let msg = 'Key must be ';
|
|
1
|
+
function message(msg, actual, ...types) {
|
|
3
2
|
if (types.length > 2) {
|
|
4
3
|
const last = types.pop();
|
|
5
4
|
msg += `one of type ${types.join(', ')}, or ${last}.`;
|
|
@@ -22,4 +21,10 @@ export default (actual, ...types) => {
|
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
return msg;
|
|
24
|
+
}
|
|
25
|
+
export default (actual, ...types) => {
|
|
26
|
+
return message('Key must be ', actual, ...types);
|
|
25
27
|
};
|
|
28
|
+
export function withAlg(alg, actual, ...types) {
|
|
29
|
+
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
30
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { JWEInvalid } from '../util/errors.js';
|
|
2
2
|
const checkCekLength = (cek, expected) => {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const actual = cek.byteLength << 3;
|
|
4
|
+
if (actual !== expected) {
|
|
5
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
5
6
|
}
|
|
6
7
|
};
|
|
7
8
|
export default checkCekLength;
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const invalid_key_input_js_1 = require("./invalid_key_input.js");
|
|
4
4
|
const is_key_like_js_1 = require("../runtime/is_key_like.js");
|
|
5
|
-
const symmetricTypeCheck = (key) => {
|
|
5
|
+
const symmetricTypeCheck = (alg, key) => {
|
|
6
6
|
if (key instanceof Uint8Array)
|
|
7
7
|
return;
|
|
8
8
|
if (!(0, is_key_like_js_1.default)(key)) {
|
|
9
|
-
throw new TypeError((0, invalid_key_input_js_1.
|
|
9
|
+
throw new TypeError((0, invalid_key_input_js_1.withAlg)(alg, key, ...is_key_like_js_1.types, 'Uint8Array'));
|
|
10
10
|
}
|
|
11
11
|
if (key.type !== 'secret') {
|
|
12
12
|
throw new TypeError(`${is_key_like_js_1.types.join(' or ')} instances for symmetric algorithms must be of type "secret"`);
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
const asymmetricTypeCheck = (key, usage) => {
|
|
15
|
+
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
16
16
|
if (!(0, is_key_like_js_1.default)(key)) {
|
|
17
|
-
throw new TypeError((0, invalid_key_input_js_1.
|
|
17
|
+
throw new TypeError((0, invalid_key_input_js_1.withAlg)(alg, key, ...is_key_like_js_1.types));
|
|
18
18
|
}
|
|
19
19
|
if (key.type === 'secret') {
|
|
20
20
|
throw new TypeError(`${is_key_like_js_1.types.join(' or ')} instances for asymmetric algorithms must not be of type "secret"`);
|
|
@@ -38,10 +38,10 @@ const checkKeyType = (alg, key, usage) => {
|
|
|
38
38
|
alg.startsWith('PBES2') ||
|
|
39
39
|
/^A\d{3}(?:GCM)?KW$/.test(alg);
|
|
40
40
|
if (symmetric) {
|
|
41
|
-
symmetricTypeCheck(key);
|
|
41
|
+
symmetricTypeCheck(alg, key);
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
asymmetricTypeCheck(key, usage);
|
|
44
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
exports.default = checkKeyType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.withAlg = void 0;
|
|
4
|
+
function message(msg, actual, ...types) {
|
|
5
5
|
if (types.length > 2) {
|
|
6
6
|
const last = types.pop();
|
|
7
7
|
msg += `one of type ${types.join(', ')}, or ${last}.`;
|
|
@@ -24,4 +24,11 @@ exports.default = (actual, ...types) => {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
return msg;
|
|
27
|
+
}
|
|
28
|
+
exports.default = (actual, ...types) => {
|
|
29
|
+
return message('Key must be ', actual, ...types);
|
|
27
30
|
};
|
|
31
|
+
function withAlg(alg, actual, ...types) {
|
|
32
|
+
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
33
|
+
}
|
|
34
|
+
exports.withAlg = withAlg;
|
|
@@ -19,14 +19,16 @@ const checkCekLength = (enc, cek) => {
|
|
|
19
19
|
throw new errors_js_1.JOSENotSupported(`Content Encryption Algorithm ${enc} is not supported either by JOSE or your javascript runtime`);
|
|
20
20
|
}
|
|
21
21
|
if (cek instanceof Uint8Array) {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const actual = cek.byteLength << 3;
|
|
23
|
+
if (actual !== expected) {
|
|
24
|
+
throw new errors_js_1.JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
24
25
|
}
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
28
|
if ((0, is_key_object_js_1.default)(cek) && cek.type === 'secret') {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const actual = cek.symmetricKeySize << 3;
|
|
30
|
+
if (actual !== expected) {
|
|
31
|
+
throw new errors_js_1.JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
30
32
|
}
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import invalidKeyInput from './invalid_key_input.js';
|
|
1
|
+
import { withAlg as invalidKeyInput } from './invalid_key_input.js';
|
|
2
2
|
import isKeyLike, { types } from '../runtime/is_key_like.js';
|
|
3
|
-
const symmetricTypeCheck = (key) => {
|
|
3
|
+
const symmetricTypeCheck = (alg, key) => {
|
|
4
4
|
if (key instanceof Uint8Array)
|
|
5
5
|
return;
|
|
6
6
|
if (!isKeyLike(key)) {
|
|
7
|
-
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
|
7
|
+
throw new TypeError(invalidKeyInput(alg, key, ...types, 'Uint8Array'));
|
|
8
8
|
}
|
|
9
9
|
if (key.type !== 'secret') {
|
|
10
10
|
throw new TypeError(`${types.join(' or ')} instances for symmetric algorithms must be of type "secret"`);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
const asymmetricTypeCheck = (key, usage) => {
|
|
13
|
+
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
14
14
|
if (!isKeyLike(key)) {
|
|
15
|
-
throw new TypeError(invalidKeyInput(key, ...types));
|
|
15
|
+
throw new TypeError(invalidKeyInput(alg, key, ...types));
|
|
16
16
|
}
|
|
17
17
|
if (key.type === 'secret') {
|
|
18
18
|
throw new TypeError(`${types.join(' or ')} instances for asymmetric algorithms must not be of type "secret"`);
|
|
@@ -36,10 +36,10 @@ const checkKeyType = (alg, key, usage) => {
|
|
|
36
36
|
alg.startsWith('PBES2') ||
|
|
37
37
|
/^A\d{3}(?:GCM)?KW$/.test(alg);
|
|
38
38
|
if (symmetric) {
|
|
39
|
-
symmetricTypeCheck(key);
|
|
39
|
+
symmetricTypeCheck(alg, key);
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
|
-
asymmetricTypeCheck(key, usage);
|
|
42
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
export default checkKeyType;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
let msg = 'Key must be ';
|
|
1
|
+
function message(msg, actual, ...types) {
|
|
3
2
|
if (types.length > 2) {
|
|
4
3
|
const last = types.pop();
|
|
5
4
|
msg += `one of type ${types.join(', ')}, or ${last}.`;
|
|
@@ -22,4 +21,10 @@ export default (actual, ...types) => {
|
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
return msg;
|
|
24
|
+
}
|
|
25
|
+
export default (actual, ...types) => {
|
|
26
|
+
return message('Key must be ', actual, ...types);
|
|
25
27
|
};
|
|
28
|
+
export function withAlg(alg, actual, ...types) {
|
|
29
|
+
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
30
|
+
}
|
|
@@ -17,14 +17,16 @@ const checkCekLength = (enc, cek) => {
|
|
|
17
17
|
throw new JOSENotSupported(`Content Encryption Algorithm ${enc} is not supported either by JOSE or your javascript runtime`);
|
|
18
18
|
}
|
|
19
19
|
if (cek instanceof Uint8Array) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const actual = cek.byteLength << 3;
|
|
21
|
+
if (actual !== expected) {
|
|
22
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
22
23
|
}
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
26
|
if (isKeyObject(cek) && cek.type === 'secret') {
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const actual = cek.symmetricKeySize << 3;
|
|
28
|
+
if (actual !== expected) {
|
|
29
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
28
30
|
}
|
|
29
31
|
return;
|
|
30
32
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
* obtain a KeyObject from your existing key material.
|
|
21
21
|
*
|
|
22
22
|
* [CryptoKey](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) is a representation of a
|
|
23
|
-
* key/secret available in the Browser and
|
|
24
|
-
* this library you may use the
|
|
23
|
+
* key/secret available in the Browser and Web-interoperable runtimes. In addition to the import
|
|
24
|
+
* functions of this library you may use the
|
|
25
25
|
* [SubtleCrypto.importKey](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey)
|
|
26
26
|
* API to obtain a CryptoKey from your existing key material.
|
|
27
27
|
*
|