ferric_crypto_lib 0.2.7

A library for Ferric Crypto
Documentation
use crate::crypto_systems::rsa::RSA;
use crate::error::RSAError;
use crate::prelude::*;
use crate::Traits::{BruteForce, Decrypt};

use std::collections::HashMap;

// TODO: update the key type for the RSA cipher
type RSAResultMap = HashMap<usize, String>;

impl BruteForce<RSAResultMap, RSAError, RSAResultMap, Option<usize>> for RSA {
    /// The `brute_force` function attempts to decrypt a given input string by trying all possible keys of the RSA cipher.
    /// It takes two arguments: the input string to be decrypted and an optional clear text string.
    /// If the clear text string is provided, the function will return as soon as it finds a match.
    /// If no clear text string is provided, the function will return all possible decrypted strings.
    ///
    /// # Arguments
    ///
    /// * `input` - A string that holds the text to be decrypted.
    /// * `clear_text` - An optional string that, if provided, the function will stop and return as soon as it finds a match.
    ///
    /// # Returns
    ///
    /// * `Result<RSAResultMap, RSAError>` - A Result type that holds either a HashMap of all possible decrypted strings (with the key used for decryption as the key in the map), or a RSAError.
    ///
    /// # Errors
    ///
    /// This function will return an error if:
    /// * The clear text string is provided and its length does not match the length of the input string.
    /// * The decryption process fails.
    fn brute_force(
        &mut self,
        input: String,
        clear_text: Option<String>,
        key_info: Option<usize>,
    ) -> Result<RSAResultMap, RSAError> {
        unimplemented!("This function is not yet implemented.")
    }

    /// The `gen_permutations` function generates a HashMap of all possible keys for the RSA cipher.
    /// The keys in the map are the keys used for decryption, and the values are empty strings that will hold the decrypted strings.
    ///
    /// # Returns
    ///
    /// * `Result<RSAResultMap, RSAError>` - A Result type that holds either a HashMap of all possible keys for the RSA cipher, or a RSAError.
    fn gen_permutations(&mut self, key_info: Option<usize>) -> Result<RSAResultMap, RSAError> {
        unimplemented!("This function is not yet implemented.")
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashMap;

    // TODO: Add tests for the RSA brute force implementation
}