Skip to content

Commit 1efe70a

Browse files
committed
rust/ike: convert to nom 8
Ticket: OISF#8050
1 parent f368324 commit 1efe70a

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

rust/src/ike/ike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::flow::Flow;
2828
use crate::ike::ikev1::{handle_ikev1, IkeV1Header, Ikev1Container};
2929
use crate::ike::ikev2::{handle_ikev2, Ikev2Container};
3030
use crate::ike::parser::*;
31-
use nom7::Err;
31+
use nom8::Err;
3232
use std;
3333
use std::collections::HashSet;
3434
use std::ffi::CString;

rust/src/ike/ikev1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::common::to_hex;
2222
use crate::direction::Direction;
2323
use crate::ike::ike::{IKEState, IkeEvent};
2424
use crate::ike::parser::*;
25-
use nom7::Err;
25+
use nom8::Err;
2626
use std;
2727
use std::collections::HashSet;
2828

rust/src/ike/parser.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
use crate::common::to_hex;
1919
use core::fmt;
20-
use nom7::bytes::streaming::take;
21-
use nom7::combinator::{complete, cond, map};
22-
use nom7::multi::many0;
23-
use nom7::number::streaming::{be_u16, be_u32, be_u64, be_u8};
24-
use nom7::{Err, IResult};
20+
use nom8::bytes::streaming::take;
21+
use nom8::combinator::{complete, cond, map};
22+
use nom8::multi::many0;
23+
use nom8::number::streaming::{be_u16, be_u32, be_u64, be_u8};
24+
use nom8::{Err, IResult, Parser};
2525
use std::collections::HashSet;
2626

2727
// Generic ISAKMP "Container" structs
@@ -278,10 +278,10 @@ pub fn parse_isakmp_header(i: &[u8]) -> IResult<&[u8], IsakmpHeader> {
278278
pub fn parse_security_association(i: &[u8]) -> IResult<&[u8], SecurityAssociationPayload<'_>> {
279279
let start_i = i;
280280
let (i, domain_of_interpretation) = be_u32(i)?;
281-
let (i, situation) = cond(domain_of_interpretation == 1, take(4_usize))(i)?;
281+
let (i, situation) = cond(domain_of_interpretation == 1, take(4_usize)).parse(i)?;
282282
let (i, data) = cond(domain_of_interpretation == 1 && start_i.len() >= 8, |b| {
283-
take(start_i.len() - 8)(b)
284-
})(i)?;
283+
take(start_i.len() - 8).parse(b)
284+
}).parse(i)?;
285285
Ok((
286286
i,
287287
SecurityAssociationPayload {
@@ -305,8 +305,8 @@ pub fn parse_proposal(i: &[u8]) -> IResult<&[u8], ProposalPayload<'_>> {
305305
let (i, number_transforms) = be_u8(i)?;
306306
let (i, spi) = take(spi_size as usize)(i)?;
307307
let (i, payload_data) = cond((start_i.len() - 4) >= usize::from(spi_size), |b| {
308-
take((start_i.len() - 4) - spi_size as usize)(b)
309-
})(i)?;
308+
take((start_i.len() - 4) - spi_size as usize).parse(b)
309+
}).parse(i)?;
310310
let payload = ProposalPayload {
311311
_proposal_number: proposal_number,
312312
_proposal_type: proposal_type,
@@ -322,7 +322,7 @@ pub fn parse_transform(i: &[u8], length: u16) -> IResult<&[u8], TransformPayload
322322
let (i, transform_number) = be_u8(i)?;
323323
let (i, transform_type) = be_u8(i)?;
324324
let (i, _) = be_u16(i)?;
325-
let (i, payload_data) = cond(length >= 4, |b| take(length - 4)(b))(i)?;
325+
let (i, payload_data) = cond(length >= 4, |b| take(length - 4).parse(b)).parse(i)?;
326326
Ok((
327327
i,
328328
TransformPayload {
@@ -334,7 +334,7 @@ pub fn parse_transform(i: &[u8], length: u16) -> IResult<&[u8], TransformPayload
334334
}
335335

336336
pub fn parse_vendor_id(i: &[u8], length: u16) -> IResult<&[u8], VendorPayload<'_>> {
337-
map(take(length), |v| VendorPayload { vendor_id: v })(i)
337+
map(take(length), |v| VendorPayload { vendor_id: v }).parse(i)
338338
}
339339

340340
fn get_attribute_type(v: u16) -> AttributeType {
@@ -444,11 +444,11 @@ pub fn parse_sa_attribute(i: &[u8]) -> IResult<&[u8], Vec<SaAttribute>> {
444444
let format = ((b >> 15) as u8, b & 0x7f_ff);
445445
let (i, attribute_length_or_value) = be_u16(i)?; // depends on format bit) = 1 -> value | 0 -> number of following bytes
446446
let (i, numeric_variable_value) =
447-
cond(format.0 == 0 && attribute_length_or_value == 4, be_u32)(i)?; // interpret as number
447+
cond(format.0 == 0 && attribute_length_or_value == 4, be_u32).parse(i)?; // interpret as number
448448
let (i, variable_attribute_value) = cond(
449449
format.0 == 0 && attribute_length_or_value != 4,
450450
take(attribute_length_or_value),
451-
)(i)?;
451+
).parse(i)?;
452452
let attr = SaAttribute {
453453
attribute_format: format.0,
454454
attribute_type: get_attribute_type(format.1),
@@ -477,19 +477,19 @@ pub fn parse_sa_attribute(i: &[u8]) -> IResult<&[u8], Vec<SaAttribute>> {
477477
};
478478
Ok((i, attr))
479479
}
480-
many0(complete(parse_attribute))(i)
480+
many0(complete(parse_attribute)).parse(i)
481481
}
482482

483483
pub fn parse_nonce(i: &[u8], length: u16) -> IResult<&[u8], NoncePayload<'_>> {
484-
map(take(length), |v| NoncePayload { nonce_data: v })(i)
484+
map(take(length), |v| NoncePayload { nonce_data: v }).parse(i)
485485
}
486486

487487
pub fn parse_ikev1_payload_list(i: &[u8]) -> IResult<&[u8], Vec<IsakmpPayload<'_>>> {
488488
fn parse_payload(i: &[u8]) -> IResult<&[u8], IsakmpPayload<'_>> {
489489
let (i, next_payload) = be_u8(i)?;
490490
let (i, reserved) = be_u8(i)?;
491491
let (i, payload_length) = be_u16(i)?;
492-
let (i, payload_data) = cond(payload_length >= 4, |b| take(payload_length - 4)(b))(i)?;
492+
let (i, payload_data) = cond(payload_length >= 4, |b| take(payload_length - 4).parse(b)).parse(i)?;
493493
Ok((
494494
i,
495495
IsakmpPayload {
@@ -502,7 +502,7 @@ pub fn parse_ikev1_payload_list(i: &[u8]) -> IResult<&[u8], Vec<IsakmpPayload<'_
502502
},
503503
))
504504
}
505-
many0(complete(parse_payload))(i)
505+
many0(complete(parse_payload)).parse(i)
506506
}
507507

508508
#[derive(FromPrimitive, Debug)]

0 commit comments

Comments
 (0)