1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub mod encrypt;
pub mod error;
pub mod prelude;
pub struct Methods;

use crate::encrypt::*;
use prelude::*;

impl Methods {
    pub fn get_methods<'a>() -> Vec<&'a str> {
        let methods = vec!["Vigenere", "Base64", "Xor"];

        methods
    }

    pub fn get_method(text: impl Into<String>) -> Result<Box<dyn Method>> {
        let text = text.into();

        if let Ok(v) = text.parse::<Vigenere>() {
            return Ok(Box::new(v));
        }

        if let Ok(b) = text.parse::<Base64>() {
            return Ok(Box::new(b));
        }

        if let Ok(b) = text.parse::<Xor>() {
            return Ok(Box::new(b));
        }

        Err(Error::InvalidMethodError(text))
    }
}

#[cfg(test)]
mod tests;