feat(cipher-factory,cli): add CBC mode support to CipherContext and CLI

Update CipherContext:
    - Add optional iv field for CBC mode
    - Add process_cbc() for CBC-specific handling
    - Add parse_hex() helper for decryption input
    - Separate ECB and CBC processing paths

Update CLI:
    - Add --iv argument for initialization vector
    - Pass IV through to CipherContext
This commit is contained in:
2025-12-31 01:08:40 +02:00
parent 6c5cd9b78a
commit 1ffc0327b3
2 changed files with 74 additions and 9 deletions

View File

@@ -12,11 +12,15 @@ pub struct Args {
#[arg(short, long)]
pub algorithm: Algorithm,
/// Key used for encryption/decryption. Can be a string or a path to a file
/// Key used for encryption/decryption (hex string, e.g., 0x2b7e...)
#[arg(short, long, required = true)]
pub key: String,
/// The text to encrypt/decrypt. Can be a string or a path to a file
/// Initialization vector for CBC mode (hex string, e.g., 0x0001...)
#[arg(long)]
pub iv: Option<String>,
/// The text to encrypt/decrypt
#[arg(value_name = "TEXT", required = true)]
pub text: String,
@@ -31,6 +35,7 @@ impl From<Args> for CipherContext {
algorithm: args.algorithm,
operation: args.operation,
key: args.key,
iv: args.iv,
input_text: args.text,
output_format: args.output_format.unwrap_or_default(),
}