pub fn encrypt(
path: impl AsRef<Path> + Clone,
size: Option<String>,
out_path: Option<PathBuf>
) -> Result<(), HexCryptError>Expand description
Encrypts the UTF-8 encoded text from the specified file and converts it into an RGB image.
Arguments
path- A reference to a path that points to the file containing the text to be encrypted.size- An optionalStringrepresenting the custom size of the image (e.g., “16x32”).out_path- An optionalPathBufrepresenting the output path for the generated image. IfNone,pathis used insted (with .png extension)
Errors
This function can return a HexCryptError enum that represents different error cases, including I/O errors,
invalid image sizes, and issues related to image creation and processing.
Examples
use std::path::PathBuf;
use hexcrypt::encrypt;
let input_path = PathBuf::from("input.txt");
let output_path = PathBuf::from("output.png");
let size = Some("16x32".to_string());
match encrypt(input_path, size, Some(output_path)) {
Ok(_) => println!("Encryption successful!"),
Err(e) => eprintln!("Error: {:?}", e),
}