#[cfg(any(
feature = "ui",
feature = "cipher",
feature = "code",
feature = "digest"
))]
pub mod action;
#[cfg(feature = "cipher")]
pub mod cipher;
#[cfg(feature = "ui")]
pub mod ui;
#[cfg(feature = "code")]
pub mod code;
#[cfg(feature = "digest")]
pub mod digest;
#[cfg(feature = "cryptanalysis")]
pub mod cryptanalysis;
mod util;
use core::fmt;
#[macro_export]
macro_rules! map {
( $( $x:expr ),* ) => {
{
let mut temp_map = HashMap::new();
$(
temp_map.insert($x.0, $x.1);
)*
temp_map
}
};
}
pub trait CaseInsensitiveCiphertext {
fn ciphertext_is_capitalized(
&self
) -> Option<bool>;
fn set_ciphertext_capitalization(
&mut self,
capitalized: bool,
);
}
pub trait CryptographicAtom: CaseInsensitiveCiphertext {
fn get_atom_class(
&self
) -> AtomClass;
fn get_atom_type(
&self
) -> AtomType;
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum AtomClass {
#[cfg(feature = "cipher")]
Cipher,
#[cfg(feature = "code")]
Code,
#[cfg(feature = "digest")]
Digest,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum AtomType {
#[cfg(any(feature = "base16", feature = "hex"))]
Base16,
#[cfg(feature = "base32")]
Base32,
#[cfg(feature = "base32hex")]
Base32Hex,
#[cfg(feature = "base64")]
Base64,
#[cfg(feature = "base64url")]
Base64Url,
#[cfg(feature = "caesar")]
Caesar,
#[cfg(feature = "vigenere")]
Vigenere,
}
impl fmt::Display for AtomType {
fn fmt(
&self,
f: &mut fmt::Formatter<'_>
) -> fmt::Result {
match self {
#[cfg(any(
feature = "base16",
feature = "hex"
))]
AtomType::Base16 => { write![f, "Base16" ] }
#[cfg(feature = "base32")]
AtomType::Base32 => { write![f, "Base32" ] }
#[cfg(feature = "base32hex")]
AtomType::Base32Hex => { write![f, "Base32Hex" ]}
#[cfg(feature = "base64")]
AtomType::Base64 => { write![f, "Base64"] }
#[cfg(feature = "base64url")]
AtomType::Base64Url => { write![f, "Base64Url"] }
#[cfg(feature = "caesar")]
AtomType::Caesar => { write![f, "Caesar"] }
#[cfg(feature = "sha256")]
AtomType::Sha256 => { write![f, "Sha256"] }
#[cfg(feature = "vigenere")]
AtomType::Vigenere => { write![f, "Vigenere"] }
}
}
}
#[derive(Debug, PartialEq)]
pub enum CryptoError {
IllegalCharacter(String, usize, Vec<u8>),
#[cfg(any(
feature = "base16",
feature = "base32",
feature = "base32hex",
feature = "base64",
feature = "base64url",
feature = "hex"
))]
IllegalResidueClass(String, u8, u8),
#[cfg(feature = "cipher")]
InvalidKey(String, Vec<u8>),
#[cfg(any(
feature = "base32",
feature = "base32hex",
feature = "base64",
feature = "base64url"
))]
MalformedPadding(String, Vec<u8>),
#[cfg(feature = "cipher")]
MissingKey(String),
}
impl fmt::Display for CryptoError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Err(error) = write![f, ">>> Runtime Error:\n"] {
return Err(error);
}
match self {
CryptoError::IllegalCharacter(description, index, origin) => {
write![f, "... Class: Illegal Character\n\
... Description: {}\n\
... Origin: {:#?}\n\
... Index: {}\n",
description, origin, index]
}
#[cfg(any(
feature = "base16",
feature = "base32",
feature = "base32hex",
feature = "base64",
feature = "base64url",
feature = "hex"
))]
CryptoError::IllegalResidueClass(description, a, m) => {
write![f, "... Class: Illegal Residue Class\n\
... Description: {}\n\
... Residue Class: {} + {}ℤ\n",
description, a, m]
}
#[cfg(feature = "cipher")]
CryptoError::InvalidKey(description, key) => {
write![f, "... Class: Invalid Key\n\
... Description: {}\n\
... Invalid Key: {:#?}\n",
description, key]
}
#[cfg(any(feature = "base32", feature = "base32hex", feature = "base64",
feature = "base64url"))]
CryptoError::MalformedPadding(description, origin) => {
write![f, "... Class: Malformed Padding\n\
... Description: {}\n\
... Origin: {:#?}\n",
description, origin]
}
#[cfg(feature = "cipher")]
CryptoError::MissingKey(description) => {
write![f, "... Class: Missing Key\n\
... Description: {}\n",
description]
}
}
}
}