Struct const_base::errors::WrongInputLength
source · pub struct WrongInputLength { /* private fields */ }
Expand description
When the slice passed to decode
is not a valid length for the passed encoding.
The input lengths that are wrong for each encoding:
- Base 64: when
input.len() % 4
equals1
. - Base 32: when
input.len() % 8
equals1
,3
, or6
. - Base 16: when
input.len() % 2
equals1
.
Example
Base 64
use const_base::{Config, DecodeError, Encoding, WrongInputLength, decode};
const DECODED: Result<[u8; 8], DecodeError> = decode(b"AAAAA", Config::B64);
match DECODED {
Err(DecodeError::WrongInputLength(err)) => {
assert_eq!(err.length(), 5);
assert!(matches!(err.encoding(), Encoding::Base64{..}));
}
_ => unreachable!()
}