| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bbd976b commit f44d0b9
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2890,10 +2890,7 @@ class Hash : public ObjectWrap { | |||
| 2890 | 2890 | ||
| 2891 | 2891 | bool HashInit (const char* hashType) { | |
| 2892 | 2892 | 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; | ||
| 2897 | 2894 | EVP_MD_CTX_init(&mdctx); | |
| 2898 | 2895 | EVP_DigestInit_ex(&mdctx, md, NULL); | |
| 2899 | 2896 | initialised_ = true; | |
@@ -2917,13 +2914,16 @@ class Hash : public ObjectWrap { | |||
| 2917 | 2914 | "Must give hashtype string as argument"))); | |
| 2918 | 2915 | } | |
| 2919 | 2916 | ||
| 2920 | - Hash *hash = new Hash(); | ||
| 2921 | - hash->Wrap(args.This()); | ||
| 2922 | - | ||
| 2923 | 2917 | String::Utf8Value hashType(args[0]->ToString()); | |
| 2924 | 2918 | ||
| 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 | + } | ||
| 2926 | 2925 | ||
| 2926 | + hash->Wrap(args.This()); | ||
| 2927 | 2927 | return args.This(); | |
| 2928 | 2928 | } | |
| 2929 | 2929 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -278,6 +278,11 @@ fileStream.on('close', function() { | |||
| 278 | 278 | 'Test SHA1 of sample.png'); | |
| 279 | 279 | }); | |
| 280 | 280 | ||
| 281 | + // Issue #2227: unknown digest method should throw an error. | ||
| 282 | + assert.throws(function() { | ||
| 283 | + crypto.createHash('xyzzy'); | ||
| 284 | + }); | ||
| 285 | + | ||
| 281 | 286 | // Test signing and verifying | |
| 282 | 287 | var s1 = crypto.createSign('RSA-SHA1') | |
| 283 | 288 | .update('Test123') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments