import { CustomFileTypes, FileSignature } from '../interfaces/custom-file-type.interface'; import { MimeRegistryService } from './mime-registry.service'; /** * 检测到的文件类型 */ export interface DetectedType { /** 类型名称 */ type: string; /** 签名 */ signature: FileSignature; /** 置信度 0-1 */ confidence: number; /** 是否为自定义类型 */ isCustom?: boolean; } /** * 文件完整性检查结果 */ export interface IntegrityResult { /** 是否完整 */ valid: boolean; /** 错误列表 */ errors: string[]; } /** * 签名验证选项 */ export interface SignatureValidationOptions { /** 读取的最大字节数 */ maxReadBytes?: number; /** 是否严格验证 */ strict?: boolean; /** 容差范围 */ tolerance?: number; } /** * 验证结果 */ export interface ValidationResult { /** 验证是否通过 */ valid: boolean; /** 检测到的类型 */ detectedTypes: DetectedType[]; /** 期望的类型 */ expectedTypes: string[]; /** 错误列表 */ errors: string[]; /** 元数据 */ metadata: { fileSize: number; confidence: number; signatures: Array<{ type: string; signature: FileSignature; }>; }; } /** * 文件签名验证服务 */ export declare class FileSignatureValidator { private readonly mimeRegistry; private readonly logger; private readonly defaultSignatures; constructor(mimeRegistry: MimeRegistryService, customTypes?: CustomFileTypes); /** * 验证文件签名 */ validateFileSignature(filePath: string, expectedTypes: string[], options?: SignatureValidationOptions): Promise; /** * 检测文件类型 */ detectFileTypes(buffer: Buffer): Promise; /** * 注册自定义签名 */ registerCustomSignatures(customTypes: CustomFileTypes): void; /** * 检查签名是否匹配 */ private matchesSignature; /** * 检查类型是否匹配 */ private matchesType; /** * 规范化签名字节 */ private normalizeSignatureBytes; /** * 读取文件缓冲区 */ private readFileBuffer; /** * 检查文件完整性 */ private checkFileIntegrity; /** * 读取文件尾部 */ private readFileTail; /** * 计算签名置信度 */ private calculateSignatureConfidence; /** * 计算总体置信度 */ private calculateConfidence; /** * 获取验证错误信息 */ private getValidationError; /** * 初始化默认签名 */ private initializeDefaultSignatures; }