extern crate data_encoding; // 2.5.0
fn main() {
const LEN: usize = 64;
let mut signature = [0; 64];
let s = data_encoding::BASE64.encode(&signature);
println!("{}", s);
// okay
assert_eq!(data_encoding::BASE64.decode(s.as_bytes()).unwrap().len(), LEN);
// panics
data_encoding::BASE64.decode_mut(s.as_bytes(), &mut signature).unwrap();
// panics
assert_eq!(data_encoding::BASE64.decode_len(s.len()).unwrap(), LEN);
}
It looks like decode_len
doesn't consider the effect of padding on the output length at all, and decode_mut
's prior checking uses the results of decode_len
directly. But such an obvious bug in such a frequently used library makes me doubt myself.