UNPKG

xypriss-security

Version:

XyPriss Security is an advanced JavaScript security library designed for enterprise applications. It provides military-grade encryption, secure data structures, quantum-resistant cryptography, and comprehensive security utilities for modern web applicatio

70 lines (67 loc) 2.2 kB
import { ALGORITHM_REGISTRY } from '../algorithms/registry.js'; /** * Utility class for algorithm validation and information */ class CryptoAlgorithmUtils { /** * Validates if an algorithm is supported */ static isSupported(algorithm) { return algorithm in ALGORITHM_REGISTRY; } /** * Gets algorithm information */ static getInfo(algorithm) { return ALGORITHM_REGISTRY[algorithm]; } /** * Checks if an algorithm is deprecated */ static isDeprecated(algorithm) { return ALGORITHM_REGISTRY[algorithm].deprecated; } /** * Gets all algorithms by security level */ static getAlgorithmsBySecurityLevel(level) { return Object.entries(ALGORITHM_REGISTRY) .filter(([, info]) => info.securityLevel === level) .map(([algorithm]) => algorithm); } /** * Gets recommended algorithms (non-deprecated, strong or very-strong) */ static getRecommendedAlgorithms() { return Object.entries(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(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; } } export { CryptoAlgorithmUtils }; //# sourceMappingURL=CryptoAlgorithmUtils.js.map