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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#[derive(Debug)]
pub struct HideConfig<'a> {
    pub payload_path: &'a str,
    pub carrier_path: &'a str,
    pub output_path: Option<&'a str>,
    pub strategy: Option<&'a str>,
}

#[derive(Debug)]
pub struct RevealConfig<'a> {
    pub carrier_path: &'a str,
    pub output_path: Option<&'a str>,
    pub strategy: Option<&'a str>,
}

mod images;
mod text;
mod videos;

fn hide_default(payload: &str, carrier: &str, _o:&str) {
    panic!("No strategy can be used to hide {} in {}!", payload, carrier);
}

pub fn run_hide(config: HideConfig) {
    let mut hide: fn(&str, &str, &str) = hide_default;
    let mut output_file_name_if_note_specified = "./steg_package.txt";

    if config.payload_path.ends_with(".png") && config.carrier_path.ends_with(".png") {
        println!("Hide using - Least Significant Bit PNG Steganography (lsb_png_steganography)");
        hide = images::lsb_png_steganography::hide;
        output_file_name_if_note_specified = "./steg_package.png";
    } else if config.payload_path.ends_with(".txt") && config.carrier_path.ends_with(".txt") {
        println!("Hide using - whitespace text steganography (whitespace_text_steganography)");
        hide = text::whitespace_text_steganography::hide; 
        output_file_name_if_note_specified = "./steg_package.txt";
    } else if config.payload_path.ends_with(".txt") && config.carrier_path.ends_with(".png") {
        println!("Hide using - Least Significant Bit Text into PNG Steganography (lsb_text_png_steganography)");
        hide = text::lsb_text_png_steganography::hide;
        output_file_name_if_note_specified = "./steg_package.png";
    }

    if let Some(output_path) = config.output_path {
        hide(config.payload_path, config.carrier_path, output_path);
    } else {
        hide(config.payload_path, config.carrier_path, output_file_name_if_note_specified);
    }
}

fn reveal_default(carrier: &str, _o:&str) {
    panic!("No strategy was specified for getting a payload from {}!", carrier);
}

pub fn run_reveal(config: RevealConfig) {
    let mut reveal: fn(&str, &str) = reveal_default;
    let mut output_file_name_if_note_specified = "./hidden_message.txt";

    if config.carrier_path.ends_with(".png") {
        if let Some(strategy) = config.strategy {
            if strategy == "lsb_png_steganography" {
                reveal = images::lsb_png_steganography::reveal;
                output_file_name_if_note_specified = "./hidden_message.png";
            } else if strategy == "lsb_text_png_steganography" {
                reveal = text::lsb_text_png_steganography::reveal;
                output_file_name_if_note_specified = "./hidden_message.txt";
            } else {
                panic!("The strategy {} can't be used for .png files", strategy);
            }
        } else {
            panic!(".png files need a strategy specified to get messages out (e.g. -s lsb_text_png_steganography)");
        }
    } else if config.carrier_path.ends_with(".txt") {
        reveal = text::whitespace_text_steganography::reveal;
        output_file_name_if_note_specified = "./hidden_message.txt";
    }

    if let Some(output_path) = config.output_path {
        reveal(config.carrier_path, output_path);
    } else {
        reveal(config.carrier_path, output_file_name_if_note_specified);
    }
}

#[cfg(test)]
mod tests {
    use super::{HideConfig, RevealConfig};

    #[test]
    fn lsb_png_steganography_hide_does_not_panic() {
        let config = HideConfig {
            strategy: None,
            payload_path: "./images/payload.png",
            carrier_path: "./images/carrier.png",
            output_path: Some("images/output/lsb_png_steganography_hide_does_not_panic.png"),
        };

        super::run_hide(config);
    }

    #[test]
    fn lsb_png_steganography_reveal_does_not_panic() {
        let config = RevealConfig {
            strategy: Some("lsb_png_steganography"),
            carrier_path: "./images/contains_hidden_image.png",
            output_path: Some(
                "./images/output/whitespace_text_steganography_reveal_does_not_panic.png",
            ),
        };

        super::run_reveal(config);
    }

    #[test]
    fn whitespace_text_steganography_hide_does_not_panic() {
        let config = HideConfig {
            strategy: None,
            payload_path: "./texts/payload_haiku.txt",
            carrier_path: "./texts/carrier_sonnet.txt",
            output_path: Some(
                "./texts/output/whitespace_text_steganography_hide_does_not_panic.txt",
            ),
        };

        super::run_hide(config);
    }

    #[test]
    fn whitespace_text_steganography_reveal_does_not_panic() {
        let config = RevealConfig {
            strategy: None,
            carrier_path: "./texts/hidden.txt",
            output_path: Some(
                "./texts/output/whitespace_text_steganography_reveal_does_not_panic.txt",
            ),
        };

        super::run_reveal(config);
    }

     #[test]
    fn lsb_text_png_steganography_hide_does_not_panic() {
        let config = HideConfig {
            strategy: None,
            payload_path: "./texts/payload_haiku.txt",
            carrier_path: "./images/carrier.png",
            output_path: Some(
                "./images/output/lsb_text_png_steganography_hide_does_not_panic.png",
            ),
        };

        super::run_hide(config);
    }

    #[test]
    fn lsb_text_png_steganography_reveal_does_not_panic() {
        let config = RevealConfig {
            strategy: Some("lsb_text_png_steganography"),
            carrier_path: "./images/contains_hidden_text.png",
            output_path: Some(
                "./texts/output/lsb_text_png_steganography_reveal_does_not_panic.txt",
            ),
        };

        super::run_reveal(config);
    }
}