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
use super::{AssociatedData, Bicrypter, CryptError, Decrypter, Encrypter};
#[derive(Clone, Copy)]
pub struct NoopBicrypter;
impl Default for NoopBicrypter {
fn default() -> Self {
Self
}
}
impl Bicrypter for NoopBicrypter {}
impl Encrypter for NoopBicrypter {
fn encrypt(
&self,
buffer: &[u8],
_: &AssociatedData,
) -> Result<Vec<u8>, CryptError> {
Ok(Vec::from(buffer))
}
fn new_encrypt_associated_data(&self) -> AssociatedData {
AssociatedData::None
}
}
impl Decrypter for NoopBicrypter {
fn decrypt(
&self,
buffer: &[u8],
_: &AssociatedData,
) -> Result<Vec<u8>, CryptError> {
Ok(Vec::from(buffer))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn encrypt_should_return_a_copy_of_input_data() {
let bicrypter = NoopBicrypter;
let data = vec![1, 2, 3];
let encrypted_data = bicrypter
.encrypt(&data, &AssociatedData::None)
.expect("Encrypt failed unexpectedly");
assert_eq!(data, encrypted_data);
}
#[test]
fn decrypt_should_return_a_copy_of_input_data() {
let bicrypter = NoopBicrypter;
let data = vec![1, 2, 3];
let decrypted_data = bicrypter
.decrypt(&data, &AssociatedData::None)
.expect("Decrypt failed unexpectedly");
assert_eq!(data, decrypted_data);
}
}