Skip to content

Commit

Permalink
Bump nom from 7.1.3 to 8.0.0 (#62)
Browse files Browse the repository at this point in the history
* Bump nom from 7.1.3 to 8.0.0

Bumps [nom](https://github.com/rust-bakery/nom) from 7.1.3 to 8.0.0.
- [Changelog](https://github.com/rust-bakery/nom/blob/main/CHANGELOG.md)
- [Commits](rust-bakery/nom@7.1.3...8.0.0)

---
updated-dependencies:
- dependency-name: nom
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* db parser fixed

* lint fixed

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: biandratti <[email protected]>
  • Loading branch information
dependabot[bot] and biandratti authored Feb 4, 2025
1 parent 9d79082 commit 3cec9fc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
11 changes: 2 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["p0f", "fingerprinting", "network", "security", "TCP"]
categories = ["network-programming"]

[dependencies]
nom = "7.1"
nom = "8.0"
pnet = "0.35.0"
failure = "0.1.8"
log = "0.4.25"
Expand Down
67 changes: 41 additions & 26 deletions src/db_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use nom::{
bytes::complete::tag,
character::complete::{alphanumeric1, space0},
combinator::rest,
sequence::{preceded, tuple},
sequence::preceded,
IResult,
};

Expand Down Expand Up @@ -204,40 +204,42 @@ impl_from_str!(HttpHeader, parse_http_header);

fn parse_named_value(input: &str) -> IResult<&str, (&str, &str)> {
let (input, (name, _, _, _, value)) =
tuple((alphanumeric1, space0, tag("="), space0, rest))(input)?;
(alphanumeric1, space0, tag("="), space0, rest).parse(input)?;
Ok((input, (name, value)))
}

fn parse_classes(input: &str) -> IResult<&str, Vec<String>> {
let (input, (_, _, _, _, classes)) = tuple((
let (input, (_, _, _, _, classes)) = (
tag("classes"),
space0,
tag("="),
space0,
separated_list0(tag(","), alphanumeric1),
))(input)?;
)
.parse(input)?;

let class_vec = classes.into_iter().map(|s| s.to_string()).collect();
Ok((input, class_vec))
}

fn parse_module(input: &str) -> IResult<&str, (String, Option<String>)> {
let (input, (_, module, direction, _)) =
tuple((tag("["), alpha1, opt(preceded(tag(":"), alpha1)), tag("]")))(input)?;
(tag("["), alpha1, opt(preceded(tag(":"), alpha1)), tag("]")).parse(input)?;
let module_str = module.to_string();
let direction_str = direction.map(|s| s.to_string());

Ok((input, (module_str, direction_str)))
}

fn parse_ua_os(input: &str) -> IResult<&str, Vec<(String, Option<String>)>> {
let (input, (_, _, _, _, values)) = tuple((
let (input, (_, _, _, _, values)) = (
tag("ua_os"),
space0,
tag("="),
space0,
separated_list0(tag(","), parse_key_value),
))(input)?;
)
.parse(input)?;

let result = values
.into_iter()
Expand All @@ -248,17 +250,18 @@ fn parse_ua_os(input: &str) -> IResult<&str, Vec<(String, Option<String>)>> {
}

fn parse_key_value(input: &str) -> IResult<&str, (&str, Option<&str>)> {
let (input, (name, _, value)) = tuple((
let (input, (name, _, value)) = (
alphanumeric1,
space0,
opt(preceded(tuple((space0, tag("="), space0)), alphanumeric1)),
))(input)?;
opt(preceded((space0, tag("="), space0), alphanumeric1)),
)
.parse(input)?;

Ok((input, (name, value)))
}

fn parse_label(input: &str) -> IResult<&str, Label> {
let (input, (ty, _, class, _, name, flavor)) = tuple((
let (input, (ty, _, class, _, name, flavor)) = (
parse_type,
tag(":"),
alt((
Expand All @@ -268,7 +271,8 @@ fn parse_label(input: &str) -> IResult<&str, Label> {
tag(":"),
take_until(":"),
opt(preceded(tag(":"), rest)),
))(input)?;
)
.parse(input)?;

Ok((
input,
Expand All @@ -285,14 +289,15 @@ fn parse_type(input: &str) -> IResult<&str, Type> {
alt((
tag("s").map(|_| Type::Specified),
tag("g").map(|_| Type::Generic),
))(input)
))
.parse(input)
}

fn parse_tcp_signature(input: &str) -> IResult<&str, TcpSignature> {
let (
input,
(version, _, ittl, _, olen, _, mss, _, wsize, _, wscale, _, olayout, _, quirks, _, pclass),
) = tuple((
) = (
parse_ip_version,
tag(":"),
parse_ttl,
Expand All @@ -316,7 +321,8 @@ fn parse_tcp_signature(input: &str) -> IResult<&str, TcpSignature> {
separated_list0(tag(","), parse_quirk),
tag(":"),
parse_payload_size,
))(input)?;
)
.parse(input)?;

Ok((
input,
Expand All @@ -339,7 +345,8 @@ fn parse_ip_version(input: &str) -> IResult<&str, IpVersion> {
map(tag("4"), |_| IpVersion::V4),
map(tag("6"), |_| IpVersion::V6),
map(tag("*"), |_| IpVersion::Any),
))(input)
))
.parse(input)
}

fn parse_ttl(input: &str) -> IResult<&str, Ttl> {
Expand All @@ -362,7 +369,8 @@ fn parse_ttl(input: &str) -> IResult<&str, Ttl> {
},
),
map_res(digit1, |s: &str| s.parse::<u8>().map(Ttl::Value)),
))(input)
))
.parse(input)
}

fn parse_window_size(input: &str) -> IResult<&str, WindowSize> {
Expand All @@ -378,7 +386,8 @@ fn parse_window_size(input: &str) -> IResult<&str, WindowSize> {
s.parse::<u16>().map(WindowSize::Mod)
}),
map_res(digit1, |s: &str| s.parse::<u16>().map(WindowSize::Value)),
))(input)
))
.parse(input)
}

fn parse_tcp_option(input: &str) -> IResult<&str, TcpOption> {
Expand All @@ -397,7 +406,8 @@ fn parse_tcp_option(input: &str) -> IResult<&str, TcpOption> {
map(digit1, |s: &str| s.parse::<u8>().unwrap_or(0)),
)
.map(TcpOption::Unknown),
))(input)
))
.parse(input)
}

fn parse_quirk(input: &str) -> IResult<&str, Quirk> {
Expand All @@ -419,27 +429,30 @@ fn parse_quirk(input: &str) -> IResult<&str, Quirk> {
map(tag("opt+"), |_| Quirk::TrailinigNonZero),
map(tag("exws"), |_| Quirk::ExcessiveWindowScaling),
map(tag("bad"), |_| Quirk::OptBad),
))(input)
))
.parse(input)
}

fn parse_payload_size(input: &str) -> IResult<&str, PayloadSize> {
alt((
map(tag("0"), |_| PayloadSize::Zero),
map(tag("+"), |_| PayloadSize::NonZero),
map(tag("*"), |_| PayloadSize::Any),
))(input)
))
.parse(input)
}

fn parse_http_signature(input: &str) -> IResult<&str, HttpSignature> {
let (input, (version, _, horder, _, habsent, _, expsw)) = tuple((
let (input, (version, _, horder, _, habsent, _, expsw)) = (
parse_http_version,
tag(":"),
separated_list1(tag(","), parse_http_header),
tag(":"),
opt(separated_list0(tag(","), parse_http_header)),
tag(":"),
rest,
))(input)?;
)
.parse(input)?;

let habsent = habsent
.unwrap_or_default()
Expand All @@ -463,18 +476,20 @@ fn parse_http_version(input: &str) -> IResult<&str, HttpVersion> {
map(tag("0"), |_| HttpVersion::V10),
map(tag("1"), |_| HttpVersion::V11),
map(tag("*"), |_| HttpVersion::Any),
))(input)
))
.parse(input)
}

fn parse_header_key_value(input: &str) -> IResult<&str, (&str, Option<&str>)> {
pair(
take_while(|c: char| (c.is_ascii_alphanumeric() || c == '-') && c != ':' && c != '='),
opt(preceded(tag("=["), terminated(take_until("]"), char(']')))),
)(input)
)
.parse(input)
}

fn parse_http_header(input: &str) -> IResult<&str, HttpHeader> {
let (input, optional) = opt(char('?'))(input)?;
let (input, optional) = opt(char('?')).parse(input)?;
let (input, (name, value)) = parse_header_key_value(input)?;

Ok((
Expand Down

0 comments on commit 3cec9fc

Please sign in to comment.