Browse Source

Merge Hash.init() function into JS constructor

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
009b4569b3
  1. 2
      lib/crypto.js
  2. 22
      src/node_crypto.cc
  3. 2
      test/simple/test-crypto.js

2
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;

22
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<Value>
New (const Arguments& args)
{
HandleScope scope;
Hash *hash = new Hash();
hash->Wrap(args.This());
return args.This();
}
static Handle<Value>
HashInit(const Arguments& args) {
Hash *hash = ObjectWrap::Unwrap<Hash>(args.This());
static Handle<Value> 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();
}

2
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");

Loading…
Cancel
Save