]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/ike: convert to nom 8 14207/head
authorJason Ish <jason.ish@oisf.net>
Tue, 28 Oct 2025 22:06:25 +0000 (16:06 -0600)
committerJason Ish <jason.ish@oisf.net>
Thu, 30 Oct 2025 15:15:41 +0000 (09:15 -0600)
Ticket: #8050

rust/src/ike/ike.rs
rust/src/ike/ikev1.rs
rust/src/ike/parser.rs

index f6582782633fedbb536c31d7915f7445db8b6419..db8bfe24c5a0072adda3317cf3876028277bef00 100644 (file)
@@ -28,7 +28,7 @@ use crate::flow::Flow;
 use crate::ike::ikev1::{handle_ikev1, IkeV1Header, Ikev1Container};
 use crate::ike::ikev2::{handle_ikev2, Ikev2Container};
 use crate::ike::parser::*;
-use nom7::Err;
+use nom8::Err;
 use std;
 use std::collections::HashSet;
 use std::ffi::CString;
index 4ce29d2a10fa846031e2e4d7c56e765b3c219f94..b96d50b5887471efe2c145d3feb108be3d2c2138 100644 (file)
@@ -22,7 +22,7 @@ use crate::common::to_hex;
 use crate::direction::Direction;
 use crate::ike::ike::{IKEState, IkeEvent};
 use crate::ike::parser::*;
-use nom7::Err;
+use nom8::Err;
 use std;
 use std::collections::HashSet;
 
index 29518d074f106becb54f83300b73b100aae75fae..f7f74a83cda73aa8831f1c7fab80669ee2a1bab6 100644 (file)
 
 use crate::common::to_hex;
 use core::fmt;
-use nom7::bytes::streaming::take;
-use nom7::combinator::{complete, cond, map};
-use nom7::multi::many0;
-use nom7::number::streaming::{be_u16, be_u32, be_u64, be_u8};
-use nom7::{Err, IResult};
+use nom8::bytes::streaming::take;
+use nom8::combinator::{complete, cond, map};
+use nom8::multi::many0;
+use nom8::number::streaming::{be_u16, be_u32, be_u64, be_u8};
+use nom8::{Err, IResult, Parser};
 use std::collections::HashSet;
 
 // Generic ISAKMP "Container" structs
@@ -278,10 +278,10 @@ pub fn parse_isakmp_header(i: &[u8]) -> IResult<&[u8], IsakmpHeader> {
 pub fn parse_security_association(i: &[u8]) -> IResult<&[u8], SecurityAssociationPayload<'_>> {
     let start_i = i;
     let (i, domain_of_interpretation) = be_u32(i)?;
-    let (i, situation) = cond(domain_of_interpretation == 1, take(4_usize))(i)?;
+    let (i, situation) = cond(domain_of_interpretation == 1, take(4_usize)).parse(i)?;
     let (i, data) = cond(domain_of_interpretation == 1 && start_i.len() >= 8, |b| {
-        take(start_i.len() - 8)(b)
-    })(i)?;
+        take(start_i.len() - 8).parse(b)
+    }).parse(i)?;
     Ok((
         i,
         SecurityAssociationPayload {
@@ -305,8 +305,8 @@ pub fn parse_proposal(i: &[u8]) -> IResult<&[u8], ProposalPayload<'_>> {
     let (i, number_transforms) = be_u8(i)?;
     let (i, spi) = take(spi_size as usize)(i)?;
     let (i, payload_data) = cond((start_i.len() - 4) >= usize::from(spi_size), |b| {
-        take((start_i.len() - 4) - spi_size as usize)(b)
-    })(i)?;
+        take((start_i.len() - 4) - spi_size as usize).parse(b)
+    }).parse(i)?;
     let payload = ProposalPayload {
         _proposal_number: proposal_number,
         _proposal_type: proposal_type,
@@ -322,7 +322,7 @@ pub fn parse_transform(i: &[u8], length: u16) -> IResult<&[u8], TransformPayload
     let (i, transform_number) = be_u8(i)?;
     let (i, transform_type) = be_u8(i)?;
     let (i, _) = be_u16(i)?;
-    let (i, payload_data) = cond(length >= 4, |b| take(length - 4)(b))(i)?;
+    let (i, payload_data) = cond(length >= 4, |b| take(length - 4).parse(b)).parse(i)?;
     Ok((
         i,
         TransformPayload {
@@ -334,7 +334,7 @@ pub fn parse_transform(i: &[u8], length: u16) -> IResult<&[u8], TransformPayload
 }
 
 pub fn parse_vendor_id(i: &[u8], length: u16) -> IResult<&[u8], VendorPayload<'_>> {
-    map(take(length), |v| VendorPayload { vendor_id: v })(i)
+    map(take(length), |v| VendorPayload { vendor_id: v }).parse(i)
 }
 
 fn get_attribute_type(v: u16) -> AttributeType {
@@ -444,11 +444,11 @@ pub fn parse_sa_attribute(i: &[u8]) -> IResult<&[u8], Vec<SaAttribute>> {
         let format = ((b >> 15) as u8, b & 0x7f_ff);
         let (i, attribute_length_or_value) = be_u16(i)?; // depends on format bit) = 1 -> value | 0 -> number of following bytes
         let (i, numeric_variable_value) =
-            cond(format.0 == 0 && attribute_length_or_value == 4, be_u32)(i)?; // interpret as number
+            cond(format.0 == 0 && attribute_length_or_value == 4, be_u32).parse(i)?; // interpret as number
         let (i, variable_attribute_value) = cond(
             format.0 == 0 && attribute_length_or_value != 4,
             take(attribute_length_or_value),
-        )(i)?;
+        ).parse(i)?;
         let attr = SaAttribute {
             attribute_format: format.0,
             attribute_type: get_attribute_type(format.1),
@@ -477,11 +477,11 @@ pub fn parse_sa_attribute(i: &[u8]) -> IResult<&[u8], Vec<SaAttribute>> {
         };
         Ok((i, attr))
     }
-    many0(complete(parse_attribute))(i)
+    many0(complete(parse_attribute)).parse(i)
 }
 
 pub fn parse_nonce(i: &[u8], length: u16) -> IResult<&[u8], NoncePayload<'_>> {
-    map(take(length), |v| NoncePayload { nonce_data: v })(i)
+    map(take(length), |v| NoncePayload { nonce_data: v }).parse(i)
 }
 
 pub fn parse_ikev1_payload_list(i: &[u8]) -> IResult<&[u8], Vec<IsakmpPayload<'_>>> {
@@ -489,7 +489,7 @@ pub fn parse_ikev1_payload_list(i: &[u8]) -> IResult<&[u8], Vec<IsakmpPayload<'_
         let (i, next_payload) = be_u8(i)?;
         let (i, reserved) = be_u8(i)?;
         let (i, payload_length) = be_u16(i)?;
-        let (i, payload_data) = cond(payload_length >= 4, |b| take(payload_length - 4)(b))(i)?;
+        let (i, payload_data) = cond(payload_length >= 4, |b| take(payload_length - 4).parse(b)).parse(i)?;
         Ok((
             i,
             IsakmpPayload {
@@ -502,7 +502,7 @@ pub fn parse_ikev1_payload_list(i: &[u8]) -> IResult<&[u8], Vec<IsakmpPayload<'_
             },
         ))
     }
-    many0(complete(parse_payload))(i)
+    many0(complete(parse_payload)).parse(i)
 }
 
 #[derive(FromPrimitive, Debug)]