kaiser/ciphers/
mod.rs

1use crate::{Buffer, PartialBuffer};
2
3macro_rules! derive_encrypt_decrypt {
4    ($name:ident, $err:ident) => {
5        impl Encrypt for $name {
6            type Error = $err;
7
8            fn encrypt(&self, buf: Buffer) -> Result<Buffer, Self::Error> {
9                self.encrypt_partial(buf.into()).map(|b| b.into())
10            }
11        }
12
13        impl Decrypt for $name {
14            type Error = $err;
15
16            fn decrypt(&self, buf: Buffer) -> Result<Buffer, Self::Error> {
17                self.decrypt_partial(buf.into()).map(|b| b.into())
18            }
19        }
20    };
21}
22
23mod caesar;
24pub use self::caesar::Caesar;
25
26mod affine;
27pub use self::affine::Affine;
28
29mod vigenere;
30pub use self::vigenere::Vigenere;
31
32mod transposition;
33pub use self::transposition::Transposition;
34
35pub trait Encrypt {
36    type Error: std::error::Error;
37
38    fn encrypt(&self, buf: Buffer) -> Result<Buffer, Self::Error>;
39}
40
41pub trait Decrypt {
42    type Error: std::error::Error;
43
44    fn decrypt(&self, buf: Buffer) -> Result<Buffer, Self::Error>;
45}
46
47pub trait PartialEncrypt: Encrypt {
48    fn encrypt_partial(&self, buf: PartialBuffer) -> Result<PartialBuffer, Self::Error>;
49}
50
51pub trait PartialDecrypt: Decrypt {
52    fn decrypt_partial(&self, buf: PartialBuffer) -> Result<PartialBuffer, Self::Error>;
53}