Skip to content

Releases: mm9942/crypt_guard

V1.3.10 - Fix for rust beta: 1.85.0-beta.5

22 Jan 00:48
b444692
Compare
Choose a tag to compare

New Version: V1.3.10

Fix for rust beta: 1.85.0-beta.5

New Features since: V1.3.9

New Features:

Macros:

ArchiveUtil!(path, delete_flag, Variant);
  • $path: The path to the directory/file to archive or the archive file to extract. Accepts a &str or a PathBuf.
  • $delete_flag: A boolean indicating whether to delete the original directory/file or the archive file after the operation.
  • Variant: Specifies the operation type. Use Archive to compress and Extract to decompress.

Variants:

  • Archive: Compresses the specified directory or file.
  • Extract: Decompresses the specified archive file.
extract!(archive_path, delete_archive);
  • $archive_path: The path to the .tar.xz archive you intend to extract. It can be a &str or a PathBuf.
  • $delete_archive: A boolean flag indicating whether to delete the archive file after extraction (true to delete, false to retain).
archive!(source_path, delete_dir);
  • $source_path: The path to the directory or file you wish to archive. It can be provided as a &str or a PathBuf.
  • $delete_dir: A boolean flag indicating whether to delete the original directory or file after archiving (true to delete, false to retain).

Zip Manager:

Zipping Files and Directories Using the ZipManager

CryptGuard introduces the ZipManager, a utility for archiving multiple files and directories into a single ZIP archive. This tool simplifies the process of creating ZIP files by providing an easy-to-use API. Macros for zipping will be added later.

Example 1: Zipping Both Files and Directories

In this example, we'll demonstrate how to zip multiple files and directories into one ZIP archive.

use crypt_guard::zip_manager::*;
use std::path::PathBuf;
use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Setting up sample files and directories
    // Create a sample directory
    fs::create_dir_all("sample_dir")?;
    fs::create_dir_all("sample_dir/nested_dir")?;
    
    // Create sample files
    fs::write("file1.txt", "This is the content of file1.")?;
    fs::write("file2.txt", "This is the content of file2.")?;
    fs::write("sample_dir/file3.txt", "This is the content of file3 in sample_dir.")?;
    fs::write("sample_dir/nested_dir/file4.txt", "This is the content of file4 in nested_dir.")?;
    
    // Specify the output ZIP file path
    let output_zip = "archive_with_dirs.zip";
    
    // Create a new ZipManager instance
    let mut manager = ZipManager::new(output_zip);
    
    // Add individual files to the zip
    manager.add_file("file1.txt");
    manager.add_file("file2.txt");
    
    // Add directories to the zip
    manager.add_directory("sample_dir");
    
    // Create the ZIP archive with Deflated compression
    manager.create_zip(Compression::Deflated)?;
    
    println!("ZIP archive created at {}", output_zip);
    
    // Cleanup sample files and directories
    fs::remove_file("file1.txt")?;
    fs::remove_file("file2.txt")?;
    fs::remove_dir_all("sample_dir")?;
    
    Ok(())
}
Example 2: Zipping Multiple Files Only

Here's how to zip multiple individual files into a single ZIP archive.

use crypt_guard::zip_manager::*;
use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Setting up sample files
    fs::write("file1.txt", "Content of file1")?;
    fs::write("file2.txt", "Content of file2")?;
    fs::write("file3.txt", "Content of file3")?;
    
    // Specify the output ZIP file path
    let output_zip = "archive_with_files.zip";
    
    // Create a new ZipManager instance
    let mut manager = ZipManager::new(output_zip);
    
    // Add files to zip
    manager.add_file("file1.txt");
    manager.add_file("file2.txt");
    manager.add_file("file3.txt");
    
    // Create the ZIP archive with Deflated compression
    manager.create_zip(Compression::Deflated)?;
    
    println!("ZIP archive created at {}", output_zip);
    
    // Cleanup sample files
    fs::remove_file("file1.txt")?;
    fs::remove_file("file2.txt")?;
    fs::remove_file("file3.txt")?;
    
    Ok(())
}
Compression Methods

The ZipManager allows you to choose from different compression methods depending on your needs. The available options are:

  • Compression::stored(): No compression is applied. Use this option for faster archiving when compression is unnecessary.
  • Compression::deflated(): Standard ZIP compression. Offers a good balance between compression ratio and speed.
  • Compression::zip2(): Uses Bzip2 compression. Provides higher compression ratios but may be slower.
  • Compression::zstd(): Uses Zstandard compression. Offers high compression ratios and speed. Note that to use Zstandard compression, you need to enable the zstd feature in the zip crate.

Full Changelog: V1.3.0...V1.3.9

V1.3.9

21 Jan 23:38
d86a957
Compare
Choose a tag to compare

New Version: V1.3.9

New Features:

Macros:

ArchiveUtil!(path, delete_flag, Variant);
  • $path: The path to the directory/file to archive or the archive file to extract. Accepts a &str or a PathBuf.
  • $delete_flag: A boolean indicating whether to delete the original directory/file or the archive file after the operation.
  • Variant: Specifies the operation type. Use Archive to compress and Extract to decompress.

Variants:

  • Archive: Compresses the specified directory or file.
  • Extract: Decompresses the specified archive file.
extract!(archive_path, delete_archive);
  • $archive_path: The path to the .tar.xz archive you intend to extract. It can be a &str or a PathBuf.
  • $delete_archive: A boolean flag indicating whether to delete the archive file after extraction (true to delete, false to retain).
archive!(source_path, delete_dir);
  • $source_path: The path to the directory or file you wish to archive. It can be provided as a &str or a PathBuf.
  • $delete_dir: A boolean flag indicating whether to delete the original directory or file after archiving (true to delete, false to retain).

Zip Manager:

Zipping Files and Directories Using the ZipManager

CryptGuard introduces the ZipManager, a utility for archiving multiple files and directories into a single ZIP archive. This tool simplifies the process of creating ZIP files by providing an easy-to-use API. Macros for zipping will be added later.

Example 1: Zipping Both Files and Directories

In this example, we'll demonstrate how to zip multiple files and directories into one ZIP archive.

use crypt_guard::zip_manager::*;
use std::path::PathBuf;
use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Setting up sample files and directories
    // Create a sample directory
    fs::create_dir_all("sample_dir")?;
    fs::create_dir_all("sample_dir/nested_dir")?;
    
    // Create sample files
    fs::write("file1.txt", "This is the content of file1.")?;
    fs::write("file2.txt", "This is the content of file2.")?;
    fs::write("sample_dir/file3.txt", "This is the content of file3 in sample_dir.")?;
    fs::write("sample_dir/nested_dir/file4.txt", "This is the content of file4 in nested_dir.")?;
    
    // Specify the output ZIP file path
    let output_zip = "archive_with_dirs.zip";
    
    // Create a new ZipManager instance
    let mut manager = ZipManager::new(output_zip);
    
    // Add individual files to the zip
    manager.add_file("file1.txt");
    manager.add_file("file2.txt");
    
    // Add directories to the zip
    manager.add_directory("sample_dir");
    
    // Create the ZIP archive with Deflated compression
    manager.create_zip(Compression::Deflated)?;
    
    println!("ZIP archive created at {}", output_zip);
    
    // Cleanup sample files and directories
    fs::remove_file("file1.txt")?;
    fs::remove_file("file2.txt")?;
    fs::remove_dir_all("sample_dir")?;
    
    Ok(())
}
Example 2: Zipping Multiple Files Only

Here's how to zip multiple individual files into a single ZIP archive.

use crypt_guard::zip_manager::*;
use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Setting up sample files
    fs::write("file1.txt", "Content of file1")?;
    fs::write("file2.txt", "Content of file2")?;
    fs::write("file3.txt", "Content of file3")?;
    
    // Specify the output ZIP file path
    let output_zip = "archive_with_files.zip";
    
    // Create a new ZipManager instance
    let mut manager = ZipManager::new(output_zip);
    
    // Add files to zip
    manager.add_file("file1.txt");
    manager.add_file("file2.txt");
    manager.add_file("file3.txt");
    
    // Create the ZIP archive with Deflated compression
    manager.create_zip(Compression::Deflated)?;
    
    println!("ZIP archive created at {}", output_zip);
    
    // Cleanup sample files
    fs::remove_file("file1.txt")?;
    fs::remove_file("file2.txt")?;
    fs::remove_file("file3.txt")?;
    
    Ok(())
}
Compression Methods

The ZipManager allows you to choose from different compression methods depending on your needs. The available options are:

  • Compression::stored(): No compression is applied. Use this option for faster archiving when compression is unnecessary.
  • Compression::deflated(): Standard ZIP compression. Offers a good balance between compression ratio and speed.
  • Compression::zip2(): Uses Bzip2 compression. Provides higher compression ratios but may be slower.
  • Compression::zstd(): Uses Zstandard compression. Offers high compression ratios and speed. Note that to use Zstandard compression, you need to enable the zstd feature in the zip crate.

Full Changelog: V1.3.0...V1.3.9

V1.3.0

23 Jul 18:27
55dfedd
Compare
Choose a tag to compare

New Version: V1.3.0

New Features:

Implementation of AEAD: AES_GCM_SIV. Planned implementation of CTR, CBC and XTS for device encryption!

Full Changelog: V1.2.16...V1.3.0

V1.2.16

23 Jul 18:20
c2126be
Compare
Choose a tag to compare

Full Changelog: V1.2.11...V1.2.16

V1.2.14 - Macros now Integrating a new safety approach

08 Jul 14:31
37127fc
Compare
Choose a tag to compare

V1.2.14

new safety by zeroing out used püroperties!

Full Changelog: V1.2.13Release...V1.2.14Release

V1.2.13 Release

25 Jun 19:11
243514f
Compare
Choose a tag to compare

V1.2.11

17 Jun 13:59
d888dd3
Compare
Choose a tag to compare

Full Changelog: V1.2.9...V1.2.11

V1.2.9

02 May 17:59
d9c0c40
Compare
Choose a tag to compare

What's Changed

Full Changelog: V1.2.3...V1.2.9

V1.2.3

15 Apr 12:41
105b71f
Compare
Choose a tag to compare

Full Changelog: V1.2.2...V1.2.3

V1.2.2

13 Apr 09:10
332d170
Compare
Choose a tag to compare

Full Changelog: V1.2.0...V1.2.2