n-digit-token
Version:
Cryptographically secure pseudo-random token of n digits
33 lines (32 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateCustomMemory = void 0;
const constants_1 = require("../constants");
/**
* Validates options.customMemory.
* Please read the README for more information.
* @param length
* @param options
* @throws {error} if called with invalid options
*/
const validateCustomMemory = (length, options) => {
if (!options || options.customMemory === undefined) {
return;
}
// check order has to follow options > 0 > undef/null
if (options.customMemory === 0) {
throw new Error('Invalid options: customMemory must be a positive integer.');
}
if (!Number.isInteger(options.customMemory) || options.customMemory <= 0) {
throw new Error('Invalid options: customMemory must be a positive integer.');
}
if (options.customMemory < constants_1.DEFAULT_BYTE_SIZE + length) {
/* tslint:disable-next-line:no-console */
console.warn('Warning - scarce memory: Allocated memory is less than ideal for the algorithm, this *may* result in decreased performance.');
}
if (options.customMemory > (constants_1.DEFAULT_BYTE_SIZE + length) * 2) {
/* tslint:disable-next-line:no-console */
console.warn('Warning - overcompensated memory: Allocated memory is more than ideal for the algorithm, this *may* result in decreased performance.');
}
};
exports.validateCustomMemory = validateCustomMemory;