]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/applayertemplate: convert to nom 8
authorJason Ish <jason.ish@oisf.net>
Mon, 27 Oct 2025 16:27:59 +0000 (10:27 -0600)
committerVictor Julien <vjulien@oisf.net>
Wed, 29 Oct 2025 15:33:52 +0000 (15:33 +0000)
Ticket: #8027

rust/src/applayertemplate/parser.rs
rust/src/applayertemplate/template.rs

index dc096eb0c677227bbb83e9191102770cc82f92e4..52d90cded7dcf719ac1252003d692a6803e921a7 100644 (file)
  * 02110-1301, USA.
  */
 
-use nom7::{
+use nom8::{
     bytes::streaming::{take, take_until},
     combinator::map_res,
-    IResult,
+    IResult, Parser,
 };
 use std;
 
@@ -27,9 +27,9 @@ fn parse_len(input: &str) -> Result<u32, std::num::ParseIntError> {
 }
 
 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 (i, len) = map_res(map_res(take_until(":"), std::str::from_utf8), parse_len).parse(i)?;
+    let (i, _sep) = take(1_usize).parse(i)?;
+    let (i, msg) = map_res(take(len as usize), std::str::from_utf8).parse(i)?;
     let result = msg.to_string();
     Ok((i, result))
 }
@@ -37,7 +37,7 @@ pub fn parse_message(i: &[u8]) -> IResult<&[u8], String> {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use nom7::Err;
+    use nom8::Err;
 
     /// Simple test of some valid data.
     #[test]
index 022343306a390988c726cbe9c6f49bf7a3f89ae3..fc59e723ae6e692a267aab968e379d28b83cebcf 100644 (file)
@@ -20,7 +20,8 @@ use crate::applayer::*;
 use crate::conf::conf_get;
 use crate::core::{ALPROTO_UNKNOWN, IPPROTO_TCP};
 use crate::flow::Flow;
-use nom7 as nom;
+use nom8 as nom;
+use nom8::{AsChar, Parser};
 use std;
 use std::collections::VecDeque;
 use std::ffi::CString;
@@ -247,11 +248,11 @@ impl TemplateState {
 /// characters for that pattern.
 fn probe(input: &[u8]) -> nom::IResult<&[u8], ()> {
     let size = std::cmp::min(10, input.len());
-    let (rem, prefix) = nom::bytes::complete::take(size)(input)?;
+    let (rem, prefix) = nom::bytes::complete::take(size).parse(input)?;
     nom::sequence::terminated(
-        nom::bytes::complete::take_while1(nom::character::is_digit),
+        nom::bytes::complete::take_while1(|c: u8| c.is_dec_digit()),
         nom::bytes::complete::tag(":"),
-    )(prefix)?;
+    ).parse(prefix)?;
     Ok((rem, ()))
 }