Browse Source

crypto: throw exception on unknown digest method

Fixes #2227.
v0.7.4-release
Ben Noordhuis 13 years ago
parent
commit
f44d0b9044
  1. 16
      src/node_crypto.cc
  2. 5
      test/simple/test-crypto.js

16
src/node_crypto.cc

@ -2890,10 +2890,7 @@ class Hash : public ObjectWrap {
bool HashInit (const char* hashType) {
md = EVP_get_digestbyname(hashType);
if(!md) {
fprintf(stderr, "node-crypto : Unknown message digest %s\n", hashType);
return false;
}
if(!md) return false;
EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, md, NULL);
initialised_ = true;
@ -2917,13 +2914,16 @@ class Hash : public ObjectWrap {
"Must give hashtype string as argument")));
}
Hash *hash = new Hash();
hash->Wrap(args.This());
String::Utf8Value hashType(args[0]->ToString());
hash->HashInit(*hashType);
Hash *hash = new Hash();
if (!hash->HashInit(*hashType)) {
delete hash;
return ThrowException(Exception::Error(String::New(
"Digest method not supported")));
}
hash->Wrap(args.This());
return args.This();
}

5
test/simple/test-crypto.js

@ -278,6 +278,11 @@ fileStream.on('close', function() {
'Test SHA1 of sample.png');
});
// Issue #2227: unknown digest method should throw an error.
assert.throws(function() {
crypto.createHash('xyzzy');
});
// Test signing and verifying
var s1 = crypto.createSign('RSA-SHA1')
.update('Test123')

Loading…
Cancel
Save