Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
crypto: do not lowercase cipher/hash names
Browse files Browse the repository at this point in the history
`crypto.getCiphers()` and `crypto.getHashes()` should prefer lower-case
variants of names, but should not introduce them.

fix #7282
  • Loading branch information
indutny committed Mar 10, 2014
1 parent 6bd78fd commit f0d8705
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/crypto.js
Expand Up @@ -608,8 +608,13 @@ function filterDuplicates(names) {
// for example, 'sha1' instead of 'SHA1'.

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Mar 11, 2014

Member

You forgot to update the comment.

This comment has been minimized.

Copy link
@indutny

indutny Mar 11, 2014

Author Member

Why? I think it is correct, but the code wasn't :)

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();
}
2 changes: 2 additions & 0 deletions test/simple/test-crypto.js
Expand Up @@ -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.
Expand Down

0 comments on commit f0d8705

Please sign in to comment.