summaryrefslogtreecommitdiff
path: root/lib/internal/crypto
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2019-11-22 18:04:46 +0100
committerMichaël Zasso <targos@protonmail.com>2019-11-25 10:28:15 +0100
commit0646eda4fc0affb98e13c30acb522e63b7fd6dde (patch)
tree078209f50b044e24ea2c72cbbe7dca6e34bb7e25 /lib/internal/crypto
parent35c6e0cc2b56a5380e6808ef5603ecc2b167e032 (diff)
downloadandroid-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.gz
android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.bz2
android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.zip
lib: flatten access to primordials
Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/internal/crypto')
-rw-r--r--lib/internal/crypto/cipher.js20
-rw-r--r--lib/internal/crypto/diffiehellman.js8
-rw-r--r--lib/internal/crypto/hash.js12
-rw-r--r--lib/internal/crypto/keygen.js6
-rw-r--r--lib/internal/crypto/keys.js6
-rw-r--r--lib/internal/crypto/random.js8
-rw-r--r--lib/internal/crypto/sig.js12
7 files changed, 43 insertions, 29 deletions
diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js
index 133b1e5153..add56eae68 100644
--- a/lib/internal/crypto/cipher.js
+++ b/lib/internal/crypto/cipher.js
@@ -1,6 +1,8 @@
'use strict';
-const { Object } = primordials;
+const {
+ ObjectSetPrototypeOf,
+} = primordials;
const {
RSA_PKCS1_OAEP_PADDING,
@@ -126,8 +128,8 @@ function Cipher(cipher, password, options) {
createCipher.call(this, cipher, password, options, true);
}
-Object.setPrototypeOf(Cipher.prototype, LazyTransform.prototype);
-Object.setPrototypeOf(Cipher, LazyTransform);
+ObjectSetPrototypeOf(Cipher.prototype, LazyTransform.prototype);
+ObjectSetPrototypeOf(Cipher, LazyTransform);
Cipher.prototype._transform = function _transform(chunk, encoding, callback) {
this.push(this[kHandle].update(chunk, encoding));
@@ -239,8 +241,8 @@ function addCipherPrototypeFunctions(constructor) {
constructor.prototype.setAAD = Cipher.prototype.setAAD;
}
-Object.setPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
-Object.setPrototypeOf(Cipheriv, LazyTransform);
+ObjectSetPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
+ObjectSetPrototypeOf(Cipheriv, LazyTransform);
addCipherPrototypeFunctions(Cipheriv);
function Decipher(cipher, password, options) {
@@ -250,8 +252,8 @@ function Decipher(cipher, password, options) {
createCipher.call(this, cipher, password, options, false);
}
-Object.setPrototypeOf(Decipher.prototype, LazyTransform.prototype);
-Object.setPrototypeOf(Decipher, LazyTransform);
+ObjectSetPrototypeOf(Decipher.prototype, LazyTransform.prototype);
+ObjectSetPrototypeOf(Decipher, LazyTransform);
addCipherPrototypeFunctions(Decipher);
@@ -262,8 +264,8 @@ function Decipheriv(cipher, key, iv, options) {
createCipherWithIV.call(this, cipher, key, options, false, iv);
}
-Object.setPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
-Object.setPrototypeOf(Decipheriv, LazyTransform);
+ObjectSetPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
+ObjectSetPrototypeOf(Decipheriv, LazyTransform);
addCipherPrototypeFunctions(Decipheriv);
module.exports = {
diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js
index 7e0fde38bc..da8f87bf16 100644
--- a/lib/internal/crypto/diffiehellman.js
+++ b/lib/internal/crypto/diffiehellman.js
@@ -1,6 +1,8 @@
'use strict';
-const { Object } = primordials;
+const {
+ ObjectDefineProperty,
+} = primordials;
const { Buffer } = require('buffer');
const {
@@ -63,7 +65,7 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
generator = toBuf(generator, genEncoding);
this[kHandle] = new _DiffieHellman(sizeOrKey, generator);
- Object.defineProperty(this, 'verifyError', {
+ ObjectDefineProperty(this, 'verifyError', {
enumerable: true,
value: this[kHandle].verifyError,
writable: false
@@ -75,7 +77,7 @@ function DiffieHellmanGroup(name) {
if (!(this instanceof DiffieHellmanGroup))
return new DiffieHellmanGroup(name);
this[kHandle] = new _DiffieHellmanGroup(name);
- Object.defineProperty(this, 'verifyError', {
+ ObjectDefineProperty(this, 'verifyError', {
enumerable: true,
value: this[kHandle].verifyError,
writable: false
diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js
index b28f9fca13..56784275f9 100644
--- a/lib/internal/crypto/hash.js
+++ b/lib/internal/crypto/hash.js
@@ -1,6 +1,8 @@
'use strict';
-const { Object } = primordials;
+const {
+ ObjectSetPrototypeOf,
+} = primordials;
const {
Hash: _Hash,
@@ -47,8 +49,8 @@ function Hash(algorithm, options) {
LazyTransform.call(this, options);
}
-Object.setPrototypeOf(Hash.prototype, LazyTransform.prototype);
-Object.setPrototypeOf(Hash, LazyTransform);
+ObjectSetPrototypeOf(Hash.prototype, LazyTransform.prototype);
+ObjectSetPrototypeOf(Hash, LazyTransform);
Hash.prototype.copy = function copy(options) {
const state = this[kState];
@@ -118,8 +120,8 @@ function Hmac(hmac, key, options) {
LazyTransform.call(this, options);
}
-Object.setPrototypeOf(Hmac.prototype, LazyTransform.prototype);
-Object.setPrototypeOf(Hmac, LazyTransform);
+ObjectSetPrototypeOf(Hmac.prototype, LazyTransform.prototype);
+ObjectSetPrototypeOf(Hmac, LazyTransform);
Hmac.prototype.update = Hash.prototype.update;
diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js
index 0a4bde77fa..88d2822fa6 100644
--- a/lib/internal/crypto/keygen.js
+++ b/lib/internal/crypto/keygen.js
@@ -1,6 +1,8 @@
'use strict';
-const { Object } = primordials;
+const {
+ ObjectDefineProperty,
+} = primordials;
const { AsyncWrap, Providers } = internalBinding('async_wrap');
const {
@@ -63,7 +65,7 @@ function generateKeyPair(type, options, callback) {
handleError(impl(wrap));
}
-Object.defineProperty(generateKeyPair, customPromisifyArgs, {
+ObjectDefineProperty(generateKeyPair, customPromisifyArgs, {
value: ['publicKey', 'privateKey'],
enumerable: false
});
diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js
index 250147d752..25ef888495 100644
--- a/lib/internal/crypto/keys.js
+++ b/lib/internal/crypto/keys.js
@@ -1,6 +1,8 @@
'use strict';
-const { Object } = primordials;
+const {
+ ObjectDefineProperty,
+} = primordials;
const {
KeyObject: KeyObjectHandle,
@@ -48,7 +50,7 @@ class KeyObject {
this[kKeyType] = type;
- Object.defineProperty(this, kHandle, {
+ ObjectDefineProperty(this, kHandle, {
value: handle,
enumerable: false,
configurable: false,
diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js
index f42458aa78..425b65e268 100644
--- a/lib/internal/crypto/random.js
+++ b/lib/internal/crypto/random.js
@@ -1,6 +1,8 @@
'use strict';
-const { Math } = primordials;
+const {
+ MathMin,
+} = primordials;
const { AsyncWrap, Providers } = internalBinding('async_wrap');
const { Buffer, kMaxLength } = require('buffer');
@@ -14,13 +16,13 @@ const { validateNumber } = require('internal/validators');
const { isArrayBufferView } = require('internal/util/types');
const kMaxUint32 = 2 ** 32 - 1;
-const kMaxPossibleLength = Math.min(kMaxLength, kMaxUint32);
+const kMaxPossibleLength = MathMin(kMaxLength, kMaxUint32);
function assertOffset(offset, elementSize, length) {
validateNumber(offset, 'offset');
offset *= elementSize;
- const maxLength = Math.min(length, kMaxPossibleLength);
+ const maxLength = MathMin(length, kMaxPossibleLength);
if (Number.isNaN(offset) || offset > maxLength || offset < 0) {
throw new ERR_OUT_OF_RANGE('offset', `>= 0 && <= ${maxLength}`, offset);
}
diff --git a/lib/internal/crypto/sig.js b/lib/internal/crypto/sig.js
index 6eda845564..27930ce1ac 100644
--- a/lib/internal/crypto/sig.js
+++ b/lib/internal/crypto/sig.js
@@ -1,6 +1,8 @@
'use strict';
-const { Object } = primordials;
+const {
+ ObjectSetPrototypeOf,
+} = primordials;
const {
ERR_CRYPTO_SIGN_KEY_REQUIRED,
@@ -38,8 +40,8 @@ function Sign(algorithm, options) {
Writable.call(this, options);
}
-Object.setPrototypeOf(Sign.prototype, Writable.prototype);
-Object.setPrototypeOf(Sign, Writable);
+ObjectSetPrototypeOf(Sign.prototype, Writable.prototype);
+ObjectSetPrototypeOf(Sign, Writable);
Sign.prototype._write = function _write(chunk, encoding, callback) {
this.update(chunk, encoding);
@@ -153,8 +155,8 @@ function Verify(algorithm, options) {
Writable.call(this, options);
}
-Object.setPrototypeOf(Verify.prototype, Writable.prototype);
-Object.setPrototypeOf(Verify, Writable);
+ObjectSetPrototypeOf(Verify.prototype, Writable.prototype);
+ObjectSetPrototypeOf(Verify, Writable);
Verify.prototype._write = Sign.prototype._write;
Verify.prototype.update = Sign.prototype.update;