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 Base32HexContext {
atom_class: AtomClass,
atom_type: AtomType,
is_capitalized: bool,
}
impl Base32HexContext {
fn get_lowercase_decode_alphabet() -> HashMap<u8, u64> {
map![
(0x30, 0), (0x31, 1), (0x32, 2), (0x33, 3),
(0x34, 4), (0x35, 5), (0x36, 6), (0x37, 7),
(0x38, 8), (0x39, 9), (0x61, 10), (0x62, 11),
(0x63, 12), (0x64, 13), (0x65, 14), (0x66, 15),
(0x67, 16), (0x68, 17), (0x69, 18), (0x6a, 19),
(0x6b, 20), (0x6c, 21), (0x6d, 22), (0x6e, 23),
(0x6f, 24), (0x70, 25), (0x71, 26), (0x72, 27),
(0x73, 28), (0x74, 29), (0x75, 30), (0x76, 31),
(0x3d, 32)
]
}
fn get_uppercase_decode_alphabet() -> HashMap<u8, u64> {
map![
(0x30, 0), (0x31, 1), (0x32, 2), (0x33, 3),
(0x34, 4), (0x35, 5), (0x36, 6), (0x37, 7),
(0x38, 8), (0x39, 9), (0x41, 10), (0x42, 11),
(0x43, 12), (0x44, 13), (0x45, 14), (0x46, 15),
(0x47, 16), (0x48, 17), (0x49, 18), (0x4a, 19),
(0x4b, 20), (0x4c, 21), (0x4d, 22), (0x4e, 23),
(0x4f, 24), (0x50, 25), (0x51, 26), (0x52, 27),
(0x53, 28), (0x54, 29), (0x55, 30), (0x56, 31),
(0x3d, 32)
]
}
fn get_uppercase_encode_alphabet() -> [u8; 33] {
[
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x3d
]
}
fn get_lowercase_encode_alphabet() -> [u8; 33] {
[
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
0x3d
]
}
pub fn new() -> Base32HexContext {
Base32HexContext {
atom_class: AtomClass::Code,
atom_type: AtomType::Base32Hex,
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 Base32hex ciphertext validation!".to_string(),
(ciphertext.len() % 8) as u8, 8,
));
}
let alphabet = if self.is_capitalized {
Base32HexContext::get_uppercase_decode_alphabet()
} else {
Base32HexContext::get_lowercase_decode_alphabet()
};
let padding_byte = Base32HexContext::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 Base32hex 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 Base32hex 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 Base32hex ciphertext validation!".to_string(),
ciphertext.clone(),
))
}
}
}
impl CaseInsensitiveCiphertext for Base32HexContext {
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 Base32HexContext {}
impl CryptographicAtom for Base32HexContext {
fn get_atom_class(&self) -> AtomClass { self.atom_class }
fn get_atom_type(&self) -> AtomType { self.atom_type }
}
impl Decode for Base32HexContext {
fn decode(
&mut self,
ciphertext: &Vec<u8>,
) -> Result<Vec<u8>, CryptoError> {
let mono_case_text = text_to_mono_case(ciphertext, self.is_capitalized);
if let Err(error) = self.validate_ciphertext(&mono_case_text) {
Err(error)
} else {
Ok(base32_decode(&mono_case_text, if self.is_capitalized {
Base32HexContext::get_uppercase_decode_alphabet()
} else {
Base32HexContext::get_lowercase_decode_alphabet()
}))
}
}
}
impl Encode for Base32HexContext {
fn encode(
&mut self,
plaintext: &Vec<u8>,
) -> Result<Vec<u8>, CryptoError> {
Ok(base32_encode(plaintext, if self.is_capitalized {
Base32HexContext::get_uppercase_encode_alphabet()
} else {
Base32HexContext::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 = Base32HexContext::new();
assert_eq![ctx.get_atom_class(), AtomClass::Code];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_02() {
let ctx = Base32HexContext::new();
assert_eq![ctx.get_atom_type(), AtomType::Base32Hex];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_03() {
let ctx = Base32HexContext::new();
assert_eq![ctx.ciphertext_is_capitalized(), Some(true)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_04() {
let mut ctx = Base32HexContext::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 = Base32HexContext::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 = Base32HexContext::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 = Base32HexContext::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![
0x43, 0x4f, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0x66];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_09() {
let ciphertext = vec![
0x63, 0x70, 0x6e, 0x67,
0x3d, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0x66, 0x6f];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = false;
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_10() {
let ciphertext = vec![
0x43, 0x50, 0x4e, 0x4d,
0x55, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0x66, 0x6f, 0x6f];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_11() {
let ciphertext = vec![
0x43, 0x70, 0x6e, 0x4d,
0x75, 0x6f, 0x47, 0x3d,
];
let expected_plaintext = vec![0x66, 0x6f, 0x6f, 0x62];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_12() {
let ciphertext = vec![
0x63, 0x70, 0x6e, 0x6d,
0x75, 0x6f, 0x6a, 0x31,
];
let expected_plaintext = vec![0x66, 0x6f, 0x6f, 0x62, 0x61];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_13() {
let ciphertext = vec![
0x63, 0x50, 0x4e, 0x4d,
0x75, 0x4f, 0x4a, 0x31,
0x45, 0x38, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = false;
let plaintext = ctx.decode(&ciphertext);
assert_eq![plaintext, Ok(expected_plaintext)];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_14() {
let ciphertext = vec![
0x73, 0x65, 0x30, 0x52,
0x56, 0x4f, 0x73, 0x31,
0x6e, 0x4f, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let expected_plaintext = vec![0xe3, 0x81, 0xbf, 0xe3, 0x81, 0xbe];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = false;
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 = Base32HexContext::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![
0x43, 0x4f, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::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_17() {
let plaintext = vec![0x66, 0x6f];
let expected_ciphertext = vec![
0x63, 0x70, 0x6e, 0x67,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::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![
0x43, 0x50, 0x4e, 0x4d,
0x55, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::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![
0x63, 0x70, 0x6e, 0x6d,
0x75, 0x6f, 0x67, 0x3d,
];
let mut ctx = Base32HexContext::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![
0x43, 0x50, 0x4e, 0x4d,
0x55, 0x4f, 0x4a, 0x31,
];
let mut ctx = Base32HexContext::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![
0x43, 0x50, 0x4e, 0x4d,
0x55, 0x4f, 0x4a, 0x31,
0x45, 0x38, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::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![
0x73, 0x65, 0x30, 0x72,
0x76, 0x6f, 0x73, 0x31,
0x6e, 0x6f, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::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 = 0x2f;
for v in 0..=9 {
k += 1;
decode_alphabet.insert(k, v);
}
k = 0x60;
for v in 10..=31 {
k += 1;
decode_alphabet.insert(k, v);
}
decode_alphabet.insert(0x3d, 32);
assert_eq![Base32HexContext::get_lowercase_decode_alphabet().len(), decode_alphabet.len()];
assert_eq![Base32HexContext::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 = 0x2f;
for v in 0..=9 {
k += 1;
decode_alphabet.insert(k, v);
}
k = 0x40;
for v in 10..=31 {
k += 1;
decode_alphabet.insert(k, v);
}
decode_alphabet.insert(0x3d, 32);
assert_eq![Base32HexContext::get_uppercase_decode_alphabet().len(), decode_alphabet.len()];
assert_eq![Base32HexContext::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 0x30..=0x39 {
encode_alphabet[k] = v;
k += 1;
}
for v in 0x41..=0x56 {
encode_alphabet[k] = v;
k += 1;
}
encode_alphabet[k] = 0x3d;
assert_eq![Base32HexContext::get_uppercase_encode_alphabet().len(), encode_alphabet.len()];
assert_eq![Base32HexContext::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 0x30..=0x39 {
encode_alphabet[k] = v;
k += 1;
}
for v in 0x61..=0x76 {
encode_alphabet[k] = v;
k += 1;
}
encode_alphabet[k] = 0x3d;
assert_eq![Base32HexContext::get_lowercase_encode_alphabet().len(), encode_alphabet.len()];
assert_eq![Base32HexContext::get_lowercase_encode_alphabet(), encode_alphabet];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_27() {
let ciphertext = vec![];
let ctx = Base32HexContext::new();
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_28() {
let ciphertext = vec![
0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x37,
];
let ctx = Base32HexContext::new();
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_29() {
let ciphertext = vec![
0x38, 0x39, 0x61, 0x62,
0x63, 0x64, 0x65, 0x3d,
];
let mut ctx = Base32HexContext::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![
0x47, 0x48, 0x49, 0x4a,
0x4b, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_31() {
let ciphertext = vec![
0x6f, 0x70, 0x71, 0x72,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_32() {
let ciphertext = vec![
0x53, 0x54, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Ok(())];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_33() {
let ciphertext = vec![
0x30, 0x31, 0x32, 0x33,
];
let ctx = Base32HexContext::new();
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalResidueClass(
"Failure during Base32hex ciphertext validation!".to_string(), 4, 8,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_34() {
let ciphertext = vec![
0x34, 0x35, 0x36, 0x37,
0xff, 0x38, 0x39, 0x41,
0x42, 0x43, 0x44, 0x45,
0x46, 0x47, 0x48, 0x49,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalCharacter(
"Failure during Base32hex ciphertext validation!".to_string(), 4,
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_35() {
let ciphertext = vec![
0x4a, 0x50, 0x51, 0x52,
0x53, 0x54, 0x55, 0x56,
0x3d, 0x3d, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalCharacter(
"Failure during Base32hex ciphertext validation!".to_string(), 8,
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_36() {
let mut ciphertext = vec![
0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x00,
];
let ctx = Base32HexContext::new();
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::IllegalCharacter(
"Failure during Base32hex 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 Base32hex ciphertext validation!".to_string(), i - 1,
ciphertext.clone(),
))];
}
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_37() {
let ciphertext = vec![
0x38, 0x39, 0x61, 0x3d,
0x3d, 0x3d, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32hex ciphertext validation!".to_string(),
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_38() {
let ciphertext = vec![
0x43, 0x44, 0x45, 0x46,
0x47, 0x48, 0x3d, 0x3d,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32hex ciphertext validation!".to_string(),
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_39() {
let ciphertext = vec![
0x6b, 0x6c, 0x3d, 0x6e,
0x6f, 0x70, 0x71, 0x3d,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32hex ciphertext validation!".to_string(),
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_40() {
let ciphertext = vec![
0x53, 0x54, 0x3d, 0x3d,
0x30, 0x31, 0x3d, 0x33,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32hex ciphertext validation!".to_string(),
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_41() {
let ciphertext = vec![
0x34, 0x35, 0x3d, 0x3d,
0x3d, 0x3d, 0x3d, 0x62,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = false;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32hex ciphertext validation!".to_string(),
ciphertext,
))];
}
#[cfg_attr(not(feature = "doc_tests"), test)]
fn test_42() {
let ciphertext = vec![
0x43, 0x44, 0x45, 0x46,
0x47, 0x3d, 0x48, 0x49,
];
let mut ctx = Base32HexContext::new();
ctx.is_capitalized = true;
assert_eq![ctx.validate_ciphertext(&ciphertext), Err(CryptoError::MalformedPadding(
"Failure during Base32hex ciphertext validation!".to_string(),
ciphertext,
))];
}
}