Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFilip Skokan <panva.ip@gmail.com>2021-05-10 13:33:11 +0300
committerFilip Skokan <panva.ip@gmail.com>2021-05-17 11:29:18 +0300
commit3ee1f9a29a6b18da79ac96c7e5e80f2933dfe2fb (patch)
tree71083800dae51ca21684b06bc3ecfffaa04356df /lib
parent2130598e91562efbfd594ba14f5f3eda2b2432d6 (diff)
util: add util.types.isKeyObject and util.types.isCryptoKey
closes #38611 PR-URL: https://github.com/nodejs/node/pull/38619 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/crypto/keys.js4
-rw-r--r--lib/internal/util/types.js37
2 files changed, 39 insertions, 2 deletions
diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js
index cc5b00a16ee..c24b2d14eb5 100644
--- a/lib/internal/crypto/keys.js
+++ b/lib/internal/crypto/keys.js
@@ -639,8 +639,8 @@ function createPrivateKey(key) {
return new PrivateKeyObject(handle);
}
-function isKeyObject(key) {
- return key instanceof KeyObject;
+function isKeyObject(obj) {
+ return obj != null && obj[kKeyType] !== undefined;
}
// Our implementation of CryptoKey is a simple wrapper around a KeyObject
diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js
index 6f5309a41c3..aca7dbc4b2f 100644
--- a/lib/internal/util/types.js
+++ b/lib/internal/util/types.js
@@ -2,6 +2,7 @@
const {
ArrayBufferIsView,
+ ObjectDefineProperties,
TypedArrayPrototypeGetSymbolToStringTag,
} = primordials;
@@ -69,3 +70,39 @@ module.exports = {
isBigInt64Array,
isBigUint64Array
};
+
+let isCryptoKey;
+let isKeyObject;
+
+ObjectDefineProperties(module.exports, {
+ isKeyObject: {
+ configurable: false,
+ enumerable: true,
+ value(obj) {
+ if (!process.versions.openssl) {
+ return false;
+ }
+
+ if (!isKeyObject) {
+ ({ isKeyObject } = require('internal/crypto/keys'));
+ }
+
+ return isKeyObject(obj);
+ }
+ },
+ isCryptoKey: {
+ configurable: false,
+ enumerable: true,
+ value(obj) {
+ if (!process.versions.openssl) {
+ return false;
+ }
+
+ if (!isCryptoKey) {
+ ({ isCryptoKey } = require('internal/crypto/keys'));
+ }
+
+ return isCryptoKey(obj);
+ }
+ }
+});