FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

crypto: throw exception on unknown digest method · bmehanni/node@f44d0b9 · GitHub

Repository navigation

Commit f44d0b9

Browse files
committed
crypto: throw exception on unknown digest method
Fixes nodejs#2227.
1 parent bbd976b commit f44d0b9

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎src/node_crypto.cc‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,10 +2890,7 @@ class Hash : public ObjectWrap {
28902890

28912891
bool HashInit (const char* hashType) {
28922892
md = EVP_get_digestbyname(hashType);
2893-
if(!md) {
2894-
fprintf(stderr, "node-crypto : Unknown message digest %s\n", hashType);
2895-
return false;
2896-
}
2893+
if(!md) return false;
28972894
EVP_MD_CTX_init(&mdctx);
28982895
EVP_DigestInit_ex(&mdctx, md, NULL);
28992896
initialised_ = true;
@@ -2917,13 +2914,16 @@ class Hash : public ObjectWrap {
29172914
"Must give hashtype string as argument")));
29182915
}
29192916

2920-
Hash *hash = new Hash();
2921-
hash->Wrap(args.This());
2922-
29232917
String::Utf8Value hashType(args[0]->ToString());
29242918

2925-
hash->HashInit(*hashType);
2919+
Hash *hash = new Hash();
2920+
if (!hash->HashInit(*hashType)) {
2921+
delete hash;
2922+
return ThrowException(Exception::Error(String::New(
2923+
"Digest method not supported")));
2924+
}
29262925

2926+
hash->Wrap(args.This());
29272927
return args.This();
29282928
}
29292929

‎test/simple/test-crypto.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ fileStream.on('close', function() {
278278
'Test SHA1 of sample.png');
279279
});
280280

281+
// Issue #2227: unknown digest method should throw an error.
282+
assert.throws(function() {
283+
crypto.createHash('xyzzy');
284+
});
285+
281286
// Test signing and verifying
282287
var s1 = crypto.createSign('RSA-SHA1')
283288
.update('Test123')

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL