| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0593351 commit 2c7804a
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,20 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + | ||
| 5 | + const bench = common.createBenchmark(main, { | ||
| 6 | + n: [1, 5000], | ||
| 7 | + v: ['crypto', 'tls'] | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + function main(conf) { | ||
| 11 | + const n = +conf.n; | ||
| 12 | + const v = conf.v; | ||
| 13 | + const method = require(v).getCiphers; | ||
| 14 | + var i = 0; | ||
| 15 | + | ||
| 16 | + common.v8ForceOptimization(method); | ||
| 17 | + bench.start(); | ||
| 18 | + for (; i < n; i++) method(); | ||
| 19 | + bench.end(n); | ||
| 20 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -632,41 +632,23 @@ exports.randomBytes = exports.pseudoRandomBytes = randomBytes; | |||
| 632 | 632 | ||
| 633 | 633 | exports.rng = exports.prng = randomBytes; | |
| 634 | 634 | ||
| 635 | - exports.getCiphers = function() { | ||
| 636 | - return filterDuplicates(getCiphers()); | ||
| 637 | - }; | ||
| 638 | - | ||
| 639 | - | ||
| 640 | - exports.getHashes = function() { | ||
| 641 | - return filterDuplicates(getHashes()); | ||
| 642 | - }; | ||
| 635 | + exports.getCiphers = internalUtil.cachedResult(() => { | ||
| 636 | + return internalUtil.filterDuplicateStrings(getCiphers()); | ||
| 637 | + }); | ||
| 643 | 638 | ||
| 639 | + exports.getHashes = internalUtil.cachedResult(() => { | ||
| 640 | + return internalUtil.filterDuplicateStrings(getHashes()); | ||
| 641 | + }); | ||
| 644 | 642 | ||
| 645 | - exports.getCurves = function() { | ||
| 646 | - return filterDuplicates(getCurves()); | ||
| 647 | - }; | ||
| 643 | + exports.getCurves = internalUtil.cachedResult(() => { | ||
| 644 | + return internalUtil.filterDuplicateStrings(getCurves()); | ||
| 645 | + }); | ||
| 648 | 646 | ||
| 649 | 647 | Object.defineProperty(exports, 'fips', { | |
| 650 | 648 | get: getFipsCrypto, | |
| 651 | 649 | set: setFipsCrypto | |
| 652 | 650 | }); | |
| 653 | 651 | ||
| 654 | - function filterDuplicates(names) { | ||
| 655 | - // Drop all-caps names in favor of their lowercase aliases, | ||
| 656 | - // for example, 'sha1' instead of 'SHA1'. | ||
| 657 | - var ctx = {}; | ||
| 658 | - names.forEach(function(name) { | ||
| 659 | - var key = name; | ||
| 660 | - if (/^[0-9A-Z\-]+$/.test(key)) key = key.toLowerCase(); | ||
| 661 | - if (!ctx.hasOwnProperty(key) || ctx[key] < name) | ||
| 662 | - ctx[key] = name; | ||
| 663 | - }); | ||
| 664 | - | ||
| 665 | - return Object.getOwnPropertyNames(ctx).map(function(key) { | ||
| 666 | - return ctx[key]; | ||
| 667 | - }).sort(); | ||
| 668 | - } | ||
| 669 | - | ||
| 670 | 652 | // Legacy API | |
| 671 | 653 | Object.defineProperty(exports, 'createCredentials', { | |
| 672 | 654 | configurable: true, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,3 +89,34 @@ exports.assertCrypto = function(exports) { | |||
| 89 | 89 | if (noCrypto) | |
| 90 | 90 | throw new Error('Node.js is not compiled with openssl crypto support'); | |
| 91 | 91 | }; | |
| 92 | + | ||
| 93 | + // Filters duplicate strings. Used to support functions in crypto and tls | ||
| 94 | + // modules. Implemented specifically to maintain existing behaviors in each. | ||
| 95 | + exports.filterDuplicateStrings = function filterDuplicateStrings(items, low) { | ||
| 96 | + if (!Array.isArray(items)) | ||
| 97 | + return []; | ||
| 98 | + const len = items.length; | ||
| 99 | + if (len <= 1) | ||
| 100 | + return items; | ||
| 101 | + const map = new Map(); | ||
| 102 | + for (var i = 0; i < len; i++) { | ||
| 103 | + const item = items[i]; | ||
| 104 | + const key = item.toLowerCase(); | ||
| 105 | + if (low) { | ||
| 106 | + map.set(key, key); | ||
| 107 | + } else { | ||
| 108 | + if (!map.has(key) || map.get(key) <= item) | ||
| 109 | + map.set(key, item); | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + return Array.from(map.values()).sort(); | ||
| 113 | + }; | ||
| 114 | + | ||
| 115 | + exports.cachedResult = function cachedResult(fn) { | ||
| 116 | + var result; | ||
| 117 | + return () => { | ||
| 118 | + if (result === undefined) | ||
| 119 | + result = fn(); | ||
| 120 | + return result; | ||
| 121 | + }; | ||
| 122 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('internal/util').assertCrypto(exports); | ||
| 3 | + const internalUtil = require('internal/util'); | ||
| 4 | + internalUtil.assertCrypto(exports); | ||
| 4 | 5 | ||
| 5 | 6 | const net = require('net'); | |
| 6 | 7 | const url = require('url'); | |
@@ -21,16 +22,9 @@ exports.DEFAULT_CIPHERS = | |||
| 21 | 22 | ||
| 22 | 23 | exports.DEFAULT_ECDH_CURVE = 'prime256v1'; | |
| 23 | 24 | ||
| 24 | - exports.getCiphers = function() { | ||
| 25 | - const names = binding.getSSLCiphers(); | ||
| 26 | - // Drop all-caps names in favor of their lowercase aliases, | ||
| 27 | - var ctx = {}; | ||
| 28 | - names.forEach(function(name) { | ||
| 29 | - if (/^[0-9A-Z\-]+$/.test(name)) name = name.toLowerCase(); | ||
| 30 | - ctx[name] = true; | ||
| 31 | - }); | ||
| 32 | - return Object.getOwnPropertyNames(ctx).sort(); | ||
| 33 | - }; | ||
| 25 | + exports.getCiphers = internalUtil.cachedResult(() => { | ||
| 26 | + return internalUtil.filterDuplicateStrings(binding.getSSLCiphers(), true); | ||
| 27 | + }); | ||
| 34 | 28 | ||
| 35 | 29 | // Convert protocols array into valid OpenSSL protocols list | |
| 36 | 30 | // ("\x06spdy/2\x08http/1.1\x08http/1.0") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments