diff --git a/src/request/mod.rs b/src/request/mod.rs index db27c6e..2c83f14 100644 --- a/src/request/mod.rs +++ b/src/request/mod.rs @@ -135,23 +135,3 @@ define_tokens_128! { XOAUTH, XOAUTH2, } - -/* - * Adapted from Daniel Lemire's source: - * https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2019/04/17/hexparse.cpp - * - */ - -pub(crate) static HEX_MAP: &[i8] = &[ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, - 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -]; diff --git a/src/request/parser.rs b/src/request/parser.rs index f4f5f0a..e05d406 100644 --- a/src/request/parser.rs +++ b/src/request/parser.rs @@ -583,19 +583,15 @@ impl<'x, 'y> Rfc5321Parser<'x, 'y> { return Ok(value.into_string()); } b'+' => { - let mut hex1 = 0; + let mut hex1 = None; while let Some(&ch) = self.bytes.next() { - if ch.is_ascii_hexdigit() { - if hex1 != 0 { - let hex1 = HEX_MAP[hex1 as usize]; - let hex2 = HEX_MAP[ch as usize]; - if hex1 != -1 && hex2 != -1 { - value.push(((hex1 as u8) << 4) | hex2 as u8); - } + if let Some(digit) = char::from(ch).to_digit(16) { + if let Some(hex1) = hex1 { + value.push(((hex1 as u8) << 4) | digit as u8); break; } else { - hex1 = ch; + hex1 = Some(digit); } } else if ch == LF { self.stop_char = b'\n';