]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/applayertemplate: convert to nom7
authorPierre Chifflier <chifflier@wzdftpd.net>
Wed, 19 Jan 2022 14:06:21 +0000 (15:06 +0100)
committerVictor Julien <vjulien@oisf.net>
Thu, 29 Sep 2022 08:37:50 +0000 (10:37 +0200)
rust/src/applayertemplate/parser.rs
rust/src/applayertemplate/template.rs

index 0fdfc9c2ef5b03a6275e0452e147c9a6f9f6154c..d781e9891d5fc204a85d988988d8baf57d5f85b5 100644 (file)
  * 02110-1301, USA.
  */
 
+use nom7::{
+    bytes::streaming::{take, take_until},
+    combinator::map_res,
+    IResult,
+};
 use std;
 
 fn parse_len(input: &str) -> Result<u32, std::num::ParseIntError> {
     input.parse::<u32>()
 }
 
-named!(pub parse_message<String>,
-       do_parse!(
-           len:  map_res!(
-                 map_res!(take_until!(":"), std::str::from_utf8), parse_len) >>
-           _sep: take!(1) >>
-           msg:  take_str!(len) >>
-               (
-                   msg.to_string()
-               )
-       ));
+pub fn parse_message(i: &[u8]) -> IResult<&[u8], String> {
+    let (i, len) = map_res(map_res(take_until(":"), std::str::from_utf8), parse_len)(i)?;
+    let (i, _sep) = take(1_usize)(i)?;
+    let (i, msg) = map_res(take(len as usize), std::str::from_utf8)(i)?;
+    let result = msg.to_string();
+    Ok((i, result))
+}
 
 #[cfg(test)]
 mod tests {
-
-    use nom::*;
     use super::*;
+    use nom7::Err;
 
     /// Simple test of some valid data.
     #[test]
index a0ec9a34afc18856079876967d534c4f5a0d3240..3db22ea3432f519c6e049fb64ef005f910747359 100644 (file)
@@ -20,7 +20,7 @@ use std::collections::VecDeque;
 use crate::core::{ALPROTO_UNKNOWN, AppProto, Flow, IPPROTO_TCP};
 use crate::applayer::{self, *};
 use std::ffi::CString;
-use nom;
+use nom7 as nom;
 use super::parser;
 
 static mut ALPROTO_TEMPLATE: AppProto = ALPROTO_UNKNOWN;