UNPKG

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.

106 lines (102 loc) 3.18 kB
'use strict'; var events = require('events'); var utils = require('../../utils/utils.js'); /** * Execution Context Manager for Fortified Function Core * Manages secure execution contexts and their lifecycle */ class ExecutionContextManager extends events.EventEmitter { constructor(options, securityManager) { super(); this.activeExecutions = new Map(); this.options = options; this.securityManager = securityManager; } /** * Create secure execution context with encrypted parameters */ async createSecureExecutionContext(executionId, args) { const startTime = performance.now(); const memorySnapshot = utils.FortifiedUtils.getCurrentMemoryUsage(); const context = { executionId, encryptedParameters: new Map(), secureBuffers: new Map(), startTime, memorySnapshot, auditEntry: { timestamp: new Date(), executionId, parametersHash: await this.securityManager.hashParameters(args), executionTime: 0, memoryUsage: memorySnapshot, success: false, securityFlags: [], }, }; // Encrypt sensitive parameters if (this.options.autoEncrypt) { await this.securityManager.encryptParameters(context, args); } this.activeExecutions.set(executionId, context); this.emit("context_created", { executionId }); return context; } /** * Get execution context by ID */ getExecutionContext(executionId) { return this.activeExecutions.get(executionId); } /** * Get all active execution contexts */ getActiveExecutions() { return new Map(this.activeExecutions); } /** * Schedule secure cleanup of execution context */ scheduleCleanup(context) { const cleanup = () => { // Destroy secure buffers for (const buffer of context.secureBuffers.values()) { buffer.destroy(); } // Clear encrypted parameters context.encryptedParameters.clear(); // Remove from active executions this.activeExecutions.delete(context.executionId); this.emit("context_cleaned", { executionId: context.executionId }); }; if (this.options.memoryWipeDelay > 0) { setTimeout(cleanup, this.options.memoryWipeDelay); } else { cleanup(); } } /** * Clean up all active executions */ cleanupAllExecutions() { for (const context of this.activeExecutions.values()) { this.scheduleCleanup(context); } } /** * Get execution count */ getActiveExecutionCount() { return this.activeExecutions.size; } /** * Clean up resources */ destroy() { this.cleanupAllExecutions(); this.removeAllListeners(); } } exports.ExecutionContextManager = ExecutionContextManager; //# sourceMappingURL=execution-context.js.map