ferric_crypto_lib 0.2.7

A library for Ferric Crypto
Documentation
use crate::utils::{BaseString, EncodedString};

/// Trait for encryption.
///
/// This trait provides a common interface for encryption algorithms.
///
/// # Type Parameters
///
/// * `E` - The type of error that can be returned by the `encrypt` method.
///
/// # Required Methods
///
/// * `encrypt` - Encrypts a string. The exact behavior depends on the implementation.
/// * `encrypt_char` - Encrypts a single character. The exact behavior depends on the implementation.
pub trait Encrypt<E, I, O> {
    /// Encrypts a string.
    ///
    /// # Arguments
    ///
    /// * `input` - The string to be encrypted.
    ///
    /// # Returns
    ///
    /// * A `Result<String, E>` which is `Ok` if the encryption is successful, and `Err` otherwise.
    ///   The `Ok` variant contains the encrypted string, and the `Err` variant contains an error.
    fn encrypt(&self, input: I) -> Result<O, E>;
}

/// Trait for decryption.
///
/// This trait provides a common interface for decryption algorithms.
///
/// # Required Methods
///
/// * `decrypt` - Decrypts a string. The exact behavior depends on the implementation.
/// * `decrypt_char` - Decrypts a single character. The exact behavior depends on the implementation.
/// * `brute_force` - Attempts to decrypt a string by trying all possible keys. The exact behavior depends on the implementation. TODO: Move to a separate cracking specific trait
pub trait Decrypt<E, I, O> {
    /// Decrypts a string.
    ///
    /// # Arguments
    ///
    /// * `input` - The string to be decrypted.
    ///
    /// # Returns
    ///
    /// * A `String` that represents the decrypted string.
    fn decrypt(&self, input: I) -> Result<O, E>;
}

/// Trait for cracking.
///
pub trait BruteForce<R, E, P, K> {
    fn brute_force(
        &mut self,
        input: String,
        clear_text: Option<String>,
        key_info: K,
    ) -> Result<R, E>;
    fn gen_permutations(&mut self, key_info: K) -> Result<P, E>;
}