use base64::engine::{general_purpose::STANDARD, Engine}; use base64::*;
use base64::engine::general_purpose::{GeneralPurpose, NO_PAD};
// generate random contents of the specified length and test encode/decode roundtrip fn roundtrip_random<E: Engine>(
byte_buf: &mut Vec<u8>,
str_buf: &mut String,
engine: &E,
byte_len: usize,
approx_values_per_byte: u8,
max_rounds: u64,
) { // let the short ones be short but don't let it get too crazy large let num_rounds = calculate_number_of_rounds(byte_len, approx_values_per_byte, max_rounds); letmut r = rand::rngs::SmallRng::from_entropy(); letmut decode_buf = Vec::new();
for _ in0..num_rounds {
byte_buf.clear();
str_buf.clear();
decode_buf.clear(); while byte_buf.len() < byte_len {
byte_buf.push(r.gen::<u8>());
}
#[test] fn roundtrip_decode_trailing_10_bytes() { // This is a special case because we decode 8 byte blocks of input at a time as much as we can, // ideally unrolled to 32 bytes at a time, in stages 1 and 2. Since we also write a u64's worth // of bytes (8) to the output, we always write 2 garbage bytes that then will be overwritten by // the NEXT block. However, if the next block only contains 2 bytes, it will decode to 1 byte, // and therefore be too short to cover up the trailing 2 garbage bytes. Thus, we have stage 3 // to handle that case.
for num_quads in0..25 { letmut s: String = "ABCD".repeat(num_quads);
s.push_str("EFGHIJKLZg");
let engine = GeneralPurpose::new(&alphabet::STANDARD, NO_PAD); let decoded = engine.decode(&s).unwrap();
assert_eq!(num_quads * 3 + 7, decoded.len());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.