EasyPQC.FileOperations
WARNING: THIS FUNCTION DOES NOT WORK AND IS EXPERIMENTAL. THE WIKI FOR THIS IS OUTDATED AS I TEST OUT METHODS TO MAKE IT WORK.
Types
PackedFile
Represents a file that has been packed (compressed and optionally encrypted) with its associated signature.
-
Fields:
- string FilePath: The path of the packed file.
- string Signature: The signature of the packed file, usually encrypted.
-
Methods:
- ToString(): Converts the PackedFile to a string representation in the format FilePath|Signature.
- static PackedFile FromString(string packedFileString): Creates a PackedFile instance from a string representation.
CompressionLevel
Defines the level of compression for LZ4 compression.
- Values:
- Fast: Fast compression.
- Balanced: Balanced compression.
- Max: Maximum compression.
CompressionProgress
Delegate for reporting the progress of a file compression or decompression operation.
- Parameters:
- long current: The current position of the operation.
- long fileSize: The total size of the file.
- int percentage: The percentage of completion.
Methods
CompressFileAsync(string fileInput, string fileOutput, CompressionProgress compressionProgress, CompressionLevel compressionType)
Compresses a file asynchronously using LZ4 and reports progress.
-
Parameters:
- fileInput: The input file path.
- fileOutput: The output file path.
- compressionProgress: A delegate for progress reporting.
- compressionType: The level of compression to use.
-
Returns: Task: The path to the compressed file.
DecompressFileAsync(string fileInput, string fileOutput, CompressionProgress compressionProgress, CompressionLevel compressionType)
Decompresses a file asynchronously using LZ4 and reports progress.
-
Parameters:
- fileInput: The input file path.
- fileOutput: The output file path.
- compressionProgress: A delegate for progress reporting.
- compressionType: The level of compression to use.
-
Returns: Task: The path to the decompressed file.
HashFile(Stream fileData)
Hashes a file asynchronously using Blake3.
-
Parameters:
- fileData: The stream containing the file data to hash.
-
Returns: Task<byte[]>: The computed hash of the file.
VerifyHash(Stream fileData, byte[] signature)
Verifies the integrity of a file by comparing its hash to a provided signature.
-
Parameters:
- fileData: The stream containing the file data to verify.
- signature: The signature to compare the hash against.
-
Returns: Task: true if the hash matches the signature, otherwise false.
PackFiles(string fileInput, string fileOutput, byte[] privateKey, SecureData sessionkey, CompressionProgress compressionProgress, CompressionLevel compressionType, bool encryptFile)
Compresses a file, creates a signed hash, and optionally encrypts the file.
-
Parameters:
- fileInput: The input file path.
- fileOutput: The output directory for the packed file.
- privateKey: The private key for signing the file hash.
- sessionkey: The session key for encryption (if applicable).
- compressionProgress: A delegate for progress reporting.
- compressionType: The level of compression to use.
- encryptFile: Whether to encrypt the packed file.
-
Returns: Task: A PackedFile containing the packed file and its signature.
UnpackFile(PackedFile inputFile, string outputPath, byte[] publicKey, CompressionProgress compressionProgress, CompressionLevel compressionType, SecureData sessionkey)
Unpacks and decompresses a file, verifying its signature and decrypting it if necessary.
-
Parameters:
- inputFile: The packed file to unpack.
- outputPath: The directory where the unpacked file should be saved.
- publicKey: The public key for signature verification.
- compressionProgress: A delegate for progress reporting.
- compressionType: The level of compression used.
- sessionkey: The session key for decryption (if applicable).
-
Returns: Task: true if the file was successfully unpacked and verified, otherwise false.