react-native-quick-crypto 0.6.0 → 0.7.0-rc.0
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/README.md +70 -18
- package/android/CMakeLists.txt +58 -61
- package/android/build.gradle +105 -53
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/gradle.properties +5 -5
- package/android/src/main/{AndroidManifest.xml → AndroidManifestNew.xml} +1 -2
- package/cpp/Cipher/MGLCipherHostObject.cpp +31 -5
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +21 -31
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +4 -17
- package/cpp/Cipher/MGLPublicCipher.h +1 -1
- package/cpp/Cipher/MGLPublicCipherInstaller.h +6 -6
- package/cpp/Cipher/MGLRsa.cpp +224 -11
- package/cpp/Cipher/MGLRsa.h +13 -3
- package/cpp/Hash/MGLHashHostObject.cpp +1 -1
- package/cpp/Hash/MGLHashInstaller.cpp +2 -4
- package/cpp/JSIUtils/MGLJSIMacros.h +10 -0
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +1 -1
- package/cpp/MGLKeys.cpp +415 -471
- package/cpp/MGLKeys.h +70 -2
- package/cpp/MGLQuickCryptoHostObject.cpp +9 -0
- package/cpp/Random/MGLRandomHostObject.cpp +9 -2
- package/cpp/Sig/MGLSignHostObjects.cpp +1 -1
- package/cpp/Utils/MGLUtils.cpp +104 -32
- package/cpp/Utils/MGLUtils.h +172 -143
- package/cpp/Utils/node.h +13 -0
- package/cpp/webcrypto/MGLWebCrypto.cpp +63 -0
- package/cpp/webcrypto/MGLWebCrypto.h +34 -0
- package/cpp/webcrypto/crypto_ec.cpp +334 -0
- package/cpp/webcrypto/crypto_ec.h +65 -0
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +4 -4
- package/lib/commonjs/@types/crypto-browserify.d.js.map +1 -1
- package/lib/commonjs/Cipher.js +53 -194
- package/lib/commonjs/Cipher.js.map +1 -1
- package/lib/commonjs/Hash.js +29 -29
- package/lib/commonjs/Hash.js.map +1 -1
- package/lib/commonjs/Hashnames.js +75 -0
- package/lib/commonjs/Hashnames.js.map +1 -0
- package/lib/commonjs/Hmac.js +6 -29
- package/lib/commonjs/Hmac.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +3 -5
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +11 -20
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/hash.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/hmac.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/random.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js +6 -0
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +1 -0
- package/lib/commonjs/QuickCrypto.js +5 -14
- package/lib/commonjs/QuickCrypto.js.map +1 -1
- package/lib/commonjs/Utils.js +360 -48
- package/lib/commonjs/Utils.js.map +1 -1
- package/lib/commonjs/aes.js +324 -0
- package/lib/commonjs/aes.js.map +1 -0
- package/lib/commonjs/constants.js +1 -2
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/ec.js +288 -0
- package/lib/commonjs/ec.js.map +1 -0
- package/lib/commonjs/index.js +6 -10
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys.js +280 -48
- package/lib/commonjs/keys.js.map +1 -1
- package/lib/commonjs/pbkdf2.js +44 -18
- package/lib/commonjs/pbkdf2.js.map +1 -1
- package/lib/commonjs/random.js +49 -68
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/rsa.js +329 -0
- package/lib/commonjs/rsa.js.map +1 -0
- package/lib/commonjs/sig.js +13 -54
- package/lib/commonjs/sig.js.map +1 -1
- package/lib/commonjs/subtle.js +271 -0
- package/lib/commonjs/subtle.js.map +1 -0
- package/lib/module/@types/crypto-browserify.d.js.map +1 -1
- package/lib/module/Cipher.js +53 -188
- package/lib/module/Cipher.js.map +1 -1
- package/lib/module/Hash.js +27 -21
- package/lib/module/Hash.js.map +1 -1
- package/lib/module/Hashnames.js +71 -0
- package/lib/module/Hashnames.js.map +1 -0
- package/lib/module/Hmac.js +4 -21
- package/lib/module/Hmac.js.map +1 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +3 -4
- package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +11 -17
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/module/NativeQuickCrypto/hash.js.map +1 -1
- package/lib/module/NativeQuickCrypto/hmac.js.map +1 -1
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +1 -1
- package/lib/module/NativeQuickCrypto/random.js.map +1 -1
- package/lib/module/NativeQuickCrypto/sig.js.map +1 -1
- package/lib/module/NativeQuickCrypto/webcrypto.js +2 -0
- package/lib/module/NativeQuickCrypto/webcrypto.js.map +1 -0
- package/lib/module/QuickCrypto.js +2 -0
- package/lib/module/QuickCrypto.js.map +1 -1
- package/lib/module/Utils.js +319 -33
- package/lib/module/Utils.js.map +1 -1
- package/lib/module/aes.js +317 -0
- package/lib/module/aes.js.map +1 -0
- package/lib/module/constants.js.map +1 -1
- package/lib/module/ec.js +282 -0
- package/lib/module/ec.js.map +1 -0
- package/lib/module/index.js +7 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys.js +279 -43
- package/lib/module/keys.js.map +1 -1
- package/lib/module/pbkdf2.js +44 -13
- package/lib/module/pbkdf2.js.map +1 -1
- package/lib/module/random.js +46 -54
- package/lib/module/random.js.map +1 -1
- package/lib/module/rsa.js +323 -0
- package/lib/module/rsa.js.map +1 -0
- package/lib/module/sig.js +13 -46
- package/lib/module/sig.js.map +1 -1
- package/lib/module/subtle.js +265 -0
- package/lib/module/subtle.js.map +1 -0
- package/lib/typescript/src/Cipher.d.ts +72 -0
- package/lib/typescript/src/Cipher.d.ts.map +1 -0
- package/lib/typescript/{Hash.d.ts → src/Hash.d.ts} +8 -7
- package/lib/typescript/src/Hash.d.ts.map +1 -0
- package/lib/typescript/src/Hashnames.d.ts +11 -0
- package/lib/typescript/src/Hashnames.d.ts.map +1 -0
- package/lib/typescript/{Hmac.d.ts → src/Hmac.d.ts} +3 -3
- package/lib/typescript/src/Hmac.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts +34 -0
- package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts.map +1 -0
- package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/NativeQuickCrypto.d.ts +3 -0
- package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/hash.d.ts +7 -0
- package/lib/typescript/src/NativeQuickCrypto/hash.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts +6 -0
- package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts.map +1 -0
- package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/pbkdf2.d.ts +2 -1
- package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/random.d.ts +2 -1
- package/lib/typescript/src/NativeQuickCrypto/random.d.ts.map +1 -0
- package/lib/typescript/{NativeQuickCrypto → src/NativeQuickCrypto}/sig.d.ts +5 -4
- package/lib/typescript/src/NativeQuickCrypto/sig.d.ts.map +1 -0
- package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts +27 -0
- package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts.map +1 -0
- package/lib/typescript/{QuickCrypto.d.ts → src/QuickCrypto.d.ts} +16 -8
- package/lib/typescript/src/QuickCrypto.d.ts.map +1 -0
- package/lib/typescript/src/Utils.d.ts +44 -0
- package/lib/typescript/src/Utils.d.ts.map +1 -0
- package/lib/typescript/src/aes.d.ts +5 -0
- package/lib/typescript/src/aes.d.ts.map +1 -0
- package/lib/typescript/{constants.d.ts → src/constants.d.ts} +1 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/ec.d.ts +5 -0
- package/lib/typescript/src/ec.d.ts.map +1 -0
- package/lib/typescript/{index.d.ts → src/index.d.ts} +33 -27
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/keys.d.ts +154 -0
- package/lib/typescript/src/keys.d.ts.map +1 -0
- package/lib/typescript/src/pbkdf2.d.ts +12 -0
- package/lib/typescript/src/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/{random.d.ts → src/random.d.ts} +7 -6
- package/lib/typescript/src/random.d.ts.map +1 -0
- package/lib/typescript/src/rsa.d.ts +4 -0
- package/lib/typescript/src/rsa.d.ts.map +1 -0
- package/lib/typescript/{sig.d.ts → src/sig.d.ts} +3 -3
- package/lib/typescript/src/sig.d.ts.map +1 -0
- package/lib/typescript/src/subtle.d.ts +11 -0
- package/lib/typescript/src/subtle.d.ts.map +1 -0
- package/package.json +35 -30
- package/react-native-quick-crypto.podspec +5 -4
- package/src/Cipher.ts +103 -100
- package/src/Hash.ts +42 -6
- package/src/Hashnames.ts +91 -0
- package/src/Hmac.ts +3 -3
- package/src/NativeQuickCrypto/Cipher.ts +1 -0
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +2 -0
- package/src/NativeQuickCrypto/webcrypto.ts +46 -0
- package/src/QuickCrypto.ts +2 -0
- package/src/Utils.ts +409 -5
- package/src/aes.ts +365 -0
- package/src/ec.ts +351 -0
- package/src/keys.ts +428 -54
- package/src/pbkdf2.ts +84 -11
- package/src/random.ts +37 -24
- package/src/rsa.ts +396 -0
- package/src/sig.ts +3 -2
- package/src/subtle.ts +358 -0
- package/lib/commonjs/@types/stream-browserify.d.js +0 -2
- package/lib/commonjs/@types/stream-browserify.d.js.map +0 -1
- package/lib/module/@types/stream-browserify.d.js +0 -2
- package/lib/module/@types/stream-browserify.d.js.map +0 -1
- package/lib/typescript/Cipher.d.ts +0 -87
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -32
- package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -6
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -5
- package/lib/typescript/Utils.d.ts +0 -23
- package/lib/typescript/keys.d.ts +0 -60
- package/lib/typescript/pbkdf2.d.ts +0 -9
- package/src/@types/stream-browserify.d.ts +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["NativeQuickCrypto/pbkdf2.ts"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["NativeQuickCrypto/random.ts"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["NativeQuickCrypto/sig.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["NativeQuickCrypto/webcrypto.ts"],"mappings":""}
|
|
@@ -4,26 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.QuickCrypto = void 0;
|
|
7
|
-
|
|
8
7
|
var pbkdf2 = _interopRequireWildcard(require("./pbkdf2"));
|
|
9
|
-
|
|
10
8
|
var random = _interopRequireWildcard(require("./random"));
|
|
11
|
-
|
|
12
9
|
var _Cipher = require("./Cipher");
|
|
13
|
-
|
|
14
10
|
var _sig = require("./sig");
|
|
15
|
-
|
|
16
11
|
var _Hmac = require("./Hmac");
|
|
17
|
-
|
|
18
12
|
var _Hash = require("./Hash");
|
|
19
|
-
|
|
20
13
|
var _constants = require("./constants");
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const QuickCrypto = {
|
|
14
|
+
var _subtle = require("./subtle");
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
const QuickCrypto = exports.QuickCrypto = {
|
|
27
18
|
createHmac: _Hmac.createHmac,
|
|
28
19
|
Hmac: _Hmac.createHmac,
|
|
29
20
|
Hash: _Hash.createHash,
|
|
@@ -39,9 +30,9 @@ const QuickCrypto = {
|
|
|
39
30
|
generateKeyPairSync: _Cipher.generateKeyPairSync,
|
|
40
31
|
createSign: _sig.createSign,
|
|
41
32
|
createVerify: _sig.createVerify,
|
|
33
|
+
subtle: _subtle.subtle,
|
|
42
34
|
constants: _constants.constants,
|
|
43
35
|
...pbkdf2,
|
|
44
36
|
...random
|
|
45
37
|
};
|
|
46
|
-
exports.QuickCrypto = QuickCrypto;
|
|
47
38
|
//# sourceMappingURL=QuickCrypto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["pbkdf2","_interopRequireWildcard","require","random","_Cipher","_sig","_Hmac","_Hash","_constants","_subtle","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","QuickCrypto","exports","createHmac","Hmac","Hash","createHash","createCipher","createCipheriv","createDecipher","createDecipheriv","publicEncrypt","publicDecrypt","privateDecrypt","generateKeyPair","generateKeyPairSync","createSign","createVerify","subtle","constants"],"sourceRoot":"../../src","sources":["QuickCrypto.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAWA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AAAkC,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAV,wBAAAU,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAE3B,MAAMY,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG;EACzBE,UAAU,EAAVA,gBAAU;EACVC,IAAI,EAAED,gBAAU;EAChBE,IAAI,EAAEC,gBAAU;EAChBA,UAAU,EAAVA,gBAAU;EACVC,YAAY,EAAZA,oBAAY;EACZC,cAAc,EAAdA,sBAAc;EACdC,cAAc,EAAdA,sBAAc;EACdC,gBAAgB,EAAhBA,wBAAgB;EAChBC,aAAa,EAAbA,qBAAa;EACbC,aAAa,EAAbA,qBAAa;EACbC,cAAc,EAAdA,sBAAc;EACdC,eAAe,EAAfA,uBAAe;EACfC,mBAAmB,EAAnBA,2BAAmB;EACnBC,UAAU,EAAVA,eAAU;EACVC,YAAY,EAAZA,iBAAY;EACZC,MAAM,EAANA,cAAM;EACNC,SAAS,EAATA,oBAAS;EACT,GAAGjD,MAAM;EACT,GAAGG;AACL,CAAC"}
|
package/lib/commonjs/Utils.js
CHANGED
|
@@ -3,33 +3,74 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
setDefaultEncoding: true,
|
|
8
|
+
getDefaultEncoding: true,
|
|
9
|
+
kEmptyObject: true,
|
|
10
|
+
toArrayBuffer: true,
|
|
11
|
+
bufferLikeToArrayBuffer: true,
|
|
12
|
+
binaryLikeToArrayBuffer: true,
|
|
13
|
+
ab2str: true,
|
|
14
|
+
validateString: true,
|
|
15
|
+
validateFunction: true,
|
|
16
|
+
isStringOrBuffer: true,
|
|
17
|
+
validateObject: true,
|
|
18
|
+
validateInt32: true,
|
|
19
|
+
validateUint32: true,
|
|
20
|
+
hasAnyNotIn: true,
|
|
21
|
+
lazyDOMException: true,
|
|
22
|
+
validateMaxBufferLength: true,
|
|
23
|
+
normalizeAlgorithm: true,
|
|
24
|
+
validateBitLength: true,
|
|
25
|
+
validateByteLength: true,
|
|
26
|
+
validateKeyOps: true
|
|
27
|
+
};
|
|
6
28
|
exports.ab2str = ab2str;
|
|
7
29
|
exports.binaryLikeToArrayBuffer = binaryLikeToArrayBuffer;
|
|
30
|
+
exports.bufferLikeToArrayBuffer = bufferLikeToArrayBuffer;
|
|
8
31
|
exports.getDefaultEncoding = getDefaultEncoding;
|
|
32
|
+
exports.hasAnyNotIn = hasAnyNotIn;
|
|
9
33
|
exports.isStringOrBuffer = isStringOrBuffer;
|
|
10
34
|
exports.kEmptyObject = void 0;
|
|
35
|
+
exports.lazyDOMException = lazyDOMException;
|
|
36
|
+
exports.normalizeAlgorithm = void 0;
|
|
11
37
|
exports.setDefaultEncoding = setDefaultEncoding;
|
|
12
38
|
exports.toArrayBuffer = toArrayBuffer;
|
|
39
|
+
exports.validateByteLength = exports.validateBitLength = void 0;
|
|
13
40
|
exports.validateFunction = validateFunction;
|
|
14
41
|
exports.validateInt32 = validateInt32;
|
|
42
|
+
exports.validateMaxBufferLength = exports.validateKeyOps = void 0;
|
|
15
43
|
exports.validateObject = validateObject;
|
|
16
44
|
exports.validateString = validateString;
|
|
17
45
|
exports.validateUint32 = validateUint32;
|
|
18
|
-
|
|
19
46
|
var _reactNativeBuffer = require("@craftzdog/react-native-buffer");
|
|
47
|
+
var _Hashnames = require("./Hashnames");
|
|
48
|
+
Object.keys(_Hashnames).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
51
|
+
if (key in exports && exports[key] === _Hashnames[key]) return;
|
|
52
|
+
Object.defineProperty(exports, key, {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return _Hashnames[key];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
// @types/node
|
|
60
|
+
|
|
61
|
+
// TODO(osp) should buffer be part of the Encoding type?
|
|
20
62
|
|
|
21
63
|
// Mimics node behavior for default global encoding
|
|
22
64
|
let defaultEncoding = 'buffer';
|
|
23
|
-
|
|
24
65
|
function setDefaultEncoding(encoding) {
|
|
25
66
|
defaultEncoding = encoding;
|
|
26
67
|
}
|
|
27
|
-
|
|
28
68
|
function getDefaultEncoding() {
|
|
29
69
|
return defaultEncoding;
|
|
30
70
|
}
|
|
71
|
+
const kEmptyObject = exports.kEmptyObject = Object.freeze(Object.create(null));
|
|
31
72
|
|
|
32
|
-
|
|
73
|
+
// Should be used by Cipher (or any other module that requires valid encodings)
|
|
33
74
|
// function slowCases(enc: string) {
|
|
34
75
|
// switch (enc.length) {
|
|
35
76
|
// case 4:
|
|
@@ -91,6 +132,7 @@ const kEmptyObject = Object.freeze(Object.create(null)); // Should be used by Ci
|
|
|
91
132
|
// if (enc === '') return 'utf8';
|
|
92
133
|
// }
|
|
93
134
|
// }
|
|
135
|
+
|
|
94
136
|
// // Return undefined if there is no match.
|
|
95
137
|
// // Move the "slow cases" to a separate function to make sure this function gets
|
|
96
138
|
// // inlined properly. That prioritizes the common case.
|
|
@@ -99,128 +141,398 @@ const kEmptyObject = Object.freeze(Object.create(null)); // Should be used by Ci
|
|
|
99
141
|
// return slowCases(enc);
|
|
100
142
|
// }
|
|
101
143
|
|
|
102
|
-
exports.kEmptyObject = kEmptyObject;
|
|
103
|
-
|
|
104
144
|
function toArrayBuffer(buf) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (buf !== null && buf !== void 0 && (_buf$buffer = buf.buffer) !== null && _buf$buffer !== void 0 && _buf$buffer.slice) {
|
|
145
|
+
if (buf?.buffer?.slice) {
|
|
108
146
|
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
109
147
|
}
|
|
110
|
-
|
|
111
148
|
const ab = new ArrayBuffer(buf.length);
|
|
112
149
|
const view = new Uint8Array(ab);
|
|
113
|
-
|
|
114
150
|
for (let i = 0; i < buf.length; ++i) {
|
|
115
151
|
view[i] = buf[i];
|
|
116
152
|
}
|
|
117
|
-
|
|
118
153
|
return ab;
|
|
119
154
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
155
|
+
function bufferLikeToArrayBuffer(buf) {
|
|
156
|
+
return _reactNativeBuffer.Buffer.isBuffer(buf) ? buf.buffer : ArrayBuffer.isView(buf) ? buf.buffer : buf;
|
|
157
|
+
}
|
|
158
|
+
function binaryLikeToArrayBuffer(input,
|
|
159
|
+
// CipherKey adds compat with node types
|
|
160
|
+
encoding = 'utf-8') {
|
|
124
161
|
if (typeof input === 'string') {
|
|
162
|
+
if (encoding === 'buffer') {
|
|
163
|
+
throw new Error('Cannot create a buffer from a string with a buffer encoding');
|
|
164
|
+
}
|
|
125
165
|
const buffer = _reactNativeBuffer.Buffer.from(input, encoding);
|
|
126
|
-
|
|
127
166
|
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
128
167
|
}
|
|
129
|
-
|
|
130
168
|
if (_reactNativeBuffer.Buffer.isBuffer(input)) {
|
|
131
169
|
return toArrayBuffer(input);
|
|
132
|
-
}
|
|
133
|
-
|
|
170
|
+
}
|
|
134
171
|
|
|
135
|
-
|
|
172
|
+
// TODO add further binary types to BinaryLike, UInt8Array and so for have this array as property
|
|
173
|
+
if (ArrayBuffer.isView(input)) {
|
|
136
174
|
return input.buffer;
|
|
137
175
|
}
|
|
138
|
-
|
|
139
176
|
if (!(input instanceof ArrayBuffer)) {
|
|
140
177
|
try {
|
|
178
|
+
// this is a strange fallback case and input is unknown at this point
|
|
179
|
+
// @ts-expect-error
|
|
141
180
|
const buffer = _reactNativeBuffer.Buffer.from(input);
|
|
142
|
-
|
|
143
181
|
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
144
182
|
} catch {
|
|
145
183
|
throw 'error';
|
|
146
184
|
}
|
|
147
185
|
}
|
|
148
186
|
|
|
187
|
+
// TODO: handle if input is KeyObject?
|
|
188
|
+
|
|
149
189
|
return input;
|
|
150
190
|
}
|
|
151
|
-
|
|
152
|
-
function ab2str(buf) {
|
|
153
|
-
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'hex';
|
|
191
|
+
function ab2str(buf, encoding = 'hex') {
|
|
154
192
|
return _reactNativeBuffer.Buffer.from(buf).toString(encoding);
|
|
155
193
|
}
|
|
156
|
-
|
|
157
194
|
function validateString(str, name) {
|
|
158
195
|
const isString = typeof str === 'string';
|
|
159
|
-
|
|
160
|
-
if (isString) {
|
|
196
|
+
if (!isString) {
|
|
161
197
|
throw new Error(`${name} is not a string`);
|
|
162
198
|
}
|
|
163
|
-
|
|
164
199
|
return isString;
|
|
165
200
|
}
|
|
166
|
-
|
|
167
201
|
function validateFunction(f) {
|
|
168
202
|
return f != null && typeof f === 'function';
|
|
169
203
|
}
|
|
170
|
-
|
|
171
204
|
function isStringOrBuffer(val) {
|
|
172
205
|
return typeof val === 'string' || ArrayBuffer.isView(val);
|
|
173
206
|
}
|
|
174
|
-
|
|
175
207
|
function validateObject(value, name, options) {
|
|
176
208
|
const useDefaultOptions = options == null;
|
|
177
209
|
const allowArray = useDefaultOptions ? false : options.allowArray;
|
|
178
210
|
const allowFunction = useDefaultOptions ? false : options.allowFunction;
|
|
179
211
|
const nullable = useDefaultOptions ? false : options.nullable;
|
|
180
|
-
|
|
181
212
|
if (!nullable && value === null || !allowArray && Array.isArray(value) || typeof value !== 'object' && (!allowFunction || typeof value !== 'function')) {
|
|
182
213
|
throw new Error(`${name} is not a valid object $${value}`);
|
|
183
214
|
}
|
|
184
|
-
|
|
185
215
|
return true;
|
|
186
216
|
}
|
|
187
|
-
|
|
188
|
-
function validateInt32(value, name) {
|
|
189
|
-
let min = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -2147483648;
|
|
190
|
-
let max = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2147483647;
|
|
191
|
-
|
|
217
|
+
function validateInt32(value, name, min = -2147483648, max = 2147483647) {
|
|
192
218
|
// The defaults for min and max correspond to the limits of 32-bit integers.
|
|
193
219
|
if (typeof value !== 'number') {
|
|
194
220
|
throw new Error(`Invalid argument - ${name} is not a number: ${value}`);
|
|
195
221
|
}
|
|
196
|
-
|
|
197
222
|
if (!Number.isInteger(value)) {
|
|
198
223
|
throw new Error(`Argument out of range - ${name} out of integer range: ${value}`);
|
|
199
224
|
}
|
|
200
|
-
|
|
201
225
|
if (value < min || value > max) {
|
|
202
226
|
throw new Error(`Invalid argument - ${name} out of range >= ${min} && <= ${max}: ${value}`);
|
|
203
227
|
}
|
|
204
228
|
}
|
|
205
|
-
|
|
206
229
|
function validateUint32(value, name, positive) {
|
|
207
230
|
if (typeof value !== 'number') {
|
|
208
231
|
// throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
|
|
209
232
|
throw new Error(`Invalid argument - ${name} is not a number: ${value}`);
|
|
210
233
|
}
|
|
211
|
-
|
|
212
234
|
if (!Number.isInteger(value)) {
|
|
213
235
|
// throw new ERR_OUT_OF_RANGE(name, 'an integer', value);
|
|
214
236
|
throw new Error(`Argument out of range - ${name} out of integer range: ${value}`);
|
|
215
237
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
238
|
+
const min = positive ? 1 : 0;
|
|
239
|
+
// 2 ** 32 === 4294967296
|
|
219
240
|
const max = 4294967295;
|
|
220
|
-
|
|
221
241
|
if (value < min || value > max) {
|
|
222
242
|
// throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
|
|
223
243
|
throw new Error(`Invalid argument - ${name} out of range >= ${min} && <= ${max}: ${value}`);
|
|
224
244
|
}
|
|
225
245
|
}
|
|
246
|
+
function hasAnyNotIn(set, checks) {
|
|
247
|
+
for (const s of set) {
|
|
248
|
+
if (!checks.includes(s)) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
function lazyDOMException(message, domName) {
|
|
255
|
+
let cause = '';
|
|
256
|
+
if (typeof domName !== 'string') {
|
|
257
|
+
cause = `\nCaused by: ${domName.cause}`;
|
|
258
|
+
}
|
|
259
|
+
return new Error(`[${domName}]: ${message}${cause}`);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// from lib/internal/crypto/util.js
|
|
263
|
+
|
|
264
|
+
// The maximum buffer size that we'll support in the WebCrypto impl
|
|
265
|
+
const kMaxBufferLength = 2 ** 31 - 1;
|
|
266
|
+
|
|
267
|
+
// // The EC named curves that we currently support via the Web Crypto API.
|
|
268
|
+
// const kNamedCurveAliases = {
|
|
269
|
+
// 'P-256': 'prime256v1',
|
|
270
|
+
// 'P-384': 'secp384r1',
|
|
271
|
+
// 'P-521': 'secp521r1',
|
|
272
|
+
// };
|
|
273
|
+
|
|
274
|
+
// const kAesKeyLengths = [128, 192, 256];
|
|
275
|
+
|
|
276
|
+
// // These are the only hash algorithms we currently support via
|
|
277
|
+
// // the Web Crypto API.
|
|
278
|
+
// const kHashTypes = ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'];
|
|
279
|
+
|
|
280
|
+
const kSupportedAlgorithms = {
|
|
281
|
+
'digest': {
|
|
282
|
+
'SHA-1': null,
|
|
283
|
+
'SHA-256': null,
|
|
284
|
+
'SHA-384': null,
|
|
285
|
+
'SHA-512': null
|
|
286
|
+
},
|
|
287
|
+
'generateKey': {
|
|
288
|
+
'RSASSA-PKCS1-v1_5': 'RsaHashedKeyGenParams',
|
|
289
|
+
'RSA-PSS': 'RsaHashedKeyGenParams',
|
|
290
|
+
'RSA-OAEP': 'RsaHashedKeyGenParams',
|
|
291
|
+
'ECDSA': 'EcKeyGenParams',
|
|
292
|
+
'ECDH': 'EcKeyGenParams',
|
|
293
|
+
'AES-CTR': 'AesKeyGenParams',
|
|
294
|
+
'AES-CBC': 'AesKeyGenParams',
|
|
295
|
+
'AES-GCM': 'AesKeyGenParams',
|
|
296
|
+
'AES-KW': 'AesKeyGenParams',
|
|
297
|
+
'HMAC': 'HmacKeyGenParams',
|
|
298
|
+
'X25519': null,
|
|
299
|
+
'Ed25519': null,
|
|
300
|
+
'X448': null,
|
|
301
|
+
'Ed448': null
|
|
302
|
+
},
|
|
303
|
+
'sign': {
|
|
304
|
+
'RSASSA-PKCS1-v1_5': null,
|
|
305
|
+
'RSA-PSS': 'RsaPssParams',
|
|
306
|
+
'ECDSA': 'EcdsaParams',
|
|
307
|
+
'HMAC': null,
|
|
308
|
+
'Ed25519': null,
|
|
309
|
+
'Ed448': 'Ed448Params'
|
|
310
|
+
},
|
|
311
|
+
'verify': {
|
|
312
|
+
'RSASSA-PKCS1-v1_5': null,
|
|
313
|
+
'RSA-PSS': 'RsaPssParams',
|
|
314
|
+
'ECDSA': 'EcdsaParams',
|
|
315
|
+
'HMAC': null,
|
|
316
|
+
'Ed25519': null,
|
|
317
|
+
'Ed448': 'Ed448Params'
|
|
318
|
+
},
|
|
319
|
+
'importKey': {
|
|
320
|
+
'RSASSA-PKCS1-v1_5': 'RsaHashedImportParams',
|
|
321
|
+
'RSA-PSS': 'RsaHashedImportParams',
|
|
322
|
+
'RSA-OAEP': 'RsaHashedImportParams',
|
|
323
|
+
'ECDSA': 'EcKeyImportParams',
|
|
324
|
+
'ECDH': 'EcKeyImportParams',
|
|
325
|
+
'HMAC': 'HmacImportParams',
|
|
326
|
+
'HKDF': null,
|
|
327
|
+
'PBKDF2': null,
|
|
328
|
+
'AES-CTR': null,
|
|
329
|
+
'AES-CBC': null,
|
|
330
|
+
'AES-GCM': null,
|
|
331
|
+
'AES-KW': null,
|
|
332
|
+
'Ed25519': null,
|
|
333
|
+
'X25519': null,
|
|
334
|
+
'Ed448': null,
|
|
335
|
+
'X448': null
|
|
336
|
+
},
|
|
337
|
+
'deriveBits': {
|
|
338
|
+
HKDF: 'HkdfParams',
|
|
339
|
+
PBKDF2: 'Pbkdf2Params',
|
|
340
|
+
ECDH: 'EcdhKeyDeriveParams',
|
|
341
|
+
X25519: 'EcdhKeyDeriveParams',
|
|
342
|
+
X448: 'EcdhKeyDeriveParams'
|
|
343
|
+
},
|
|
344
|
+
'encrypt': {
|
|
345
|
+
'RSA-OAEP': 'RsaOaepParams',
|
|
346
|
+
'AES-CBC': 'AesCbcParams',
|
|
347
|
+
'AES-GCM': 'AesGcmParams',
|
|
348
|
+
'AES-CTR': 'AesCtrParams'
|
|
349
|
+
},
|
|
350
|
+
'decrypt': {
|
|
351
|
+
'RSA-OAEP': 'RsaOaepParams',
|
|
352
|
+
'AES-CBC': 'AesCbcParams',
|
|
353
|
+
'AES-GCM': 'AesGcmParams',
|
|
354
|
+
'AES-CTR': 'AesCtrParams'
|
|
355
|
+
},
|
|
356
|
+
'get key length': {
|
|
357
|
+
'AES-CBC': 'AesDerivedKeyParams',
|
|
358
|
+
'AES-CTR': 'AesDerivedKeyParams',
|
|
359
|
+
'AES-GCM': 'AesDerivedKeyParams',
|
|
360
|
+
'AES-KW': 'AesDerivedKeyParams',
|
|
361
|
+
'HMAC': 'HmacImportParams',
|
|
362
|
+
'HKDF': null,
|
|
363
|
+
'PBKDF2': null
|
|
364
|
+
},
|
|
365
|
+
'wrapKey': {
|
|
366
|
+
'AES-KW': null
|
|
367
|
+
},
|
|
368
|
+
'unwrapKey': {
|
|
369
|
+
'AES-KW': null
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// const simpleAlgorithmDictionaries = {
|
|
374
|
+
// AesGcmParams: { iv: 'BufferSource', additionalData: 'BufferSource' },
|
|
375
|
+
// RsaHashedKeyGenParams: { hash: 'HashAlgorithmIdentifier' },
|
|
376
|
+
// EcKeyGenParams: {},
|
|
377
|
+
// HmacKeyGenParams: { hash: 'HashAlgorithmIdentifier' },
|
|
378
|
+
// RsaPssParams: {},
|
|
379
|
+
// EcdsaParams: { hash: 'HashAlgorithmIdentifier' },
|
|
380
|
+
// HmacImportParams: { hash: 'HashAlgorithmIdentifier' },
|
|
381
|
+
// HkdfParams: {
|
|
382
|
+
// hash: 'HashAlgorithmIdentifier',
|
|
383
|
+
// salt: 'BufferSource',
|
|
384
|
+
// info: 'BufferSource',
|
|
385
|
+
// },
|
|
386
|
+
// Ed448Params: { context: 'BufferSource' },
|
|
387
|
+
// Pbkdf2Params: { hash: 'HashAlgorithmIdentifier', salt: 'BufferSource' },
|
|
388
|
+
// RsaOaepParams: { label: 'BufferSource' },
|
|
389
|
+
// RsaHashedImportParams: { hash: 'HashAlgorithmIdentifier' },
|
|
390
|
+
// EcKeyImportParams: {},
|
|
391
|
+
// };
|
|
392
|
+
|
|
393
|
+
const validateMaxBufferLength = (data, name) => {
|
|
394
|
+
const length = typeof data === 'string' ? data.length : data.byteLength;
|
|
395
|
+
if (length > kMaxBufferLength) {
|
|
396
|
+
throw lazyDOMException(`${name} must be less than ${kMaxBufferLength + 1} bits`, 'OperationError');
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm
|
|
401
|
+
// adapted for Node.js from Deno's implementation
|
|
402
|
+
// https://github.com/denoland/deno/blob/v1.29.1/ext/crypto/00_crypto.js#L195
|
|
403
|
+
exports.validateMaxBufferLength = validateMaxBufferLength;
|
|
404
|
+
const normalizeAlgorithm = (algorithm, op) => {
|
|
405
|
+
if (typeof algorithm === 'string') return normalizeAlgorithm({
|
|
406
|
+
name: algorithm
|
|
407
|
+
}, op);
|
|
408
|
+
|
|
409
|
+
// 1.
|
|
410
|
+
const registeredAlgorithms = kSupportedAlgorithms[op];
|
|
411
|
+
// 2. 3.
|
|
412
|
+
// commented, because typescript takes care of this for us 🤞👀
|
|
413
|
+
// const initialAlg = webidl.converters.Algorithm(algorithm, {
|
|
414
|
+
// prefix: 'Failed to normalize algorithm',
|
|
415
|
+
// context: 'passed algorithm',
|
|
416
|
+
// });
|
|
417
|
+
|
|
418
|
+
// 4.
|
|
419
|
+
let algName = algorithm.name;
|
|
420
|
+
|
|
421
|
+
// 5.
|
|
422
|
+
let desiredType;
|
|
423
|
+
for (const key in registeredAlgorithms) {
|
|
424
|
+
if (!registeredAlgorithms.hasOwnProperty(key)) {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (key.toUpperCase() === algName.toUpperCase()) {
|
|
428
|
+
algName = key;
|
|
429
|
+
// @ts-ignore
|
|
430
|
+
desiredType = registeredAlgorithms[algName];
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (desiredType === undefined) throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
|
|
434
|
+
|
|
435
|
+
// Fast path everything below if the registered dictionary is null
|
|
436
|
+
if (desiredType === null) return {
|
|
437
|
+
name: algName
|
|
438
|
+
};
|
|
439
|
+
throw lazyDOMException(`normalizeAlgorithm() not implemented for ${op} / ${algName} / ${desiredType}`, 'NotSupportedError');
|
|
440
|
+
// TODO: implement these below when needed
|
|
441
|
+
|
|
442
|
+
// // 8.
|
|
443
|
+
// const normalizedAlgorithm = webidl.converters[desiredType](algorithm, {
|
|
444
|
+
// prefix: 'Failed to normalize algorithm',
|
|
445
|
+
// context: 'passed algorithm',
|
|
446
|
+
// });
|
|
447
|
+
// // 9.
|
|
448
|
+
// normalizedAlgorithm.name = algName;
|
|
449
|
+
|
|
450
|
+
// // 9.
|
|
451
|
+
// const dict = simpleAlgorithmDictionaries[desiredType];
|
|
452
|
+
// // 10.
|
|
453
|
+
// const dictKeys = dict ? Object.keys(dict) : [];
|
|
454
|
+
// for (let i = 0; i < dictKeys.length; i++) {
|
|
455
|
+
// const member = dictKeys[i];
|
|
456
|
+
// if (!dict.hasOwnProperty(member)) continue;
|
|
457
|
+
// const idlType = dict[member];
|
|
458
|
+
// const idlValue = normalizedAlgorithm[member];
|
|
459
|
+
// // 3.
|
|
460
|
+
// if (idlType === 'BufferSource' && idlValue) {
|
|
461
|
+
// const isView = ArrayBufferIsView(idlValue);
|
|
462
|
+
// normalizedAlgorithm[member] = TypedArrayPrototypeSlice(
|
|
463
|
+
// new Uint8Array(
|
|
464
|
+
// isView ? getDataViewOrTypedArrayBuffer(idlValue) : idlValue,
|
|
465
|
+
// isView ? getDataViewOrTypedArrayByteOffset(idlValue) : 0,
|
|
466
|
+
// isView
|
|
467
|
+
// ? getDataViewOrTypedArrayByteLength(idlValue)
|
|
468
|
+
// : ArrayBufferPrototypeGetByteLength(idlValue)
|
|
469
|
+
// )
|
|
470
|
+
// );
|
|
471
|
+
// } else if (idlType === 'HashAlgorithmIdentifier') {
|
|
472
|
+
// normalizedAlgorithm[member] = normalizeAlgorithm(idlValue, 'digest');
|
|
473
|
+
// } else if (idlType === 'AlgorithmIdentifier') {
|
|
474
|
+
// // This extension point is not used by any supported algorithm (yet?)
|
|
475
|
+
// throw lazyDOMException('Not implemented.', 'NotSupportedError');
|
|
476
|
+
// }
|
|
477
|
+
// }
|
|
478
|
+
|
|
479
|
+
// return normalizedAlgorithm;
|
|
480
|
+
};
|
|
481
|
+
exports.normalizeAlgorithm = normalizeAlgorithm;
|
|
482
|
+
const validateBitLength = (length, name, required = false) => {
|
|
483
|
+
if (length !== undefined || required) {
|
|
484
|
+
// validateNumber(length, name);
|
|
485
|
+
if (length < 0) throw new Error(`${name} > 0`);
|
|
486
|
+
if (length % 8) {
|
|
487
|
+
throw lazyDOMException(`${name}'s length (${length}) must be a multiple of 8`, 'InvalidArgument');
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
exports.validateBitLength = validateBitLength;
|
|
492
|
+
const validateByteLength = (buf, name, target) => {
|
|
493
|
+
if (buf.byteLength !== target) {
|
|
494
|
+
throw lazyDOMException(`${name} must contain exactly ${target} bytes`, 'OperationError');
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
exports.validateByteLength = validateByteLength;
|
|
498
|
+
const kKeyOps = {
|
|
499
|
+
sign: 1,
|
|
500
|
+
verify: 2,
|
|
501
|
+
encrypt: 3,
|
|
502
|
+
decrypt: 4,
|
|
503
|
+
wrapKey: 5,
|
|
504
|
+
unwrapKey: 6,
|
|
505
|
+
deriveKey: 7,
|
|
506
|
+
deriveBits: 8
|
|
507
|
+
};
|
|
508
|
+
const validateKeyOps = (keyOps, usagesSet) => {
|
|
509
|
+
if (keyOps === undefined) return;
|
|
510
|
+
if (!Array.isArray(keyOps)) {
|
|
511
|
+
throw lazyDOMException('keyData.key_ops', 'InvalidArgument');
|
|
512
|
+
}
|
|
513
|
+
let flags = 0;
|
|
514
|
+
for (let n = 0; n < keyOps.length; n++) {
|
|
515
|
+
const op = keyOps[n];
|
|
516
|
+
const op_flag = kKeyOps[op];
|
|
517
|
+
// Skipping unknown key ops
|
|
518
|
+
if (op_flag === undefined) continue;
|
|
519
|
+
// Have we seen it already? if so, error
|
|
520
|
+
// eslint-disable-next-line no-bitwise
|
|
521
|
+
if (flags & 1 << op_flag) throw lazyDOMException('Duplicate key operation', 'DataError');
|
|
522
|
+
// eslint-disable-next-line no-bitwise
|
|
523
|
+
flags |= 1 << op_flag;
|
|
524
|
+
|
|
525
|
+
// TODO(@jasnell): RFC7517 section 4.3 strong recommends validating
|
|
526
|
+
// key usage combinations. Specifically, it says that unrelated key
|
|
527
|
+
// ops SHOULD NOT be used together. We're not yet validating that here.
|
|
528
|
+
}
|
|
529
|
+
if (usagesSet !== undefined) {
|
|
530
|
+
for (const use of usagesSet) {
|
|
531
|
+
if (!keyOps.includes(use)) {
|
|
532
|
+
throw lazyDOMException('Key operations and usage mismatch', 'DataError');
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
exports.validateKeyOps = validateKeyOps;
|
|
226
538
|
//# sourceMappingURL=Utils.js.map
|