crypto: do not lowercase cipher/hash names
authorFedor Indutny <fedor.indutny@gmail.com>
Mon, 10 Mar 2014 10:59:18 +0000 (14:59 +0400)
committerFedor Indutny <fedor.indutny@gmail.com>
Mon, 10 Mar 2014 21:08:43 +0000 (01:08 +0400)
`crypto.getCiphers()` and `crypto.getHashes()` should prefer lower-case
variants of names, but should not introduce them.

fix #7282

lib/crypto.js
test/simple/test-crypto.js

index 22141ff..d1c9eb5 100644 (file)
@@ -608,8 +608,13 @@ function filterDuplicates(names) {
   // for example, 'sha1' instead of 'SHA1'.
   var ctx = {};
   names.forEach(function(name) {
-    if (/^[0-9A-Z\-]+$/.test(name)) name = name.toLowerCase();
-    ctx[name] = true;
+    var key = name;
+    if (/^[0-9A-Z\-]+$/.test(key)) key = key.toLowerCase();
+    if (!ctx.hasOwnProperty(key) || ctx[key] < name)
+      ctx[key] = name;
   });
-  return Object.getOwnPropertyNames(ctx).sort();
+
+  return Object.getOwnPropertyNames(ctx).map(function(key) {
+    return ctx[key];
+  }).sort();
 }
index 96a269f..25bb359 100644 (file)
@@ -867,6 +867,8 @@ assert.notEqual(-1, crypto.getHashes().indexOf('sha1'));
 assert.notEqual(-1, crypto.getHashes().indexOf('sha'));
 assert.equal(-1, crypto.getHashes().indexOf('SHA1'));
 assert.equal(-1, crypto.getHashes().indexOf('SHA'));
+assert.notEqual(-1, crypto.getHashes().indexOf('RSA-SHA1'));
+assert.equal(-1, crypto.getHashes().indexOf('rsa-sha1'));
 assertSorted(crypto.getHashes());
 
 // Base64 padding regression test, see #4837.