fortify2-js
Version:
MOST POWERFUL JavaScript Security Library! Military-grade cryptography + 19 enhanced object methods + quantum-resistant algorithms + perfect TypeScript support. More powerful than Lodash with built-in security.
72 lines (68 loc) • 2.28 kB
JavaScript
;
var registry = require('../algorithms/registry.js');
/**
* Utility class for algorithm validation and information
*/
class CryptoAlgorithmUtils {
/**
* Validates if an algorithm is supported
*/
static isSupported(algorithm) {
return algorithm in registry.ALGORITHM_REGISTRY;
}
/**
* Gets algorithm information
*/
static getInfo(algorithm) {
return registry.ALGORITHM_REGISTRY[algorithm];
}
/**
* Checks if an algorithm is deprecated
*/
static isDeprecated(algorithm) {
return registry.ALGORITHM_REGISTRY[algorithm].deprecated;
}
/**
* Gets all algorithms by security level
*/
static getAlgorithmsBySecurityLevel(level) {
return Object.entries(registry.ALGORITHM_REGISTRY)
.filter(([, info]) => info.securityLevel === level)
.map(([algorithm]) => algorithm);
}
/**
* Gets recommended algorithms (non-deprecated, strong or very-strong)
*/
static getRecommendedAlgorithms() {
return Object.entries(registry.ALGORITHM_REGISTRY)
.filter(([, info]) => !info.deprecated &&
(info.securityLevel === "strong" ||
info.securityLevel === "very-strong"))
.map(([algorithm]) => algorithm);
}
/**
* Validates algorithm and warns about deprecated ones
*/
static validateAlgorithm(algorithm) {
if (!this.isSupported(algorithm)) {
throw new Error(`Unsupported algorithm: ${algorithm}. Supported: ${Object.keys(registry.ALGORITHM_REGISTRY).join(", ")}`);
}
const info = this.getInfo(algorithm);
if (info.deprecated) {
console.warn(`Warning: ${algorithm} is deprecated. ${info.description}`);
}
// For now, only return hash algorithms for the hash method
const hashAlgorithms = [
"SHA-1",
"SHA-256",
"SHA-384",
"SHA-512",
];
if (!hashAlgorithms.includes(algorithm)) {
throw new Error(`Algorithm ${algorithm} is not a hash algorithm`);
}
return algorithm;
}
}
exports.CryptoAlgorithmUtils = CryptoAlgorithmUtils;
//# sourceMappingURL=CryptoAlgorithmUtils.js.map