Merge Hash.init() function into JS constructor
This commit is contained in:
parent
5f3906b65e
commit
009b4569b3
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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…
x
Reference in New Issue
Block a user