Skip to content

Commit bea0916

Browse files
committed
http2: update to nom 8.0
Update http2 parser, huffman decoder, and range parser to use nom 8.0. Also updates common.rs bits wrapper to accept Parser trait, and fixes mqtt and rdp parsers affected by that change.
1 parent eea50ba commit bea0916

7 files changed

Lines changed: 92 additions & 82 deletions

File tree

rust/src/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ pub mod nom8 {
8989
/// used by the tuple parser, because the function is generic and any
9090
/// error type would be valid.
9191
/// Use an explicit error type (as described in
92-
/// https://docs.rs/nom/7.1.0/nom/bits/fn.bits.html) to solve this problem, and
92+
/// https://docs.rs/nom/8.0.0/nom/bits/fn.bits.html) to solve this problem, and
9393
/// specialize this function for `&[u8]`.
94-
pub fn bits<'a, O, E, P>(parser: P) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], O, E>
94+
pub fn bits<'a, O, E, P>(parser: P) -> impl Parser<&'a [u8], Output = O, Error = E>
9595
where
9696
E: ParseError<&'a [u8]>,
9797
Error<(&'a [u8], usize)>: ErrorConvert<E>,
98-
P: FnMut((&'a [u8], usize)) -> IResult<(&'a [u8], usize), O, Error<(&'a [u8], usize)>>,
98+
P: Parser<(&'a [u8], usize), Output = O, Error = Error<(&'a [u8], usize)>>,
9999
{
100100
// use full path to disambiguate nom `bits` from this current function name
101101
nom8::bits::bits(parser)

rust/src/http2/http2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::frames::Frame;
3232

3333
use crate::dns::dns::{dns_parse_request, dns_parse_response, DNSTransaction};
3434

35-
use nom7::Err;
35+
use nom8::Err;
3636
use std;
3737
use std::collections::VecDeque;
3838
use std::ffi::CString;

rust/src/http2/huffman.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
* 02110-1301, USA.
1616
*/
1717

18-
use nom7::bits::streaming::take as take_bits;
19-
use nom7::branch::alt;
20-
use nom7::combinator::{complete, map_opt};
21-
use nom7::error::{make_error, ErrorKind};
22-
use nom7::{Err, IResult};
18+
use nom8::bits::streaming::take as take_bits;
19+
use nom8::branch::alt;
20+
use nom8::combinator::{complete, map_opt};
21+
use nom8::error::{make_error, ErrorKind};
22+
use nom8::{Err, IResult, Parser};
2323

2424
fn http2_huffman_table_len5(n: u32) -> Option<u8> {
2525
match n {
@@ -38,7 +38,7 @@ fn http2_huffman_table_len5(n: u32) -> Option<u8> {
3838
}
3939

4040
fn http2_decode_huffman_len5(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
41-
complete(map_opt(take_bits(5u32), http2_huffman_table_len5))(input)
41+
complete(map_opt(take_bits(5u32), http2_huffman_table_len5)).parse(input)
4242
}
4343

4444
fn http2_huffman_table_len6(n: u32) -> Option<u8> {
@@ -74,7 +74,7 @@ fn http2_huffman_table_len6(n: u32) -> Option<u8> {
7474
}
7575

7676
fn http2_decode_huffman_len6(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
77-
complete(map_opt(take_bits(6u32), http2_huffman_table_len6))(input)
77+
complete(map_opt(take_bits(6u32), http2_huffman_table_len6)).parse(input)
7878
}
7979

8080
fn http2_huffman_table_len7(n: u32) -> Option<u8> {
@@ -116,7 +116,7 @@ fn http2_huffman_table_len7(n: u32) -> Option<u8> {
116116
}
117117

118118
fn http2_decode_huffman_len7(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
119-
complete(map_opt(take_bits(7u32), http2_huffman_table_len7))(input)
119+
complete(map_opt(take_bits(7u32), http2_huffman_table_len7)).parse(input)
120120
}
121121

122122
fn http2_huffman_table_len8(n: u32) -> Option<u8> {
@@ -132,7 +132,7 @@ fn http2_huffman_table_len8(n: u32) -> Option<u8> {
132132
}
133133

134134
fn http2_decode_huffman_len8(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
135-
complete(map_opt(take_bits(8u32), http2_huffman_table_len8))(input)
135+
complete(map_opt(take_bits(8u32), http2_huffman_table_len8)).parse(input)
136136
}
137137

138138
fn http2_huffman_table_len10(n: u32) -> Option<u8> {
@@ -147,7 +147,7 @@ fn http2_huffman_table_len10(n: u32) -> Option<u8> {
147147
}
148148

149149
fn http2_decode_huffman_len10(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
150-
complete(map_opt(take_bits(10u32), http2_huffman_table_len10))(input)
150+
complete(map_opt(take_bits(10u32), http2_huffman_table_len10)).parse(input)
151151
}
152152

153153
fn http2_huffman_table_len11(n: u32) -> Option<u8> {
@@ -160,7 +160,7 @@ fn http2_huffman_table_len11(n: u32) -> Option<u8> {
160160
}
161161

162162
fn http2_decode_huffman_len11(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
163-
complete(map_opt(take_bits(11u32), http2_huffman_table_len11))(input)
163+
complete(map_opt(take_bits(11u32), http2_huffman_table_len11)).parse(input)
164164
}
165165

166166
fn http2_huffman_table_len12(n: u32) -> Option<u8> {
@@ -172,7 +172,7 @@ fn http2_huffman_table_len12(n: u32) -> Option<u8> {
172172
}
173173

174174
fn http2_decode_huffman_len12(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
175-
complete(map_opt(take_bits(12u32), http2_huffman_table_len12))(input)
175+
complete(map_opt(take_bits(12u32), http2_huffman_table_len12)).parse(input)
176176
}
177177

178178
fn http2_huffman_table_len13(n: u32) -> Option<u8> {
@@ -188,7 +188,7 @@ fn http2_huffman_table_len13(n: u32) -> Option<u8> {
188188
}
189189

190190
fn http2_decode_huffman_len13(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
191-
complete(map_opt(take_bits(13u32), http2_huffman_table_len13))(input)
191+
complete(map_opt(take_bits(13u32), http2_huffman_table_len13)).parse(input)
192192
}
193193

194194
fn http2_huffman_table_len14(n: u32) -> Option<u8> {
@@ -200,7 +200,7 @@ fn http2_huffman_table_len14(n: u32) -> Option<u8> {
200200
}
201201

202202
fn http2_decode_huffman_len14(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
203-
complete(map_opt(take_bits(14u32), http2_huffman_table_len14))(input)
203+
complete(map_opt(take_bits(14u32), http2_huffman_table_len14)).parse(input)
204204
}
205205

206206
fn http2_huffman_table_len15(n: u32) -> Option<u8> {
@@ -213,7 +213,7 @@ fn http2_huffman_table_len15(n: u32) -> Option<u8> {
213213
}
214214

215215
fn http2_decode_huffman_len15(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
216-
complete(map_opt(take_bits(15u32), http2_huffman_table_len15))(input)
216+
complete(map_opt(take_bits(15u32), http2_huffman_table_len15)).parse(input)
217217
}
218218

219219
fn http2_huffman_table_len19(n: u32) -> Option<u8> {
@@ -226,7 +226,7 @@ fn http2_huffman_table_len19(n: u32) -> Option<u8> {
226226
}
227227

228228
fn http2_decode_huffman_len19(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
229-
complete(map_opt(take_bits(19u32), http2_huffman_table_len19))(input)
229+
complete(map_opt(take_bits(19u32), http2_huffman_table_len19)).parse(input)
230230
}
231231

232232
fn http2_huffman_table_len20(n: u32) -> Option<u8> {
@@ -244,7 +244,7 @@ fn http2_huffman_table_len20(n: u32) -> Option<u8> {
244244
}
245245

246246
fn http2_decode_huffman_len20(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
247-
complete(map_opt(take_bits(20u32), http2_huffman_table_len20))(input)
247+
complete(map_opt(take_bits(20u32), http2_huffman_table_len20)).parse(input)
248248
}
249249

250250
fn http2_huffman_table_len21(n: u32) -> Option<u8> {
@@ -267,7 +267,7 @@ fn http2_huffman_table_len21(n: u32) -> Option<u8> {
267267
}
268268

269269
fn http2_decode_huffman_len21(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
270-
complete(map_opt(take_bits(21u32), http2_huffman_table_len21))(input)
270+
complete(map_opt(take_bits(21u32), http2_huffman_table_len21)).parse(input)
271271
}
272272

273273
fn http2_huffman_table_len22(n: u32) -> Option<u8> {
@@ -303,7 +303,7 @@ fn http2_huffman_table_len22(n: u32) -> Option<u8> {
303303
}
304304

305305
fn http2_decode_huffman_len22(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
306-
complete(map_opt(take_bits(22u32), http2_huffman_table_len22))(input)
306+
complete(map_opt(take_bits(22u32), http2_huffman_table_len22)).parse(input)
307307
}
308308

309309
fn http2_huffman_table_len23(n: u32) -> Option<u8> {
@@ -342,7 +342,7 @@ fn http2_huffman_table_len23(n: u32) -> Option<u8> {
342342
}
343343

344344
fn http2_decode_huffman_len23(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
345-
complete(map_opt(take_bits(23u32), http2_huffman_table_len23))(input)
345+
complete(map_opt(take_bits(23u32), http2_huffman_table_len23)).parse(input)
346346
}
347347

348348
fn http2_huffman_table_len24(n: u32) -> Option<u8> {
@@ -364,7 +364,7 @@ fn http2_huffman_table_len24(n: u32) -> Option<u8> {
364364
}
365365

366366
fn http2_decode_huffman_len24(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
367-
complete(map_opt(take_bits(24u32), http2_huffman_table_len24))(input)
367+
complete(map_opt(take_bits(24u32), http2_huffman_table_len24)).parse(input)
368368
}
369369

370370
fn http2_huffman_table_len25(n: u32) -> Option<u8> {
@@ -378,7 +378,7 @@ fn http2_huffman_table_len25(n: u32) -> Option<u8> {
378378
}
379379

380380
fn http2_decode_huffman_len25(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
381-
complete(map_opt(take_bits(25u32), http2_huffman_table_len25))(input)
381+
complete(map_opt(take_bits(25u32), http2_huffman_table_len25)).parse(input)
382382
}
383383

384384
fn http2_huffman_table_len26(n: u32) -> Option<u8> {
@@ -403,7 +403,7 @@ fn http2_huffman_table_len26(n: u32) -> Option<u8> {
403403
}
404404

405405
fn http2_decode_huffman_len26((i, bit_offset): (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
406-
complete(map_opt(take_bits(26u32), http2_huffman_table_len26))((i, bit_offset))
406+
complete(map_opt(take_bits(26u32), http2_huffman_table_len26)).parse((i, bit_offset))
407407
}
408408

409409
fn http2_huffman_table_len27(n: u32) -> Option<u8> {
@@ -432,7 +432,7 @@ fn http2_huffman_table_len27(n: u32) -> Option<u8> {
432432
}
433433

434434
fn http2_decode_huffman_len27(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
435-
complete(map_opt(take_bits(27u32), http2_huffman_table_len27))(input)
435+
complete(map_opt(take_bits(27u32), http2_huffman_table_len27)).parse(input)
436436
}
437437

438438
fn http2_huffman_table_len28(n: u32) -> Option<u8> {
@@ -471,7 +471,7 @@ fn http2_huffman_table_len28(n: u32) -> Option<u8> {
471471
}
472472

473473
fn http2_decode_huffman_len28(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
474-
complete(map_opt(take_bits(28u32), http2_huffman_table_len28))(input)
474+
complete(map_opt(take_bits(28u32), http2_huffman_table_len28)).parse(input)
475475
}
476476

477477
fn http2_huffman_table_len30(n: u32) -> Option<u8> {
@@ -485,7 +485,7 @@ fn http2_huffman_table_len30(n: u32) -> Option<u8> {
485485
}
486486

487487
fn http2_decode_huffman_len30(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8> {
488-
complete(map_opt(take_bits(30u32), http2_huffman_table_len30))(input)
488+
complete(map_opt(take_bits(30u32), http2_huffman_table_len30)).parse(input)
489489
}
490490

491491
//hack to end many0 even if some bits are remaining
@@ -523,5 +523,5 @@ pub fn http2_decode_huffman(input: (&[u8], usize)) -> IResult<(&[u8], usize), u8
523523
http2_decode_huffman_len30,
524524
http2_decode_huffman_end,
525525
)),
526-
))(input)
526+
)).parse(input)
527527
}

0 commit comments

Comments
 (0)