use std::collections::hash_map::HashMap;
use crate::{
AtomClass,
AtomType,
CaseInsensitiveCiphertext,
code::{
Code,
Decode,
Encode,
},
CryptoError,
CryptographicAtom,
map,
util::text_to_mono_case,
};
use super::{
base32_decode,
base32_encode,
FOUR_PADDING_BYTE_BIT_STRING,
ONE_PADDING_BYTE_BIT_STRING,
SIX_PADDING_BYTE_BIT_STRING,
THREE_PADDING_BYTE_BIT_STRING,
ZERO_PADDING_BYTES_BIT_STRING,
};
#[derive(Clone, Copy)]
pub struct Base32Context {
atom_class: AtomClass,
atom_type: AtomType,
is_capitalized: bool,
}
impl Base32Context {
fn get_lowercase_decode_alphabet() -> HashMap<u8, u64> {
map![
(0x61, 0), (0x62, 1), (0x63, 2), (0x64, 3),
(0x65, 4), (0x66, 5), (0x67, 6), (0x68, 7),
(0x69, 8), (0x6a, 9), (0x6b, 10), (0x6c, 11),
(0x6d, 12), (0x6e, 13), (0x6f, 14), (0x70, 15),
(0x71, 16), (0x72, 17), (0x73, 18), (0x74, 19),
(0x75, 20), (0x76, 21), (0x77, 22), (0x78, 23),
(0x79, 24), (0x7a, 25), (0x32, 26), (0x33, 27),
(0x34, 28), (0x35, 29), (0x36, 30), (0x37, 31),
(0x3d, 32)
]
}
fn get_uppercase_decode_alphabet() -> HashMap<u8, u64> {
map![
(0x41, 0), (0x42, 1), (0x43, 2), (0x44, 3),
(0x45, 4), (0x46, 5), (0x47, 6), (0x48, 7),
(0x49, 8), (0x4a, 9), (0x4b, 10), (0x4c, 11),
(0x4d, 12), (0x4e, 13), (0x4f, 14), (0x50, 15),
(0x51, 16), (0x52, 17), (0x53, 18), (0x54, 19),
(0x55, 20), (0x56, 21), (0x57, 22), (0x58, 23),
(0x59, 24), (0x5a, 25), (0x32, 26), (0x33, 27),
(0x34, 28), (0x35, 29), (0x36, 30), (0x37, 31),
(0x3d, 32)
]
}
fn get_uppercase_encode_alphabet() -> [u8; 33] {
[
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
0x59, 0x5a, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x3d
]
}
fn get_lowercase_encode_alphabet() -> [u8; 33] {
[
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
0x79, 0x7a, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x3d
]
}
pub fn new() -> Base32Context {
Base32Context {
atom_class: AtomClass::Code,
atom_type: AtomType::Base32,
is_capitalized: true,
}
}
fn validate_ciphertext(
&self,
ciphertext: &Vec<u8>,
) -> Result<(), CryptoError> {
if ciphertext.is_empty() {
return Ok(());
}
if ciphertext.len() % 8 != 0 {
return Err(CryptoError::IllegalResidueClass(
"Failure during Base32 ciphertext validation!".to_string(),
(ciphertext.len() % 8) as u8, 8,
));
}
let alphabet = if self.is_capitalized {
Base32Context::get_uppercase_decode_alphabet()
} else {
Base32Context::get_lowercase_decode_alphabet()
};
let padding_byte = Base32Context::get_uppercase_encode_alphabet()[32];
let mut i = 0;
for c in &ciphertext[..ciphertext.len() - 6] {
if !alphabet.contains_key(c) || *c == padding_byte {
return Err(CryptoError::IllegalCharacter(
"Failure during Base32 ciphertext validation!".to_string(), i,
ciphertext.clone(),
));
}
i += 1;
}
let mut last_six_bytes_bit_string = 0;
for c in &ciphertext[ciphertext.len() - 6..] {
if !alphabet.contains_key(c) {
return Err(CryptoError::IllegalCharacter(
"Failure during Base32 ciphertext validation!".to_string(),
i, ciphertext.clone(),
));
}
i += 1;
if *c == padding_byte {
last_six_bytes_bit_string |= (*c as u64) << 8 * (ciphertext.len() - i);
}
}
if last_six_bytes_bit_string ^ ZERO_PADDING_BYTES_BIT_STRING == 0x0
|| last_six_bytes_bit_string ^ ONE_PADDING_BYTE_BIT_STRING == 0x0
|| last_six_bytes_bit_string ^ THREE_PADDING_BYTE_BIT_STRING == 0x0
|| last_six_bytes_bit_string ^ FOUR_PADDING_BYTE_BIT_STRING == 0x0
|| last_six_bytes_bit_string ^ SIX_PADDING_BYTE_BIT_STRING == 0x0 {
Ok(())
} else {
Err(CryptoError::MalformedPadding(
"Failure during Base32 ciphertext validation!".to_string(),
ciphertext.clone(),
))
}
}
}
impl CaseInsensitiveCiphertext for Base32Context {
fn ciphertext_is_capitalized(&self) -> Option<bool> { Some(self.is_capitalized) }
fn set_ciphertext_capitalization(
&mut self,
capitalized: bool,
) {
self.is_capitalized = capitalized;
}
}
impl Code for Base32Context {}
impl CryptographicAtom for Base32Context {
fn get_atom_class(&self) -> AtomClass { self.atom_class }
fn get_atom_type(&self) -> AtomType { self.atom_type }
}
impl Decode for Base32Context {
fn decode(
&mut self,
ciphertext: &Vec<u8>,
) -> Result<Vec<u8>, CryptoError> {
let mono_case_ciphertext = text_to_mono_case(
ciphertext, self.is_capitalized,
);
if let Err(error) = self.validate_ciphertext(&mono_case_ciphertext) {
Err(error)
} else {
Ok(base32_decode(&mono_case_ciphertext, if self.is_capitalized {
Base32Context::get_uppercase_decode_alphabet()
} else {
Base32Context::get_lowercase_decode_alphabet()
}))
}
}
}
impl Encode for Base32Context {
fn encode(
&mut self,
plaintext: &Vec<u8>,
) -> Result<Vec<u8>, CryptoError> {
if self.is_capitalized {
Ok(base32_encode(plaintext, Base32Context::get_uppercase_encode_alphabet()))
} else {
Ok(base32_encode(plaintext, Base32Context::get_lowercase_encode_alphabet()))
}
}
}
#[cfg(any(feature = "doc_tests", test))]
mod tests {
use super::*;
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_01() {
let ctx = Base32Context::new();
assert_eq![ctx.get_atom_class(), AtomClass::Code];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_02() {
let ctx = Base32Context::new();
assert_eq![ctx.get_atom_type(), AtomType::Base32];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_03() {
let ctx = Base32Context::new();
assert_eq![ctx.ciphertext_is_capitalized(), Some(true)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_04() {
let mut ctx = Base32Context::new();
ctx.set_ciphertext_capitalization(true);
assert_eq![ctx.ciphertext_is_capitalized(), Some(true)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_05() {
let mut ctx = Base32Context::new();
ctx.set_ciphertext_capitalization(false);
ctx.set_ciphertext_capitalization(true);
assert_eq![ctx.ciphertext_is_capitalized(), Some(true)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_06() {
let mut ctx = Base32Context::new();
ctx.set_ciphertext_capitalization(false);
assert_eq![ctx.ciphertext_is_capitalized(), Some(false)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_07() {
let ciphertext = vec![];
let expected_plaintext = vec![];
let mut ctx = Base32Context::new();
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_08() {
let ciphertext = vec![
0x4d, 0x59, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0x66];
let mut ctx = Base32Context::new();
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_09() {
let ciphertext = vec![
0x6d, 0x7a, 0x78, 0x71,
0x3d, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0x66, 0x6f];
let mut ctx = Base32Context::new();
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_10() {
let ciphertext = vec![
0x4d, 0x5a, 0x58, 0x57,
0x36, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0x66, 0x6f, 0x6f];
let mut ctx = Base32Context::new();
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_11() {
let ciphertext = vec![
0x4d, 0x7a, 0x78, 0x57,
0x36, 0x79, 0x51, 0x3d,
];
let expected_plaintext = vec![0x66, 0x6f, 0x6f, 0x62];
let mut ctx = Base32Context::new();
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_12() {
let ciphertext = vec![
0x6d, 0x7a, 0x78, 0x77,
0x36, 0x79, 0x74, 0x62,
];
let expected_plaintext = vec![0x66, 0x6f, 0x6f, 0x62, 0x61];
let mut ctx = Base32Context::new();
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_13() {
let ciphertext = vec![
0x6d, 0x5a, 0x58, 0x77,
0x36, 0x59, 0x54, 0x62,
0x6f, 0x69, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72];
let mut ctx = Base32Context::new();
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_14() {
let ciphertext = vec![
0x34, 0x6f, 0x61, 0x33,
0x37, 0x59, 0x34, 0x62,
0x58, 0x79, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0xe3, 0x81, 0xbf, 0xe3, 0x81, 0xbe];
let mut ctx = Base32Context::new();
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_15() {
let plaintext = vec![];
let expected_ciphertext = vec![];
let mut ctx = Base32Context::new();
let ciphertext = ctx.encode(&plaintext);
assert_eq![ciphertext, Ok(expected_ciphertext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_16() {
let plaintext = vec![0x66];
let expected_ciphertext = vec![
0x4d, 0x59, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
let ciphertext = ctx.encode(&plaintext);
assert_eq![ciphertext, Ok(expected_ciphertext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_17() {
let plaintext = vec![0x66, 0x6f];
let expected_ciphertext = vec![
0x6d, 0x7a, 0x78, 0x71,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
let ciphertext = ctx.encode(&plaintext);
assert_eq![ciphertext, Ok(expected_ciphertext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_18() {
let plaintext = vec![0x66, 0x6f, 0x6f];
let expected_ciphertext = vec![
0x4d, 0x5a, 0x58, 0x57,
0x36, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
let ciphertext = ctx.encode(&plaintext);
assert_eq![ciphertext, Ok(expected_ciphertext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_19() {
let plaintext = vec![0x66, 0x6f, 0x6f, 0x62];
let expected_ciphertext = vec![
0x6d, 0x7a, 0x78, 0x77,
0x36, 0x79, 0x71, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
let ciphertext = ctx.encode(&plaintext);
assert_eq![ciphertext, Ok(expected_ciphertext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_20() {
let plaintext = vec![0x66, 0x6f, 0x6f, 0x62, 0x61];
let expected_ciphertext = vec![
0x4d, 0x5a, 0x58, 0x57,
0x36, 0x59, 0x54, 0x42,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
let ciphertext = ctx.encode(&plaintext);
assert_eq![ciphertext, Ok(expected_ciphertext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_21() {
let plaintext = vec![0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72];
let expected_ciphertext = vec![
0x4d, 0x5a, 0x58, 0x57,
0x36, 0x59, 0x54, 0x42,
0x4f, 0x49, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
let ciphertext = ctx.encode(&plaintext);
assert_eq![ciphertext, Ok(expected_ciphertext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_22() {
let plaintext = vec![0xe3, 0x81, 0xbf, 0xe3, 0x81, 0xbe];
let expected_ciphertext = vec![
0x34, 0x6f, 0x61, 0x33,
0x37, 0x79, 0x34, 0x62,
0x78, 0x79, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
let ciphertext = ctx.encode(&plaintext);
assert_eq![ciphertext, Ok(expected_ciphertext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_23() {
let mut decode_alphabet: HashMap<u8, u64> = HashMap::new();
let mut k = 0x60;
for v in 0..=25 {
k += 1;
decode_alphabet.insert(k, v);
}
k = 0x31;
for v in 26..=31 {
k += 1;
decode_alphabet.insert(k, v);
}
decode_alphabet.insert(0x3d, 32);
assert_eq![Base32Context::get_lowercase_decode_alphabet().len(), decode_alphabet.len()];
assert_eq![Base32Context::get_lowercase_decode_alphabet(), decode_alphabet];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_24() {
let mut decode_alphabet: HashMap<u8, u64> = HashMap::new();
let mut k = 0x40;
for v in 0..=25 {
k += 1;
decode_alphabet.insert(k, v);
}
k = 0x31;
for v in 26..=31 {
k += 1;
decode_alphabet.insert(k, v);
}
decode_alphabet.insert(0x3d, 32);
assert_eq![Base32Context::get_uppercase_decode_alphabet().len(), decode_alphabet.len()];
assert_eq![Base32Context::get_uppercase_decode_alphabet(), decode_alphabet];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_25() {
let mut encode_alphabet: [u8; 33] = [0; 33];
let mut k = 0;
for v in 0x41..=0x5a {
encode_alphabet[k] = v;
k += 1;
}
for v in 0x32..=0x37 {
encode_alphabet[k] = v;
k += 1;
}
encode_alphabet[k] = 0x3d;
assert_eq![Base32Context::get_uppercase_encode_alphabet().len(), encode_alphabet.len()];
assert_eq![Base32Context::get_uppercase_encode_alphabet(), encode_alphabet];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_26() {
let mut encode_alphabet: [u8; 33] = [0; 33];
let mut k = 0;
for v in 0x61..=0x7a {
encode_alphabet[k] = v;
k += 1;
}
for v in 0x32..=0x37 {
encode_alphabet[k] = v;
k += 1;
}
encode_alphabet[k] = 0x3d;
assert_eq![Base32Context::get_lowercase_decode_alphabet().len(), encode_alphabet.len()];
assert_eq![Base32Context::get_lowercase_encode_alphabet(), encode_alphabet];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_27() {
let ciphertext = vec![];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_28() {
let ciphertext = vec![
0x41, 0x42, 0x43, 0x44,
0x45, 0x46, 0x47, 0x48,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_29() {
let ciphertext = vec![
0x69, 0x6a, 0x6b, 0x6c,
0x6d, 0x6e, 0x6f, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_30() {
let ciphertext = vec![
0x70, 0x71, 0x72, 0x73,
0x74, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_31() {
let ciphertext = vec![
0x55, 0x56, 0x57, 0x58,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_32() {
let ciphertext = vec![
0x79, 0x7a, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_33() {
let ciphertext = vec![
0x32, 0x33, 0x34, 0x35,
0x36, 0x36, 0x37,
];
let ctx = Base32Context::new();
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalResidueClass(
"Failure during Base32 ciphertext validation!".to_string(), 7, 8,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_34() {
let ciphertext = vec![
0x61, 0x62, 0x63, 0x64,
0xff, 0x46, 0x47, 0x48,
0x49, 0x4a, 0x4b, 0x4c,
0x4d, 0x4e, 0x4f, 0x50,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalCharacter(
"Failure during Base32 ciphertext validation!".to_string(), 4,
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_35() {
let ciphertext = vec![
0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalCharacter(
"Failure during Base32 ciphertext validation!".to_string(),
7, ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_36() {
let mut ciphertext = vec![
0x59, 0x5a, 0x32, 0x33,
0x34, 0x35, 0x36, 0x00,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalCharacter(
"Failure during Base32 ciphertext validation!".to_string(), 7,
ciphertext.clone(),
))];
let mut c = 0x38;
for i in (3..=7).rev() {
c -= 1;
ciphertext[i] = c;
ciphertext[i - 1] = 0x00;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalCharacter(
"Failure during Base32 ciphertext validation!".to_string(), i - 1,
ciphertext.clone(),
))];
}
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_37() {
let ciphertext = vec![
0x41, 0x42, 0x43, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32 ciphertext validation!".to_string(), ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_38() {
let ciphertext = vec![
0x65, 0x66, 0x67, 0x68,
0x69, 0x6a, 0x3d, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32 ciphertext validation!".to_string(), ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_39() {
let ciphertext = vec![
0x69, 0x6a, 0x3d, 0x6c,
0x6d, 0x6e, 0x6f, 0x3d,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32 ciphertext validation!".to_string(), ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_40() {
let ciphertext = vec![
0x6d, 0x6e, 0x3d, 0x3d,
0x71, 0x72, 0x3d, 0x74,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32 ciphertext validation!".to_string(), ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_41() {
let ciphertext = vec![
0x55, 0x56, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x33,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32 ciphertext validation!".to_string(),
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_42() {
let ciphertext = vec![
0x34, 0x35, 0x36, 0x37,
0x61, 0x3d, 0x63, 0x64,
];
let mut ctx = Base32Context::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32 ciphertext validation!".to_string(), ciphertext,
))];
}
}