From 009b4569b3d118b8d0981af7b79fc4279bb97d84 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 14 Jun 2010 13:10:23 -0700 Subject: [PATCH] Merge Hash.init() function into JS constructor --- lib/crypto.js | 2 +- src/node_crypto.cc | 22 +++++----------------- test/simple/test-crypto.js | 2 +- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/crypto.js b/lib/crypto.js index 753bf96122..b79d35790f 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -3635,7 +3635,7 @@ exports.Credentials = Credentials; exports.Hash = Hash; exports.createHash = function(hash) { - return (new Hash).init(hash); + return new Hash(hash); } exports.Hmac = Hmac; diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 284ae4996d..58c1c04489 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1992,7 +1992,6 @@ class Hash : public ObjectWrap { t->InstanceTemplate()->SetInternalFieldCount(1); - NODE_SET_PROTOTYPE_METHOD(t, "init", HashInit); NODE_SET_PROTOTYPE_METHOD(t, "update", HashUpdate); NODE_SET_PROTOTYPE_METHOD(t, "digest", HashDigest); @@ -2010,7 +2009,6 @@ class Hash : public ObjectWrap { EVP_DigestInit_ex(&mdctx, md, NULL); initialised = true; return true; - } int HashUpdate(char* data, int len) { @@ -2033,29 +2031,19 @@ class Hash : public ObjectWrap { protected: - static Handle - New (const Arguments& args) - { - HandleScope scope; - - Hash *hash = new Hash(); - hash->Wrap(args.This()); - return args.This(); - } - - static Handle - HashInit(const Arguments& args) { - Hash *hash = ObjectWrap::Unwrap(args.This()); - + static Handle New (const Arguments& args) { HandleScope scope; if (args.Length() == 0 || !args[0]->IsString()) { return ThrowException(String::New("Must give hashtype string as argument")); } + Hash *hash = new Hash(); + hash->Wrap(args.This()); + String::Utf8Value hashType(args[0]->ToString()); - bool r = hash->HashInit(*hashType); + hash->HashInit(*hashType); return args.This(); } diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index 8e2cabe42e..5f1a5c06ef 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -31,7 +31,7 @@ var a3 = crypto.createHash("sha512").update("Test123").digest(); // binary // Test multiple updates to same hash var h1 = crypto.createHash("sha1").update("Test123").digest("hex"); -var h2 = (new crypto.Hash).init("sha1").update("Test").update("123").digest("hex"); +var h2 = crypto.createHash("sha1").update("Test").update("123").digest("hex"); assert.equal(h1, h2, "multipled updates");