Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a6c93af

Browse filesBrowse files
TrottItalo A. Casas
authored andcommitted
lib: refactor crypto cipher/hash/curve getters
* refactor internal util.filterDuplicateStrings() to eliminate unused code paths * `.indexOf()` -> `.includes()` in test * more concise arrow functions PR-URL: #10682 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com>
1 parent dbb7727 commit a6c93af
Copy full SHA for a6c93af

File tree

Expand file treeCollapse file tree

3 files changed

+12
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+12
-18
lines changed
Open diff view settings
Collapse file

‎lib/crypto.js‎

Copy file name to clipboardExpand all lines: lib/crypto.js
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -637,17 +637,17 @@ exports.randomBytes = exports.pseudoRandomBytes = randomBytes;
637637

638638
exports.rng = exports.prng = randomBytes;
639639

640-
exports.getCiphers = internalUtil.cachedResult(() => {
641-
return internalUtil.filterDuplicateStrings(getCiphers());
642-
});
640+
exports.getCiphers = internalUtil.cachedResult(
641+
() => internalUtil.filterDuplicateStrings(getCiphers())
642+
);
643643

644-
exports.getHashes = internalUtil.cachedResult(() => {
645-
return internalUtil.filterDuplicateStrings(getHashes());
646-
});
644+
exports.getHashes = internalUtil.cachedResult(
645+
() => internalUtil.filterDuplicateStrings(getHashes())
646+
);
647647

648-
exports.getCurves = internalUtil.cachedResult(() => {
649-
return internalUtil.filterDuplicateStrings(getCurves());
650-
});
648+
exports.getCurves = internalUtil.cachedResult(
649+
() => internalUtil.filterDuplicateStrings(getCurves())
650+
);
651651

652652
Object.defineProperty(exports, 'fips', {
653653
get: getFipsCrypto,
Collapse file

‎lib/internal/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/util.js
+2-8Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,14 @@ exports.normalizeEncoding = function normalizeEncoding(enc) {
134134
// Filters duplicate strings. Used to support functions in crypto and tls
135135
// modules. Implemented specifically to maintain existing behaviors in each.
136136
exports.filterDuplicateStrings = function filterDuplicateStrings(items, low) {
137-
if (!Array.isArray(items))
138-
return [];
139-
const len = items.length;
140-
if (len <= 1)
141-
return items;
142137
const map = new Map();
143-
for (var i = 0; i < len; i++) {
138+
for (var i = 0; i < items.length; i++) {
144139
const item = items[i];
145140
const key = item.toLowerCase();
146141
if (low) {
147142
map.set(key, key);
148143
} else {
149-
if (!map.has(key) || map.get(key) <= item)
150-
map.set(key, item);
144+
map.set(key, item);
151145
}
152146
}
153147
return Array.from(map.values()).sort();
Collapse file

‎test/parallel/test-crypto-authenticated.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-authenticated.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ const ciphers = crypto.getCiphers();
312312
for (const i in TEST_CASES) {
313313
const test = TEST_CASES[i];
314314

315-
if (ciphers.indexOf(test.algo) === -1) {
315+
if (!ciphers.includes(test.algo)) {
316316
common.skip('unsupported ' + test.algo + ' test');
317317
continue;
318318
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.