padding-oracle-attacker
Version:
CLI tool and library to execute padding oracle attacks easily
31 lines • 1.19 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const p_limit_1 = __importDefault(require("p-limit"));
const bluebird_1 = __importDefault(require("./bluebird"));
class IgnoreError extends Error {
constructor() {
super();
this.name = 'IgnoreError';
}
}
const rejectOnFalsey = (limit) => async (promise) => {
const returnVal = await limit(promise);
if (returnVal)
return returnVal;
return Promise.reject(new IgnoreError());
};
// take an array of promises
// run n (`concurrency`) promises concurrently
// when any promise is fulfilled with a truthy value, stop
async function waitUntilFirstTruthyPromise(promises, { concurrency = 16 } = {}) {
const limit = p_limit_1.default(concurrency);
await bluebird_1.default.any(promises.map(rejectOnFalsey(limit))).catch(bluebird_1.default.AggregateError, (err) => {
if (!(err[0] instanceof IgnoreError))
throw err[0];
});
}
exports.default = waitUntilFirstTruthyPromise;
//# sourceMappingURL=promises.js.map