Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

crypto: do not lowercase cipher/hash names

`crypto.getCiphers()` and `crypto.getHashes()` should prefer lower-case
variants of names, but should not introduce them.

fix #7282
  • Loading branch information...
commit f0d870501ed240f550b2be6b0a138312fb6f4a30 1 parent 6bd78fd
@indutny indutny authored
Showing with 10 additions and 3 deletions.
  1. +8 −3 lib/crypto.js
  2. +2 −0  test/simple/test-crypto.js
View
11 lib/crypto.js
@@ -608,8 +608,13 @@ function filterDuplicates(names) {
// for example, 'sha1' instead of 'SHA1'.

You forgot to update the comment.

@indutny Owner
indutny added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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();
}
View
2  test/simple/test-crypto.js
@@ -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.
@bnoordhuis

You forgot to update the comment.

@indutny

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

Please sign in to comment.
Something went wrong with that request. Please try again.