Skip to content

Commit df43a0d

Browse files
committed
Upgrade nom to version 8.0
1 parent 1e836c4 commit df43a0d

File tree

9 files changed

+60
-46
lines changed

9 files changed

+60
-46
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ rustdoc-args = ["--cfg", "docsrs"]
4646
[dependencies]
4747
circular = "0.3"
4848
cookie-factory = { version="0.3.0", optional=true }
49-
nom = "7.0"
50-
rusticata-macros = "4.0"
49+
nom = "8.0"
50+
rusticata-macros = "5.0"
5151

5252
[dev-dependencies]
5353
criterion = { version="0.5", features=["html_reports"] }

src/data/exported_pdu.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::data::PacketData;
22
use nom::bytes::streaming::{tag, take};
33
use nom::multi::many_till;
44
use nom::number::streaming::be_u16;
5-
use nom::IResult;
5+
use nom::{IResult, Parser as _};
66
use std::convert::TryFrom;
77

88
/* values from epan/exported_pdu.h */
@@ -27,7 +27,9 @@ pub fn parse_exported_tlv(i: &[u8]) -> IResult<&[u8], ExportedTlv<'_>> {
2727
}
2828

2929
pub fn parse_many_exported_tlv(i: &[u8]) -> IResult<&[u8], Vec<ExportedTlv<'_>>> {
30-
many_till(parse_exported_tlv, tag(b"\x00\x00\x00\x00"))(i).map(|(rem, (v, _))| (rem, v))
30+
many_till(parse_exported_tlv, tag(b"\x00\x00\x00\x00" as &[u8]))
31+
.parse(i)
32+
.map(|(rem, (v, _))| (rem, v))
3133
}
3234

3335
/// Get packet data for WIRESHARK_UPPER_PDU (252)

src/data/pcap_nflog.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use nom::bytes::streaming::take;
1010
use nom::combinator::{complete, cond, verify};
1111
use nom::multi::many0;
1212
use nom::number::streaming::{be_u16, le_u16, le_u8};
13-
use nom::IResult;
13+
use nom::{IResult, Parser as _};
1414

1515
// Defined in linux/netfilter/nfnetlink_log.h
1616
#[derive(Copy, Clone)]
@@ -68,10 +68,10 @@ pub struct NflogTlv<'a> {
6868
}
6969

7070
pub fn parse_nflog_tlv(i: &[u8]) -> IResult<&[u8], NflogTlv<'_>> {
71-
let (i, l) = verify(le_u16, |&n| n >= 4)(i)?;
71+
let (i, l) = verify(le_u16, |&n| n >= 4).parse(i)?;
7272
let (i, t) = le_u16(i)?;
7373
let (i, v) = take(l - 4)(i)?;
74-
let (i, _padding) = cond(l % 4 != 0, take(4 - (l % 4)))(i)?;
74+
let (i, _padding) = cond(l % 4 != 0, take(4 - (l % 4))).parse(i)?;
7575
Ok((i, NflogTlv { l, t, v }))
7676
}
7777

@@ -112,7 +112,7 @@ impl NflogPacket<'_> {
112112

113113
pub fn parse_nflog(i: &[u8]) -> IResult<&[u8], NflogPacket<'_>> {
114114
let (i, header) = parse_nflog_header(i)?;
115-
let (i, data) = many0(complete(parse_nflog_tlv))(i)?;
115+
let (i, data) = many0(complete(parse_nflog_tlv)).parse(i)?;
116116
Ok((i, NflogPacket { header, data }))
117117
}
118118

src/pcap/capture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::linktype::Linktype;
55
use crate::pcap::{parse_pcap_frame, parse_pcap_header, LegacyPcapBlock, PcapHeader};
66
use nom::combinator::complete;
77
use nom::multi::many0;
8-
use nom::{IResult, Needed};
8+
use nom::{IResult, Needed, Parser as _};
99
use std::fmt;
1010

1111
/// Parsing iterator over legacy pcap data (requires data to be loaded into memory)
@@ -121,6 +121,6 @@ impl Capture for PcapCapture<'_> {
121121
/// Note: this requires the file to be fully loaded to memory.
122122
pub fn parse_pcap(i: &[u8]) -> IResult<&[u8], PcapCapture<'_>, PcapError<&[u8]>> {
123123
let (i, header) = parse_pcap_header(i)?;
124-
let (i, blocks) = many0(complete(parse_pcap_frame))(i)?;
124+
let (i, blocks) = many0(complete(parse_pcap_frame)).parse(i)?;
125125
Ok((i, PcapCapture { header, blocks }))
126126
}

src/pcapng/block.rs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use nom::bytes::streaming::take;
22
use nom::combinator::map;
3-
use nom::error::*;
43
use nom::number::streaming::{be_u32, le_u32};
4+
use nom::{error::*, Parser as _};
55
use nom::{Err, IResult};
66

77
use crate::endianness::PcapEndianness;
@@ -56,27 +56,30 @@ impl Block<'_> {
5656
pub fn parse_block_le(i: &[u8]) -> IResult<&[u8], Block<'_>, PcapError<&[u8]>> {
5757
match le_u32(i) {
5858
Ok((_, id)) => match id {
59-
SHB_MAGIC => map(parse_sectionheaderblock, Block::SectionHeader)(i),
59+
SHB_MAGIC => map(parse_sectionheaderblock, Block::SectionHeader).parse(i),
6060
IDB_MAGIC => map(
6161
parse_interfacedescriptionblock_le,
6262
Block::InterfaceDescription,
63-
)(i),
64-
SPB_MAGIC => map(parse_simplepacketblock_le, Block::SimplePacket)(i),
65-
EPB_MAGIC => map(parse_enhancedpacketblock_le, Block::EnhancedPacket)(i),
66-
NRB_MAGIC => map(parse_nameresolutionblock_le, Block::NameResolution)(i),
63+
)
64+
.parse(i),
65+
SPB_MAGIC => map(parse_simplepacketblock_le, Block::SimplePacket).parse(i),
66+
EPB_MAGIC => map(parse_enhancedpacketblock_le, Block::EnhancedPacket).parse(i),
67+
NRB_MAGIC => map(parse_nameresolutionblock_le, Block::NameResolution).parse(i),
6768
ISB_MAGIC => map(
6869
parse_interfacestatisticsblock_le,
6970
Block::InterfaceStatistics,
70-
)(i),
71+
)
72+
.parse(i),
7173
SJE_MAGIC => map(
7274
parse_systemdjournalexportblock_le,
7375
Block::SystemdJournalExport,
74-
)(i),
75-
DSB_MAGIC => map(parse_decryptionsecretsblock_le, Block::DecryptionSecrets)(i),
76-
CB_MAGIC => map(parse_customblock_le, Block::Custom)(i),
77-
DCB_MAGIC => map(parse_dcb_le, Block::Custom)(i),
78-
PIB_MAGIC => map(parse_processinformationblock_le, Block::ProcessInformation)(i),
79-
_ => map(parse_unknownblock_le, Block::Unknown)(i),
76+
)
77+
.parse(i),
78+
DSB_MAGIC => map(parse_decryptionsecretsblock_le, Block::DecryptionSecrets).parse(i),
79+
CB_MAGIC => map(parse_customblock_le, Block::Custom).parse(i),
80+
DCB_MAGIC => map(parse_dcb_le, Block::Custom).parse(i),
81+
PIB_MAGIC => map(parse_processinformationblock_le, Block::ProcessInformation).parse(i),
82+
_ => map(parse_unknownblock_le, Block::Unknown).parse(i),
8083
},
8184
Err(e) => Err(e),
8285
}
@@ -89,27 +92,30 @@ pub fn parse_block_le(i: &[u8]) -> IResult<&[u8], Block<'_>, PcapError<&[u8]>> {
8992
pub fn parse_block_be(i: &[u8]) -> IResult<&[u8], Block<'_>, PcapError<&[u8]>> {
9093
match be_u32(i) {
9194
Ok((_, id)) => match id {
92-
SHB_MAGIC => map(parse_sectionheaderblock, Block::SectionHeader)(i),
95+
SHB_MAGIC => map(parse_sectionheaderblock, Block::SectionHeader).parse(i),
9396
IDB_MAGIC => map(
9497
parse_interfacedescriptionblock_be,
9598
Block::InterfaceDescription,
96-
)(i),
97-
SPB_MAGIC => map(parse_simplepacketblock_be, Block::SimplePacket)(i),
98-
EPB_MAGIC => map(parse_enhancedpacketblock_be, Block::EnhancedPacket)(i),
99-
NRB_MAGIC => map(parse_nameresolutionblock_be, Block::NameResolution)(i),
99+
)
100+
.parse(i),
101+
SPB_MAGIC => map(parse_simplepacketblock_be, Block::SimplePacket).parse(i),
102+
EPB_MAGIC => map(parse_enhancedpacketblock_be, Block::EnhancedPacket).parse(i),
103+
NRB_MAGIC => map(parse_nameresolutionblock_be, Block::NameResolution).parse(i),
100104
ISB_MAGIC => map(
101105
parse_interfacestatisticsblock_be,
102106
Block::InterfaceStatistics,
103-
)(i),
107+
)
108+
.parse(i),
104109
SJE_MAGIC => map(
105110
parse_systemdjournalexportblock_be,
106111
Block::SystemdJournalExport,
107-
)(i),
108-
DSB_MAGIC => map(parse_decryptionsecretsblock_be, Block::DecryptionSecrets)(i),
109-
CB_MAGIC => map(parse_customblock_be, Block::Custom)(i),
110-
DCB_MAGIC => map(parse_dcb_be, Block::Custom)(i),
111-
PIB_MAGIC => map(parse_processinformationblock_be, Block::ProcessInformation)(i),
112-
_ => map(parse_unknownblock_be, Block::Unknown)(i),
112+
)
113+
.parse(i),
114+
DSB_MAGIC => map(parse_decryptionsecretsblock_be, Block::DecryptionSecrets).parse(i),
115+
CB_MAGIC => map(parse_customblock_be, Block::Custom).parse(i),
116+
DCB_MAGIC => map(parse_dcb_be, Block::Custom).parse(i),
117+
PIB_MAGIC => map(parse_processinformationblock_be, Block::ProcessInformation).parse(i),
118+
_ => map(parse_unknownblock_be, Block::Unknown).parse(i),
113119
},
114120
Err(e) => Err(e),
115121
}

src/pcapng/capture.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::error::PcapError;
33
use crate::pcapng::*;
44
use nom::combinator::{complete, map};
55
use nom::multi::many1;
6-
use nom::{IResult, Needed};
6+
use nom::{IResult, Needed, Parser as _};
77
use std::fmt;
88

99
#[derive(Default)]
@@ -122,5 +122,6 @@ impl<'a> PcapNGCapture<'a> {
122122
pub fn parse_pcapng(i: &[u8]) -> IResult<&[u8], PcapNGCapture<'_>, PcapError<&[u8]>> {
123123
map(many1(complete(parse_section)), |sections| PcapNGCapture {
124124
sections,
125-
})(i)
125+
})
126+
.parse(i)
126127
}

src/pcapng/name_resolution.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use nom::bytes::streaming::{tag, take};
22
use nom::combinator::map;
33
use nom::error::{ErrorKind, ParseError};
44
use nom::multi::many_till;
5-
use nom::{Err, IResult};
5+
use nom::{Err, IResult, Parser as _};
66
use rusticata_macros::{align32, newtype_enum};
77

88
use crate::endianness::{PcapBE, PcapEndianness, PcapLE};
@@ -94,12 +94,16 @@ fn parse_name_record_list<'a, En: PcapEndianness, E: ParseError<&'a [u8]>>(
9494
i: &'a [u8],
9595
) -> IResult<&'a [u8], Vec<NameRecord<'a>>, E> {
9696
map(
97-
many_till(parse_name_record::<En, E>, tag(b"\x00\x00\x00\x00")),
97+
many_till(
98+
parse_name_record::<En, E>,
99+
tag(b"\x00\x00\x00\x00" as &[u8]),
100+
),
98101
|(mut v, _)| {
99102
v.push(NameRecord::END);
100103
v
101104
},
102-
)(i)
105+
)
106+
.parse(i)
103107
}
104108

105109
/// Parse a Name Resolution Block (little-endian)

src/pcapng/option.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::fmt;
44

55
use nom::combinator::{complete, map_parser};
66
use nom::multi::many0;
7-
use nom::IResult;
87
use nom::{bytes::streaming::take, error::ParseError};
8+
use nom::{IResult, Parser as _};
99
use rusticata_macros::{align32, newtype_enum};
1010

1111
use crate::endianness::{PcapBE, PcapEndianness, PcapLE};
@@ -193,7 +193,8 @@ pub(crate) fn opt_parse_options<'i, En: PcapEndianness, E: ParseError<&'i [u8]>>
193193
map_parser(
194194
take(len - opt_offset),
195195
many0(complete(parse_option::<En, E>)),
196-
)(i)
196+
)
197+
.parse(i)
197198
} else {
198199
Ok((i, Vec::new()))
199200
}

src/pcapng/section.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use nom::{
22
combinator::complete,
33
error::{make_error, ErrorKind},
44
multi::{many0, many1},
5-
Err, IResult,
5+
Err, IResult, Parser as _,
66
};
77

88
use crate::{PcapBlock, PcapError};
@@ -106,9 +106,9 @@ pub fn parse_section(i: &[u8]) -> IResult<&[u8], Section<'_>, PcapError<&[u8]>>
106106
let (rem, shb) = parse_sectionheaderblock(i)?;
107107
let big_endian = shb.big_endian();
108108
let (rem, mut b) = if big_endian {
109-
many0(complete(parse_section_content_block_be))(rem)?
109+
many0(complete(parse_section_content_block_be)).parse(rem)?
110110
} else {
111-
many0(complete(parse_section_content_block_le))(rem)?
111+
many0(complete(parse_section_content_block_le)).parse(rem)?
112112
};
113113
let mut blocks = Vec::with_capacity(b.len() + 1);
114114
blocks.push(Block::SectionHeader(shb));
@@ -120,5 +120,5 @@ pub fn parse_section(i: &[u8]) -> IResult<&[u8], Section<'_>, PcapError<&[u8]>>
120120
/// Parse multiple sections (little or big endian)
121121
#[inline]
122122
pub fn parse_sections(i: &[u8]) -> IResult<&[u8], Vec<Section<'_>>, PcapError<&[u8]>> {
123-
many1(complete(parse_section))(i)
123+
many1(complete(parse_section)).parse(i)
124124
}

0 commit comments

Comments
 (0)