'use strict'; var _const = require('../data/const.cjs'); var utils = require('./utils.cjs'); var scoring$8 = require('../matcher/bruteforce/scoring.cjs'); var scoring$7 = require('../matcher/date/scoring.cjs'); var scoring$6 = require('../matcher/dictionary/scoring.cjs'); var scoring$5 = require('../matcher/regex/scoring.cjs'); var scoring$4 = require('../matcher/repeat/scoring.cjs'); var scoring$3 = require('../matcher/sequence/scoring.cjs'); var scoring$2 = require('../matcher/spatial/scoring.cjs'); var scoring$1 = require('../matcher/separator/scoring.cjs'); var scoring = require('../matcher/wordSequence/scoring.cjs'); const getMinGuesses = (match, password) => { let minGuesses = 1; if (match.token.length < password.length) { if (match.token.length === 1) { minGuesses = _const.MIN_SUBMATCH_GUESSES_SINGLE_CHAR; } else { minGuesses = _const.MIN_SUBMATCH_GUESSES_MULTI_CHAR; } } return minGuesses; }; const matchers = { bruteforce: scoring$8, date: scoring$7, dictionary: scoring$6, regex: scoring$5, repeat: scoring$4, sequence: scoring$3, spatial: scoring$2, separator: scoring$1, wordSequence: scoring }; const getScoring = (options, name, match) => { if (matchers[name]) { return matchers[name](match, options); } if (options.matchers[name] && 'scoring' in options.matchers[name]) { return options.matchers[name].scoring(match, options); } return 0; }; // ------------------------------------------------------------------------------ // guess estimation -- one function per match pattern --------------------------- // ------------------------------------------------------------------------------ var estimateGuesses = (options, match, password) => { const extraData = {}; // a match's guess estimate doesn't change. cache it. if ('guesses' in match && match.guesses != null) { return match; } const minGuesses = getMinGuesses(match, password); const estimationResult = getScoring(options, match.pattern, match); let guesses = 0; if (typeof estimationResult === 'number') { guesses = estimationResult; } else if (match.pattern === 'dictionary') { guesses = estimationResult.calculation; extraData.baseGuesses = estimationResult.baseGuesses; extraData.uppercaseVariations = estimationResult.uppercaseVariations; extraData.l33tVariations = estimationResult.l33tVariations; } const matchGuesses = Math.max(guesses, minGuesses); return { ...match, ...extraData, guesses: matchGuesses, guessesLog10: utils.log10(matchGuesses) }; }; module.exports = estimateGuesses; //# sourceMappingURL=estimate.cjs.map