[njs] Fixed "constructor" property of "Hash" and "Hmac" objects.
Dmitry Volyntsev
xeioex at nginx.com
Thu Oct 31 15:18:04 UTC 2019
details: https://hg.nginx.org/njs/rev/297f7dd356c0
branches:
changeset: 1215:297f7dd356c0
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Oct 31 18:17:34 2019 +0300
description:
Fixed "constructor" property of "Hash" and "Hmac" objects.
diffstat:
src/njs_crypto.c | 16 ++++++++++++++++
src/test/njs_unit_test.c | 18 ++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)
diffs (68 lines):
diff -r 5abe92b2cfd0 -r 297f7dd356c0 src/njs_crypto.c
--- a/src/njs_crypto.c Thu Oct 31 18:17:33 2019 +0300
+++ b/src/njs_crypto.c Thu Oct 31 18:17:34 2019 +0300
@@ -343,6 +343,14 @@ static const njs_object_prop_t njs_hash
.writable = 1,
.configurable = 1,
},
+
+ {
+ .type = NJS_PROPERTY_HANDLER,
+ .name = njs_string("constructor"),
+ .value = njs_prop_handler(njs_object_prototype_create_constructor),
+ .writable = 1,
+ .configurable = 1,
+ },
};
@@ -634,6 +642,14 @@ static const njs_object_prop_t njs_hmac
.writable = 1,
.configurable = 1,
},
+
+ {
+ .type = NJS_PROPERTY_HANDLER,
+ .name = njs_string("constructor"),
+ .value = njs_prop_handler(njs_object_prototype_create_constructor),
+ .writable = 1,
+ .configurable = 1,
+ },
};
diff -r 5abe92b2cfd0 -r 297f7dd356c0 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Oct 31 18:17:33 2019 +0300
+++ b/src/test/njs_unit_test.c Thu Oct 31 18:17:34 2019 +0300
@@ -14191,6 +14191,15 @@ static njs_unit_test_t njs_test[] =
{ njs_str("Object.prototype.toString.call(require('crypto').createHash('sha1'))"),
njs_str("[object Object]") },
+ { njs_str("var h = require('crypto').createHash('sha1');"
+ "var Hash = h.constructor; "
+ "Hash('sha1').update('AB').digest('hex')"),
+ njs_str("06d945942aa26a61be18c3e22bf19bbca8dd2b5d") },
+
+ { njs_str("var h = require('crypto').createHash('sha1');"
+ "h.constructor.name"),
+ njs_str("Hash") },
+
{ njs_str("var h = require('crypto').createHash('md5');"
"h.update('AB').digest('hex')"),
njs_str("b86fc6b051f63d73de262d4c34e3a0a9") },
@@ -14284,6 +14293,15 @@ static njs_unit_test_t njs_test[] =
"h.digest().toString('hex')"),
njs_str("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d") },
+ { njs_str("var h = require('crypto').createHmac('sha1', '');"
+ "var Hmac = h.constructor; "
+ "Hmac('sha1', '').digest('hex')"),
+ njs_str("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d") },
+
+ { njs_str("var h = require('crypto').createHmac('sha1', '');"
+ "h.constructor.name"),
+ njs_str("Hmac") },
+
{ njs_str("var h = require('crypto').createHmac('md5', 'secret key');"
"h.update('AB').digest('hex')"),
njs_str("9c72728915eb26620a5caeafd0063b29") },
More information about the nginx-devel
mailing list