import { logger } from '../../logger.js';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.js';
import { RustSecurityBridge } from '../../security/classes.rustsecuritybridge.js';
/**
 * DKIM verifier — delegates to the Rust security bridge.
 */
export class DKIMVerifier {
    constructor() { }
    /**
     * Verify DKIM signature for an email via Rust bridge
     */
    async verify(emailData, options = {}) {
        try {
            const bridge = RustSecurityBridge.getInstance();
            const results = await bridge.verifyDkim(emailData);
            const first = results[0];
            const result = {
                isValid: first?.is_valid ?? false,
                domain: first?.domain ?? undefined,
                selector: first?.selector ?? undefined,
                status: first?.status ?? 'none',
                details: options.returnDetails ? results : undefined,
            };
            SecurityLogger.getInstance().logEvent({
                level: result.isValid ? SecurityLogLevel.INFO : SecurityLogLevel.WARN,
                type: SecurityEventType.DKIM,
                message: `DKIM verification ${result.isValid ? 'passed' : 'failed'} for domain ${result.domain || 'unknown'}`,
                details: { selector: result.selector, status: result.status },
                domain: result.domain || 'unknown',
                success: result.isValid
            });
            logger.log(result.isValid ? 'info' : 'warn', `DKIM verification: ${result.status} for domain ${result.domain || 'unknown'}`);
            return result;
        }
        catch (error) {
            logger.log('error', `DKIM verification failed: ${error.message}`);
            SecurityLogger.getInstance().logEvent({
                level: SecurityLogLevel.ERROR,
                type: SecurityEventType.DKIM,
                message: `DKIM verification error`,
                details: { error: error.message },
                success: false
            });
            return {
                isValid: false,
                status: 'temperror',
                errorMessage: `Verification error: ${error.message}`
            };
        }
    }
    /** No-op — Rust bridge handles its own caching */
    clearCache() { }
    /** Always 0 — cache is managed by the Rust side */
    getCacheSize() {
        return 0;
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5ka2ltdmVyaWZpZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi90cy9tYWlsL3NlY3VyaXR5L2NsYXNzZXMuZGtpbXZlcmlmaWVyLnRzIl0sIm5hbWVzIjpbXSwibWFw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