MCPcopy Create free account
hub / github.com/mscdex/ssh2 / generateAlgorithmList

Function generateAlgorithmList

lib/utils.js:210–321  ·  view source on GitHub ↗
(algoList, defaultList, supportedList)

Source from the content-addressed store, hash-verified

208})();
209
210function generateAlgorithmList(algoList, defaultList, supportedList) {
211 if (Array.isArray(algoList) && algoList.length > 0) {
212 // Exact list
213 for (let i = 0; i < algoList.length; ++i) {
214 if (supportedList.indexOf(algoList[i]) === -1)
215 throw new Error(`Unsupported algorithm: ${algoList[i]}`);
216 }
217 return algoList;
218 }
219
220 if (typeof algoList === 'object' && algoList !== null) {
221 // Operations based on the default list
222 const keys = Object.keys(algoList);
223 let list = defaultList;
224 for (let i = 0; i < keys.length; ++i) {
225 const key = keys[i];
226 let val = algoList[key];
227 switch (key) {
228 case 'append':
229 if (!Array.isArray(val))
230 val = [val];
231 if (Array.isArray(val)) {
232 for (let j = 0; j < val.length; ++j) {
233 const append = val[j];
234 if (typeof append === 'string') {
235 if (!append || list.indexOf(append) !== -1)
236 continue;
237 if (supportedList.indexOf(append) === -1)
238 throw new Error(`Unsupported algorithm: ${append}`);
239 if (list === defaultList)
240 list = list.slice();
241 list.push(append);
242 } else if (isRegExp(append)) {
243 for (let k = 0; k < supportedList.length; ++k) {
244 const algo = supportedList[k];
245 if (append.test(algo)) {
246 if (list.indexOf(algo) !== -1)
247 continue;
248 if (list === defaultList)
249 list = list.slice();
250 list.push(algo);
251 }
252 }
253 }
254 }
255 }
256 break;
257 case 'prepend':
258 if (!Array.isArray(val))
259 val = [val];
260 if (Array.isArray(val)) {
261 for (let j = val.length; j >= 0; --j) {
262 const prepend = val[j];
263 if (typeof prepend === 'string') {
264 if (!prepend || list.indexOf(prepend) !== -1)
265 continue;
266 if (supportedList.indexOf(prepend) === -1)
267 throw new Error(`Unsupported algorithm: ${prepend}`);

Callers 2

connectMethod · 0.85
constructorMethod · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…