From 74e1ecf3845d43742a64c2ceeef06de08ec77574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Thu, 13 Aug 2020 00:51:56 +0200 Subject: [PATCH] aquatic_http_protocol: remove unused utility function "urldecode" --- aquatic_http_protocol/src/utils.rs | 50 ------------------------------ 1 file changed, 50 deletions(-) diff --git a/aquatic_http_protocol/src/utils.rs b/aquatic_http_protocol/src/utils.rs index 2011cbf..b82764b 100644 --- a/aquatic_http_protocol/src/utils.rs +++ b/aquatic_http_protocol/src/utils.rs @@ -3,7 +3,6 @@ use std::io::Write; use anyhow::Context; use serde::{Serializer, Deserializer, de::Visitor}; -use smartstring::{SmartString, LazyCompact}; use super::response::ResponsePeer; @@ -67,44 +66,6 @@ pub fn urldecode_20_bytes(value: &str) -> anyhow::Result<[u8; 20]> { } -pub fn urldecode(value: &str) -> anyhow::Result> { - let mut processed = SmartString::new(); - - let bytes = value.as_bytes(); - let iter = ::memchr::memchr_iter(b'%', bytes); - - let mut str_index_after_hex = 0usize; - - for i in iter { - match (bytes.get(i), bytes.get(i + 1), bytes.get(i + 2)){ - (Some(0..=127), Some(0..=127), Some(0..=127)) => { - if i > 0 { - processed.push_str(&value[str_index_after_hex..i]); - } - - str_index_after_hex = i + 3; - - let hex = &value[i + 1..i + 3]; - let byte = u8::from_str_radix(&hex, 16)?; - - processed.push(byte as char); - }, - _ => { - return Err(anyhow::anyhow!( - "invalid urlencoded segment at byte {} in {}", i, value - )); - } - } - } - - if let Some(rest_of_str) = value.get(str_index_after_hex..){ - processed.push_str(rest_of_str); - } - - Ok(processed) -} - - #[inline] pub fn serialize_20_bytes( bytes: &[u8; 20], @@ -340,17 +301,6 @@ mod tests { input == decoded } - #[test] - fn test_urldecode(){ - assert_eq!(urldecode("").unwrap(), "".to_string()); - assert_eq!(urldecode("abc").unwrap(), "abc".to_string()); - assert_eq!(urldecode("%21").unwrap(), "!".to_string()); - assert_eq!(urldecode("%21%3D").unwrap(), "!=".to_string()); - assert_eq!(urldecode("abc%21def%3Dghi").unwrap(), "abc!def=ghi".to_string()); - assert!(urldecode("%").is_err()); - assert!(urldecode("%å7").is_err()); - } - #[quickcheck] fn test_serde_response_peers_ipv4( peers: Vec>,