/**
 * File Access Control System
 * Provides secure file operations with access controls and audit logging
 */
import { Readable } from 'stream';
import type { LogContext } from '../utils/logger';
export interface FileAccessPolicy {
    /** Allowed operations for this path */
    allowedOperations: FileOperation[];
    /** Maximum file size for operations */
    maxFileSize: number;
    /** Rate limit for operations per minute */
    rateLimit: number;
    /** Whether to require integrity verification */
    requireIntegrityCheck: boolean;
    /** Temporary file cleanup timeout */
    tempFileTimeout: number;
}
export type FileOperation = 'read' | 'write' | 'delete' | 'create' | 'metadata' | 'create_handle' | 'integrity_check' | 'quarantine' | 'release_quarantine';
export interface SecureFileHandle {
    /** Unique handle ID */
    id: string;
    /** Original file path */
    path: string;
    /** Sanitized file path */
    safePath: string;
    /** File hash for integrity */
    hash: string;
    /** Creation timestamp */
    createdAt: number;
    /** Access policy */
    policy: FileAccessPolicy;
    /** Usage statistics */
    stats: {
        reads: number;
        writes: number;
        lastAccessed: number;
    };
}
export interface AuditLogEntry {
    timestamp: Date;
    operation: FileOperation;
    filePath: string;
    userId?: string;
    success: boolean;
    error?: string;
    metadata?: Record<string, unknown>;
}
export declare class FileAccessController {
    private static instance;
    private handles;
    private auditLog;
    private operationCounts;
    private quarantinedFiles;
    private defaultPolicy;
    private constructor();
    static getInstance(): FileAccessController;
    /**
     * Create a secure file handle with validation and access control
     */
    createSecureHandle(filePath: string, operation: FileOperation, policy?: Partial<FileAccessPolicy>, context?: LogContext): Promise<SecureFileHandle>;
    /**
     * Create a secure readable stream with access controls
     */
    createSecureReadStream(handle: SecureFileHandle, options?: {
        start?: number;
        end?: number;
        encoding?: BufferEncoding;
    }): Readable;
    /**
     * Create a secure writable stream with access controls
     */
    createSecureWriteStream(handle: SecureFileHandle, options?: {
        flags?: string;
        mode?: number;
    }): NodeJS.WritableStream;
    /**
     * Verify file integrity using stored hash
     */
    verifyFileIntegrity(handle: SecureFileHandle): Promise<boolean>;
    /**
     * Quarantine a file due to security concerns
     */
    quarantineFile(filePath: string, reason: string): void;
    /**
     * Release a file from quarantine
     */
    releaseFromQuarantine(filePath: string, authorizer: string): void;
    /**
     * Get audit log entries
     */
    getAuditLog(filter?: {
        filePath?: string;
        operation?: FileOperation;
        startTime?: Date;
        endTime?: Date;
        successOnly?: boolean;
    }): AuditLogEntry[];
    /**
     * Clean up expired handles and temporary files
     */
    cleanup(): Promise<void>;
    private validateHandle;
    private checkRateLimit;
    private generateFileHash;
    private generateHandleId;
    private detectSuspiciousContent;
    private detectMaliciousContent;
    private logAuditEvent;
    private initializeCleanupTimer;
    /**
     * Get statistics about file operations
     */
    getStatistics(): {
        totalHandles: number;
        quarantinedFiles: number;
        auditLogSize: number;
        operationCounts: Record<string, number>;
    };
}
/**
 * Factory function for easy access
 */
export declare function getFileAccessController(): FileAccessController;
/**
 * Secure file operations wrapper
 */
export declare class SecureFileOperations {
    private controller;
    constructor();
    /**
     * Securely read a file with access controls
     */
    readFile(filePath: string, options?: {
        encoding?: BufferEncoding;
        policy?: Partial<FileAccessPolicy>;
    }, context?: LogContext): Promise<string | Buffer>;
    /**
     * Securely write a file with access controls
     */
    writeFile(filePath: string, data: string | Buffer, options?: {
        encoding?: BufferEncoding;
        policy?: Partial<FileAccessPolicy>;
    }, context?: LogContext): Promise<void>;
}
//# sourceMappingURL=file-access-controller.d.ts.map