diff --git a/Cargo.toml b/Cargo.toml index 5b7ae83..8728231 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "nettext" description = "A text-based data format for cryptographic network protocols" authors = ["Alex Auvolat "] -version = "0.3.2" +version = "0.3.3" edition = "2021" license = "AGPL-3.0" readme = "README.md" diff --git a/src/switch64.rs b/src/switch64.rs index 8d47629..0c6a4da 100644 --- a/src/switch64.rs +++ b/src/switch64.rs @@ -32,7 +32,10 @@ pub fn encode(bytes: &[u8], allow_whitespace: bool) -> Vec { // We stop at the first position where we find three consecutive // characters to encode as-is let mut b64end = bytes.len(); - for i in pos..bytes.len() - 3 { + for i in pos..bytes.len() { + if i + 3 > bytes.len() { + break; + } if bytes[i..i + 3] .iter() .all(|c| is_valid_plaintext_char(*c, allow_whitespace))