Coverage Report

Created: 2026-06-07 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/rust/src/detect/uint.rs
Line
Count
Source
1
/* Copyright (C) 2022 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17
18
use nom7::branch::alt;
19
use nom7::bytes::complete::{is_a, tag, tag_no_case, take_while};
20
use nom7::character::complete::digit1;
21
use nom7::combinator::{all_consuming, map_opt, opt, value, verify};
22
use nom7::error::{make_error, ErrorKind};
23
use nom7::Err;
24
use nom7::IResult;
25
26
use std::ffi::CStr;
27
28
#[derive(PartialEq, Eq, Clone, Debug)]
29
#[repr(u8)]
30
pub enum DetectUintMode {
31
    DetectUintModeEqual,
32
    DetectUintModeLt,
33
    DetectUintModeLte,
34
    DetectUintModeGt,
35
    DetectUintModeGte,
36
    DetectUintModeRange,
37
    DetectUintModeNe,
38
}
39
40
#[derive(Debug)]
41
#[repr(C)]
42
pub struct DetectUintData<T> {
43
    pub arg1: T,
44
    pub arg2: T,
45
    pub mode: DetectUintMode,
46
}
47
48
pub trait DetectIntType:
49
    std::str::FromStr
50
    + std::cmp::PartialOrd
51
    + num::PrimInt
52
    + num::Bounded
53
    + num::ToPrimitive
54
    + num::FromPrimitive
55
{
56
}
57
impl<T> DetectIntType for T where
58
    T: std::str::FromStr
59
        + std::cmp::PartialOrd
60
        + num::PrimInt
61
        + num::Bounded
62
        + num::ToPrimitive
63
        + num::FromPrimitive
64
{
65
}
66
67
86.2k
pub fn detect_parse_uint_unit(i: &str) -> IResult<&str, u64> {
68
86.2k
    let (i, unit) = alt((
69
86.2k
        value(1024, tag_no_case("kb")),
70
86.2k
        value(1024 * 1024, tag_no_case("mb")),
71
86.2k
        value(1024 * 1024 * 1024, tag_no_case("gb")),
72
86.2k
    ))(i)?;
73
1.86k
    return Ok((i, unit));
74
86.2k
}
75
76
158k
pub fn detect_parse_uint_with_unit<T: DetectIntType>(i: &str) -> IResult<&str, T> {
77
158k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_with_unit::<u8>::{closure#0}
Line
Count
Source
77
25.6k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_with_unit::<u32>::{closure#0}
Line
Count
Source
77
23.4k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_with_unit::<u16>::{closure#0}
Line
Count
Source
77
21.1k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_with_unit::<u64>::{closure#0}
Line
Count
Source
77
19.2k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
78
86.2k
    let (i, unit) = opt(detect_parse_uint_unit)(i)?;
79
86.2k
    if arg1 >= T::one() {
80
79.5k
        if let Some(u) = unit {
81
1.01k
            if T::max_value().to_u64().unwrap() / u < arg1.to_u64().unwrap() {
82
103
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
83
908
            }
84
908
            let ru64 = arg1 * T::from_u64(u).unwrap();
85
908
            return Ok((i, ru64));
86
78.5k
        }
87
6.77k
    }
88
85.2k
    Ok((i, arg1))
89
158k
}
suricata::detect::uint::detect_parse_uint_with_unit::<u8>
Line
Count
Source
76
36.6k
pub fn detect_parse_uint_with_unit<T: DetectIntType>(i: &str) -> IResult<&str, T> {
77
36.6k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
78
24.6k
    let (i, unit) = opt(detect_parse_uint_unit)(i)?;
79
24.6k
    if arg1 >= T::one() {
80
23.8k
        if let Some(u) = unit {
81
88
            if T::max_value().to_u64().unwrap() / u < arg1.to_u64().unwrap() {
82
88
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
83
0
            }
84
0
            let ru64 = arg1 * T::from_u64(u).unwrap();
85
0
            return Ok((i, ru64));
86
23.8k
        }
87
748
    }
88
24.5k
    Ok((i, arg1))
89
36.6k
}
suricata::detect::uint::detect_parse_uint_with_unit::<u32>
Line
Count
Source
76
51.5k
pub fn detect_parse_uint_with_unit<T: DetectIntType>(i: &str) -> IResult<&str, T> {
77
51.5k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
78
22.6k
    let (i, unit) = opt(detect_parse_uint_unit)(i)?;
79
22.6k
    if arg1 >= T::one() {
80
21.9k
        if let Some(u) = unit {
81
104
            if T::max_value().to_u64().unwrap() / u < arg1.to_u64().unwrap() {
82
8
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
83
96
            }
84
96
            let ru64 = arg1 * T::from_u64(u).unwrap();
85
96
            return Ok((i, ru64));
86
21.8k
        }
87
738
    }
88
22.5k
    Ok((i, arg1))
89
51.5k
}
suricata::detect::uint::detect_parse_uint_with_unit::<u16>
Line
Count
Source
76
35.7k
pub fn detect_parse_uint_with_unit<T: DetectIntType>(i: &str) -> IResult<&str, T> {
77
35.7k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
78
19.7k
    let (i, unit) = opt(detect_parse_uint_unit)(i)?;
79
19.7k
    if arg1 >= T::one() {
80
15.6k
        if let Some(u) = unit {
81
99
            if T::max_value().to_u64().unwrap() / u < arg1.to_u64().unwrap() {
82
3
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
83
96
            }
84
96
            let ru64 = arg1 * T::from_u64(u).unwrap();
85
96
            return Ok((i, ru64));
86
15.5k
        }
87
4.17k
    }
88
19.6k
    Ok((i, arg1))
89
35.7k
}
suricata::detect::uint::detect_parse_uint_with_unit::<u64>
Line
Count
Source
76
34.1k
pub fn detect_parse_uint_with_unit<T: DetectIntType>(i: &str) -> IResult<&str, T> {
77
34.1k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
78
19.1k
    let (i, unit) = opt(detect_parse_uint_unit)(i)?;
79
19.1k
    if arg1 >= T::one() {
80
18.0k
        if let Some(u) = unit {
81
720
            if T::max_value().to_u64().unwrap() / u < arg1.to_u64().unwrap() {
82
4
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
83
716
            }
84
716
            let ru64 = arg1 * T::from_u64(u).unwrap();
85
716
            return Ok((i, ru64));
86
17.3k
        }
87
1.10k
    }
88
18.4k
    Ok((i, arg1))
89
34.1k
}
90
91
158k
pub fn detect_parse_uint_start_equal<T: DetectIntType>(
92
158k
    i: &str,
93
158k
) -> IResult<&str, DetectUintData<T>> {
94
158k
    let (i, _) = opt(tag("="))(i)?;
95
158k
    let (i, _) = opt(is_a(" "))(i)?;
96
158k
    let (i, arg1) = detect_parse_uint_with_unit(i)?;
97
86.1k
    Ok((
98
86.1k
        i,
99
86.1k
        DetectUintData {
100
86.1k
            arg1,
101
86.1k
            arg2: T::min_value(),
102
86.1k
            mode: DetectUintMode::DetectUintModeEqual,
103
86.1k
        },
104
86.1k
    ))
105
158k
}
suricata::detect::uint::detect_parse_uint_start_equal::<u8>
Line
Count
Source
91
36.6k
pub fn detect_parse_uint_start_equal<T: DetectIntType>(
92
36.6k
    i: &str,
93
36.6k
) -> IResult<&str, DetectUintData<T>> {
94
36.6k
    let (i, _) = opt(tag("="))(i)?;
95
36.6k
    let (i, _) = opt(is_a(" "))(i)?;
96
36.6k
    let (i, arg1) = detect_parse_uint_with_unit(i)?;
97
24.5k
    Ok((
98
24.5k
        i,
99
24.5k
        DetectUintData {
100
24.5k
            arg1,
101
24.5k
            arg2: T::min_value(),
102
24.5k
            mode: DetectUintMode::DetectUintModeEqual,
103
24.5k
        },
104
24.5k
    ))
105
36.6k
}
suricata::detect::uint::detect_parse_uint_start_equal::<u32>
Line
Count
Source
91
51.5k
pub fn detect_parse_uint_start_equal<T: DetectIntType>(
92
51.5k
    i: &str,
93
51.5k
) -> IResult<&str, DetectUintData<T>> {
94
51.5k
    let (i, _) = opt(tag("="))(i)?;
95
51.5k
    let (i, _) = opt(is_a(" "))(i)?;
96
51.5k
    let (i, arg1) = detect_parse_uint_with_unit(i)?;
97
22.6k
    Ok((
98
22.6k
        i,
99
22.6k
        DetectUintData {
100
22.6k
            arg1,
101
22.6k
            arg2: T::min_value(),
102
22.6k
            mode: DetectUintMode::DetectUintModeEqual,
103
22.6k
        },
104
22.6k
    ))
105
51.5k
}
suricata::detect::uint::detect_parse_uint_start_equal::<u16>
Line
Count
Source
91
35.7k
pub fn detect_parse_uint_start_equal<T: DetectIntType>(
92
35.7k
    i: &str,
93
35.7k
) -> IResult<&str, DetectUintData<T>> {
94
35.7k
    let (i, _) = opt(tag("="))(i)?;
95
35.7k
    let (i, _) = opt(is_a(" "))(i)?;
96
35.7k
    let (i, arg1) = detect_parse_uint_with_unit(i)?;
97
19.7k
    Ok((
98
19.7k
        i,
99
19.7k
        DetectUintData {
100
19.7k
            arg1,
101
19.7k
            arg2: T::min_value(),
102
19.7k
            mode: DetectUintMode::DetectUintModeEqual,
103
19.7k
        },
104
19.7k
    ))
105
35.7k
}
suricata::detect::uint::detect_parse_uint_start_equal::<u64>
Line
Count
Source
91
34.1k
pub fn detect_parse_uint_start_equal<T: DetectIntType>(
92
34.1k
    i: &str,
93
34.1k
) -> IResult<&str, DetectUintData<T>> {
94
34.1k
    let (i, _) = opt(tag("="))(i)?;
95
34.1k
    let (i, _) = opt(is_a(" "))(i)?;
96
34.1k
    let (i, arg1) = detect_parse_uint_with_unit(i)?;
97
19.1k
    Ok((
98
19.1k
        i,
99
19.1k
        DetectUintData {
100
19.1k
            arg1,
101
19.1k
            arg2: T::min_value(),
102
19.1k
            mode: DetectUintMode::DetectUintModeEqual,
103
19.1k
        },
104
19.1k
    ))
105
34.1k
}
106
107
149k
pub fn detect_parse_uint_start_interval<T: DetectIntType>(
108
149k
    i: &str,
109
149k
) -> IResult<&str, DetectUintData<T>> {
110
149k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_start_interval::<u8>::{closure#0}
Line
Count
Source
110
26.0k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_start_interval::<u32>::{closure#0}
Line
Count
Source
110
13.6k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_start_interval::<u16>::{closure#0}
Line
Count
Source
110
22.6k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_start_interval::<u64>::{closure#0}
Line
Count
Source
110
26.1k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
111
86.0k
    let (i, _) = opt(is_a(" "))(i)?;
112
86.0k
    let (i, _) = alt((tag("-"), tag("<>")))(i)?;
113
15.2k
    let (i, _) = opt(is_a(" "))(i)?;
114
15.2k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
suricata::detect::uint::detect_parse_uint_start_interval::<u8>::{closure#1}
Line
Count
Source
114
2.14k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
suricata::detect::uint::detect_parse_uint_start_interval::<u32>::{closure#1}
Line
Count
Source
114
1.29k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
suricata::detect::uint::detect_parse_uint_start_interval::<u16>::{closure#1}
Line
Count
Source
114
2.40k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
suricata::detect::uint::detect_parse_uint_start_interval::<u64>::{closure#1}
Line
Count
Source
114
7.73k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
12.5k
        x > &arg1 && *x - arg1 > T::one()
116
15.2k
    })(i)?;
suricata::detect::uint::detect_parse_uint_start_interval::<u8>::{closure#2}
Line
Count
Source
114
1.55k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
1.55k
        x > &arg1 && *x - arg1 > T::one()
116
1.55k
    })(i)?;
suricata::detect::uint::detect_parse_uint_start_interval::<u32>::{closure#2}
Line
Count
Source
114
1.27k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
1.27k
        x > &arg1 && *x - arg1 > T::one()
116
1.27k
    })(i)?;
suricata::detect::uint::detect_parse_uint_start_interval::<u16>::{closure#2}
Line
Count
Source
114
2.01k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
2.01k
        x > &arg1 && *x - arg1 > T::one()
116
2.01k
    })(i)?;
suricata::detect::uint::detect_parse_uint_start_interval::<u64>::{closure#2}
Line
Count
Source
114
7.72k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
7.72k
        x > &arg1 && *x - arg1 > T::one()
116
7.72k
    })(i)?;
117
11.5k
    Ok((
118
11.5k
        i,
119
11.5k
        DetectUintData {
120
11.5k
            arg1,
121
11.5k
            arg2,
122
11.5k
            mode: DetectUintMode::DetectUintModeRange,
123
11.5k
        },
124
11.5k
    ))
125
149k
}
suricata::detect::uint::detect_parse_uint_start_interval::<u8>
Line
Count
Source
107
37.9k
pub fn detect_parse_uint_start_interval<T: DetectIntType>(
108
37.9k
    i: &str,
109
37.9k
) -> IResult<&str, DetectUintData<T>> {
110
37.9k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
111
25.0k
    let (i, _) = opt(is_a(" "))(i)?;
112
25.0k
    let (i, _) = alt((tag("-"), tag("<>")))(i)?;
113
2.42k
    let (i, _) = opt(is_a(" "))(i)?;
114
2.42k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
        x > &arg1 && *x - arg1 > T::one()
116
2.42k
    })(i)?;
117
1.29k
    Ok((
118
1.29k
        i,
119
1.29k
        DetectUintData {
120
1.29k
            arg1,
121
1.29k
            arg2,
122
1.29k
            mode: DetectUintMode::DetectUintModeRange,
123
1.29k
        },
124
1.29k
    ))
125
37.9k
}
suricata::detect::uint::detect_parse_uint_start_interval::<u32>
Line
Count
Source
107
32.7k
pub fn detect_parse_uint_start_interval<T: DetectIntType>(
108
32.7k
    i: &str,
109
32.7k
) -> IResult<&str, DetectUintData<T>> {
110
32.7k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
111
13.6k
    let (i, _) = opt(is_a(" "))(i)?;
112
13.6k
    let (i, _) = alt((tag("-"), tag("<>")))(i)?;
113
2.38k
    let (i, _) = opt(is_a(" "))(i)?;
114
2.38k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
        x > &arg1 && *x - arg1 > T::one()
116
2.38k
    })(i)?;
117
1.17k
    Ok((
118
1.17k
        i,
119
1.17k
        DetectUintData {
120
1.17k
            arg1,
121
1.17k
            arg2,
122
1.17k
            mode: DetectUintMode::DetectUintModeRange,
123
1.17k
        },
124
1.17k
    ))
125
32.7k
}
suricata::detect::uint::detect_parse_uint_start_interval::<u16>
Line
Count
Source
107
37.4k
pub fn detect_parse_uint_start_interval<T: DetectIntType>(
108
37.4k
    i: &str,
109
37.4k
) -> IResult<&str, DetectUintData<T>> {
110
37.4k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
111
21.2k
    let (i, _) = opt(is_a(" "))(i)?;
112
21.2k
    let (i, _) = alt((tag("-"), tag("<>")))(i)?;
113
2.61k
    let (i, _) = opt(is_a(" "))(i)?;
114
2.61k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
        x > &arg1 && *x - arg1 > T::one()
116
2.61k
    })(i)?;
117
1.73k
    Ok((
118
1.73k
        i,
119
1.73k
        DetectUintData {
120
1.73k
            arg1,
121
1.73k
            arg2,
122
1.73k
            mode: DetectUintMode::DetectUintModeRange,
123
1.73k
        },
124
1.73k
    ))
125
37.4k
}
suricata::detect::uint::detect_parse_uint_start_interval::<u64>
Line
Count
Source
107
41.4k
pub fn detect_parse_uint_start_interval<T: DetectIntType>(
108
41.4k
    i: &str,
109
41.4k
) -> IResult<&str, DetectUintData<T>> {
110
41.4k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
111
26.0k
    let (i, _) = opt(is_a(" "))(i)?;
112
26.0k
    let (i, _) = alt((tag("-"), tag("<>")))(i)?;
113
7.77k
    let (i, _) = opt(is_a(" "))(i)?;
114
7.77k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
115
        x > &arg1 && *x - arg1 > T::one()
116
7.77k
    })(i)?;
117
7.32k
    Ok((
118
7.32k
        i,
119
7.32k
        DetectUintData {
120
7.32k
            arg1,
121
7.32k
            arg2,
122
7.32k
            mode: DetectUintMode::DetectUintModeRange,
123
7.32k
        },
124
7.32k
    ))
125
41.4k
}
126
127
22.9k
fn detect_parse_uint_start_interval_inclusive<T: DetectIntType>(
128
22.9k
    i: &str,
129
22.9k
) -> IResult<&str, DetectUintData<T>> {
130
22.9k
    let (i, arg1) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
131
11.8k
        *x > T::min_value()
132
22.9k
    })(i)?;
133
11.8k
    let (i, _) = opt(is_a(" "))(i)?;
134
11.8k
    let (i, _) = alt((tag("-"), tag("<>")))(i)?;
135
6.83k
    let (i, _) = opt(is_a(" "))(i)?;
136
6.83k
    let (i, arg2) = verify(map_opt(digit1, |s: &str| s.parse::<T>().ok()), |x| {
137
6.58k
        *x > arg1 && *x < T::max_value()
138
6.83k
    })(i)?;
139
3.02k
    Ok((
140
3.02k
        i,
141
3.02k
        DetectUintData {
142
3.02k
            arg1: arg1 - T::one(),
143
3.02k
            arg2: arg2 + T::one(),
144
3.02k
            mode: DetectUintMode::DetectUintModeRange,
145
3.02k
        },
146
3.02k
    ))
147
22.9k
}
148
149
82.3k
pub fn detect_parse_uint_mode(i: &str) -> IResult<&str, DetectUintMode> {
150
82.3k
    let (i, mode) = alt((
151
82.3k
        value(DetectUintMode::DetectUintModeGte, tag(">=")),
152
82.3k
        value(DetectUintMode::DetectUintModeLte, tag("<=")),
153
82.3k
        value(DetectUintMode::DetectUintModeGt, tag(">")),
154
82.3k
        value(DetectUintMode::DetectUintModeLt, tag("<")),
155
82.3k
        value(DetectUintMode::DetectUintModeNe, tag("!=")),
156
82.3k
        value(DetectUintMode::DetectUintModeNe, tag("!")),
157
82.3k
        value(DetectUintMode::DetectUintModeEqual, tag("=")),
158
82.3k
    ))(i)?;
159
74.6k
    return Ok((i, mode));
160
82.3k
}
161
162
71.8k
fn detect_parse_uint_start_symbol<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
163
71.8k
    let (i, mode) = detect_parse_uint_mode(i)?;
164
64.1k
    let (i, _) = opt(is_a(" "))(i)?;
165
64.1k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_start_symbol::<u8>::{closure#0}
Line
Count
Source
165
8.95k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_start_symbol::<u32>::{closure#0}
Line
Count
Source
165
21.7k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_start_symbol::<u16>::{closure#0}
Line
Count
Source
165
13.9k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
suricata::detect::uint::detect_parse_uint_start_symbol::<u64>::{closure#0}
Line
Count
Source
165
13.0k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
166
167
57.3k
    match mode {
168
2.99k
        DetectUintMode::DetectUintModeNe => {}
169
        DetectUintMode::DetectUintModeLt => {
170
21.2k
            if arg1 == T::min_value() {
171
1.64k
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
172
19.5k
            }
173
        }
174
        DetectUintMode::DetectUintModeLte => {
175
1.69k
            if arg1 == T::max_value() {
176
4
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
177
1.68k
            }
178
        }
179
        DetectUintMode::DetectUintModeGt => {
180
28.1k
            if arg1 == T::max_value() {
181
40
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
182
28.1k
            }
183
        }
184
        DetectUintMode::DetectUintModeGte => {
185
3.27k
            if arg1 == T::min_value() {
186
8
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
187
3.26k
            }
188
        }
189
        _ => {
190
11
            return Err(Err::Error(make_error(i, ErrorKind::MapOpt)));
191
        }
192
    }
193
194
55.6k
    Ok((
195
55.6k
        i,
196
55.6k
        DetectUintData {
197
55.6k
            arg1,
198
55.6k
            arg2: T::min_value(),
199
55.6k
            mode,
200
55.6k
        },
201
55.6k
    ))
202
71.8k
}
suricata::detect::uint::detect_parse_uint_start_symbol::<u8>
Line
Count
Source
162
12.1k
fn detect_parse_uint_start_symbol<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
163
12.1k
    let (i, mode) = detect_parse_uint_mode(i)?;
164
10.4k
    let (i, _) = opt(is_a(" "))(i)?;
165
10.4k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
166
167
8.90k
    match mode {
168
1.18k
        DetectUintMode::DetectUintModeNe => {}
169
        DetectUintMode::DetectUintModeLt => {
170
5.07k
            if arg1 == T::min_value() {
171
1.47k
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
172
3.60k
            }
173
        }
174
        DetectUintMode::DetectUintModeLte => {
175
284
            if arg1 == T::max_value() {
176
1
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
177
283
            }
178
        }
179
        DetectUintMode::DetectUintModeGt => {
180
1.58k
            if arg1 == T::max_value() {
181
2
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
182
1.58k
            }
183
        }
184
        DetectUintMode::DetectUintModeGte => {
185
767
            if arg1 == T::min_value() {
186
1
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
187
766
            }
188
        }
189
        _ => {
190
3
            return Err(Err::Error(make_error(i, ErrorKind::MapOpt)));
191
        }
192
    }
193
194
7.42k
    Ok((
195
7.42k
        i,
196
7.42k
        DetectUintData {
197
7.42k
            arg1,
198
7.42k
            arg2: T::min_value(),
199
7.42k
            mode,
200
7.42k
        },
201
7.42k
    ))
202
12.1k
}
suricata::detect::uint::detect_parse_uint_start_symbol::<u32>
Line
Count
Source
162
28.8k
fn detect_parse_uint_start_symbol<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
163
28.8k
    let (i, mode) = detect_parse_uint_mode(i)?;
164
24.3k
    let (i, _) = opt(is_a(" "))(i)?;
165
24.3k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
166
167
21.6k
    match mode {
168
798
        DetectUintMode::DetectUintModeNe => {}
169
        DetectUintMode::DetectUintModeLt => {
170
3.39k
            if arg1 == T::min_value() {
171
15
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
172
3.38k
            }
173
        }
174
        DetectUintMode::DetectUintModeLte => {
175
276
            if arg1 == T::max_value() {
176
1
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
177
275
            }
178
        }
179
        DetectUintMode::DetectUintModeGt => {
180
16.9k
            if arg1 == T::max_value() {
181
1
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
182
16.9k
            }
183
        }
184
        DetectUintMode::DetectUintModeGte => {
185
211
            if arg1 == T::min_value() {
186
2
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
187
209
            }
188
        }
189
        _ => {
190
5
            return Err(Err::Error(make_error(i, ErrorKind::MapOpt)));
191
        }
192
    }
193
194
21.6k
    Ok((
195
21.6k
        i,
196
21.6k
        DetectUintData {
197
21.6k
            arg1,
198
21.6k
            arg2: T::min_value(),
199
21.6k
            mode,
200
21.6k
        },
201
21.6k
    ))
202
28.8k
}
suricata::detect::uint::detect_parse_uint_start_symbol::<u16>
Line
Count
Source
162
15.9k
fn detect_parse_uint_start_symbol<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
163
15.9k
    let (i, mode) = detect_parse_uint_mode(i)?;
164
14.5k
    let (i, _) = opt(is_a(" "))(i)?;
165
14.5k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
166
167
13.7k
    match mode {
168
278
        DetectUintMode::DetectUintModeNe => {}
169
        DetectUintMode::DetectUintModeLt => {
170
6.19k
            if arg1 == T::min_value() {
171
154
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
172
6.04k
            }
173
        }
174
        DetectUintMode::DetectUintModeLte => {
175
875
            if arg1 == T::max_value() {
176
1
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
177
874
            }
178
        }
179
        DetectUintMode::DetectUintModeGt => {
180
4.22k
            if arg1 == T::max_value() {
181
34
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
182
4.18k
            }
183
        }
184
        DetectUintMode::DetectUintModeGte => {
185
2.16k
            if arg1 == T::min_value() {
186
3
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
187
2.16k
            }
188
        }
189
        _ => {
190
1
            return Err(Err::Error(make_error(i, ErrorKind::MapOpt)));
191
        }
192
    }
193
194
13.5k
    Ok((
195
13.5k
        i,
196
13.5k
        DetectUintData {
197
13.5k
            arg1,
198
13.5k
            arg2: T::min_value(),
199
13.5k
            mode,
200
13.5k
        },
201
13.5k
    ))
202
15.9k
}
suricata::detect::uint::detect_parse_uint_start_symbol::<u64>
Line
Count
Source
162
14.9k
fn detect_parse_uint_start_symbol<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
163
14.9k
    let (i, mode) = detect_parse_uint_mode(i)?;
164
14.7k
    let (i, _) = opt(is_a(" "))(i)?;
165
14.7k
    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().ok())(i)?;
166
167
13.0k
    match mode {
168
726
        DetectUintMode::DetectUintModeNe => {}
169
        DetectUintMode::DetectUintModeLt => {
170
6.56k
            if arg1 == T::min_value() {
171
9
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
172
6.56k
            }
173
        }
174
        DetectUintMode::DetectUintModeLte => {
175
258
            if arg1 == T::max_value() {
176
1
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
177
257
            }
178
        }
179
        DetectUintMode::DetectUintModeGt => {
180
5.39k
            if arg1 == T::max_value() {
181
3
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
182
5.38k
            }
183
        }
184
        DetectUintMode::DetectUintModeGte => {
185
127
            if arg1 == T::min_value() {
186
2
                return Err(Err::Error(make_error(i, ErrorKind::Verify)));
187
125
            }
188
        }
189
        _ => {
190
2
            return Err(Err::Error(make_error(i, ErrorKind::MapOpt)));
191
        }
192
    }
193
194
13.0k
    Ok((
195
13.0k
        i,
196
13.0k
        DetectUintData {
197
13.0k
            arg1,
198
13.0k
            arg2: T::min_value(),
199
13.0k
            mode,
200
13.0k
        },
201
13.0k
    ))
202
14.9k
}
203
204
87.8k
pub fn detect_match_uint<T: DetectIntType>(x: &DetectUintData<T>, val: T) -> bool {
205
87.8k
    match x.mode {
206
        DetectUintMode::DetectUintModeEqual => {
207
58.3k
            if val == x.arg1 {
208
5.55k
                return true;
209
52.8k
            }
210
        }
211
        DetectUintMode::DetectUintModeNe => {
212
268
            if val != x.arg1 {
213
268
                return true;
214
0
            }
215
        }
216
        DetectUintMode::DetectUintModeLt => {
217
16.3k
            if val < x.arg1 {
218
9.98k
                return true;
219
6.32k
            }
220
        }
221
        DetectUintMode::DetectUintModeLte => {
222
482
            if val <= x.arg1 {
223
482
                return true;
224
0
            }
225
        }
226
        DetectUintMode::DetectUintModeGt => {
227
7.23k
            if val > x.arg1 {
228
2.59k
                return true;
229
4.64k
            }
230
        }
231
        DetectUintMode::DetectUintModeGte => {
232
547
            if val >= x.arg1 {
233
519
                return true;
234
28
            }
235
        }
236
        DetectUintMode::DetectUintModeRange => {
237
4.61k
            if val > x.arg1 && val < x.arg2 {
238
3.83k
                return true;
239
778
            }
240
        }
241
    }
242
64.5k
    return false;
243
87.8k
}
suricata::detect::uint::detect_match_uint::<u8>
Line
Count
Source
204
53.5k
pub fn detect_match_uint<T: DetectIntType>(x: &DetectUintData<T>, val: T) -> bool {
205
53.5k
    match x.mode {
206
        DetectUintMode::DetectUintModeEqual => {
207
53.2k
            if val == x.arg1 {
208
1.57k
                return true;
209
51.6k
            }
210
        }
211
        DetectUintMode::DetectUintModeNe => {
212
0
            if val != x.arg1 {
213
0
                return true;
214
0
            }
215
        }
216
        DetectUintMode::DetectUintModeLt => {
217
241
            if val < x.arg1 {
218
17
                return true;
219
224
            }
220
        }
221
        DetectUintMode::DetectUintModeLte => {
222
0
            if val <= x.arg1 {
223
0
                return true;
224
0
            }
225
        }
226
        DetectUintMode::DetectUintModeGt => {
227
13
            if val > x.arg1 {
228
8
                return true;
229
5
            }
230
        }
231
        DetectUintMode::DetectUintModeGte => {
232
0
            if val >= x.arg1 {
233
0
                return true;
234
0
            }
235
        }
236
        DetectUintMode::DetectUintModeRange => {
237
19
            if val > x.arg1 && val < x.arg2 {
238
10
                return true;
239
9
            }
240
        }
241
    }
242
51.9k
    return false;
243
53.5k
}
suricata::detect::uint::detect_match_uint::<u32>
Line
Count
Source
204
22.2k
pub fn detect_match_uint<T: DetectIntType>(x: &DetectUintData<T>, val: T) -> bool {
205
22.2k
    match x.mode {
206
        DetectUintMode::DetectUintModeEqual => {
207
4.44k
            if val == x.arg1 {
208
3.49k
                return true;
209
944
            }
210
        }
211
        DetectUintMode::DetectUintModeNe => {
212
0
            if val != x.arg1 {
213
0
                return true;
214
0
            }
215
        }
216
        DetectUintMode::DetectUintModeLt => {
217
7.87k
            if val < x.arg1 {
218
5.60k
                return true;
219
2.27k
            }
220
        }
221
        DetectUintMode::DetectUintModeLte => {
222
0
            if val <= x.arg1 {
223
0
                return true;
224
0
            }
225
        }
226
        DetectUintMode::DetectUintModeGt => {
227
5.55k
            if val > x.arg1 {
228
1.44k
                return true;
229
4.10k
            }
230
        }
231
        DetectUintMode::DetectUintModeGte => {
232
0
            if val >= x.arg1 {
233
0
                return true;
234
0
            }
235
        }
236
        DetectUintMode::DetectUintModeRange => {
237
4.39k
            if val > x.arg1 && val < x.arg2 {
238
3.69k
                return true;
239
705
            }
240
        }
241
    }
242
8.02k
    return false;
243
22.2k
}
suricata::detect::uint::detect_match_uint::<u16>
Line
Count
Source
204
10.9k
pub fn detect_match_uint<T: DetectIntType>(x: &DetectUintData<T>, val: T) -> bool {
205
10.9k
    match x.mode {
206
        DetectUintMode::DetectUintModeEqual => {
207
475
            if val == x.arg1 {
208
475
                return true;
209
0
            }
210
        }
211
        DetectUintMode::DetectUintModeNe => {
212
268
            if val != x.arg1 {
213
268
                return true;
214
0
            }
215
        }
216
        DetectUintMode::DetectUintModeLt => {
217
8.14k
            if val < x.arg1 {
218
4.34k
                return true;
219
3.79k
            }
220
        }
221
        DetectUintMode::DetectUintModeLte => {
222
482
            if val <= x.arg1 {
223
482
                return true;
224
0
            }
225
        }
226
        DetectUintMode::DetectUintModeGt => {
227
1.01k
            if val > x.arg1 {
228
1.01k
                return true;
229
1
            }
230
        }
231
        DetectUintMode::DetectUintModeGte => {
232
546
            if val >= x.arg1 {
233
518
                return true;
234
28
            }
235
        }
236
        DetectUintMode::DetectUintModeRange => {
237
13
            if val > x.arg1 && val < x.arg2 {
238
7
                return true;
239
6
            }
240
        }
241
    }
242
3.83k
    return false;
243
10.9k
}
suricata::detect::uint::detect_match_uint::<u64>
Line
Count
Source
204
1.08k
pub fn detect_match_uint<T: DetectIntType>(x: &DetectUintData<T>, val: T) -> bool {
205
1.08k
    match x.mode {
206
        DetectUintMode::DetectUintModeEqual => {
207
194
            if val == x.arg1 {
208
11
                return true;
209
183
            }
210
        }
211
        DetectUintMode::DetectUintModeNe => {
212
0
            if val != x.arg1 {
213
0
                return true;
214
0
            }
215
        }
216
        DetectUintMode::DetectUintModeLt => {
217
52
            if val < x.arg1 {
218
20
                return true;
219
32
            }
220
        }
221
        DetectUintMode::DetectUintModeLte => {
222
0
            if val <= x.arg1 {
223
0
                return true;
224
0
            }
225
        }
226
        DetectUintMode::DetectUintModeGt => {
227
655
            if val > x.arg1 {
228
126
                return true;
229
529
            }
230
        }
231
        DetectUintMode::DetectUintModeGte => {
232
1
            if val >= x.arg1 {
233
1
                return true;
234
0
            }
235
        }
236
        DetectUintMode::DetectUintModeRange => {
237
187
            if val > x.arg1 && val < x.arg2 {
238
129
                return true;
239
58
            }
240
        }
241
    }
242
802
    return false;
243
1.08k
}
244
245
149k
pub fn detect_parse_uint_notending<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
246
149k
    let (i, _) = opt(is_a(" "))(i)?;
247
149k
    let (i, uint) = alt((
248
149k
        detect_parse_uint_start_interval,
249
149k
        detect_parse_uint_start_equal,
250
149k
        detect_parse_uint_start_symbol,
251
149k
    ))(i)?;
252
136k
    Ok((i, uint))
253
149k
}
suricata::detect::uint::detect_parse_uint_notending::<u8>
Line
Count
Source
245
37.9k
pub fn detect_parse_uint_notending<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
246
37.9k
    let (i, _) = opt(is_a(" "))(i)?;
247
37.9k
    let (i, uint) = alt((
248
37.9k
        detect_parse_uint_start_interval,
249
37.9k
        detect_parse_uint_start_equal,
250
37.9k
        detect_parse_uint_start_symbol,
251
37.9k
    ))(i)?;
252
33.2k
    Ok((i, uint))
253
37.9k
}
suricata::detect::uint::detect_parse_uint_notending::<u32>
Line
Count
Source
245
32.7k
pub fn detect_parse_uint_notending<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
246
32.7k
    let (i, _) = opt(is_a(" "))(i)?;
247
32.7k
    let (i, uint) = alt((
248
32.7k
        detect_parse_uint_start_interval,
249
32.7k
        detect_parse_uint_start_equal,
250
32.7k
        detect_parse_uint_start_symbol,
251
32.7k
    ))(i)?;
252
28.8k
    Ok((i, uint))
253
32.7k
}
suricata::detect::uint::detect_parse_uint_notending::<u16>
Line
Count
Source
245
37.4k
pub fn detect_parse_uint_notending<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
246
37.4k
    let (i, _) = opt(is_a(" "))(i)?;
247
37.4k
    let (i, uint) = alt((
248
37.4k
        detect_parse_uint_start_interval,
249
37.4k
        detect_parse_uint_start_equal,
250
37.4k
        detect_parse_uint_start_symbol,
251
37.4k
    ))(i)?;
252
35.0k
    Ok((i, uint))
253
37.4k
}
suricata::detect::uint::detect_parse_uint_notending::<u64>
Line
Count
Source
245
41.4k
pub fn detect_parse_uint_notending<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
246
41.4k
    let (i, _) = opt(is_a(" "))(i)?;
247
41.4k
    let (i, uint) = alt((
248
41.4k
        detect_parse_uint_start_interval,
249
41.4k
        detect_parse_uint_start_equal,
250
41.4k
        detect_parse_uint_start_symbol,
251
41.4k
    ))(i)?;
252
39.5k
    Ok((i, uint))
253
41.4k
}
254
255
146k
pub fn detect_parse_uint<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
256
146k
    let (i, uint) = detect_parse_uint_notending(i)?;
257
134k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
suricata::detect::uint::detect_parse_uint::<u8>::{closure#0}
Line
Count
Source
257
3.46k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
suricata::detect::uint::detect_parse_uint::<u32>::{closure#0}
Line
Count
Source
257
3.44k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
suricata::detect::uint::detect_parse_uint::<u16>::{closure#0}
Line
Count
Source
257
995
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
suricata::detect::uint::detect_parse_uint::<u64>::{closure#0}
Line
Count
Source
257
4.52k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
258
123k
    Ok((i, uint))
259
146k
}
suricata::detect::uint::detect_parse_uint::<u8>
Line
Count
Source
255
37.9k
pub fn detect_parse_uint<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
256
37.9k
    let (i, uint) = detect_parse_uint_notending(i)?;
257
33.2k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
258
30.1k
    Ok((i, uint))
259
37.9k
}
suricata::detect::uint::detect_parse_uint::<u32>
Line
Count
Source
255
32.7k
pub fn detect_parse_uint<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
256
32.7k
    let (i, uint) = detect_parse_uint_notending(i)?;
257
28.8k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
258
25.9k
    Ok((i, uint))
259
32.7k
}
suricata::detect::uint::detect_parse_uint::<u16>
Line
Count
Source
255
34.3k
pub fn detect_parse_uint<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
256
34.3k
    let (i, uint) = detect_parse_uint_notending(i)?;
257
32.3k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
258
31.7k
    Ok((i, uint))
259
34.3k
}
suricata::detect::uint::detect_parse_uint::<u64>
Line
Count
Source
255
41.4k
pub fn detect_parse_uint<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
256
41.4k
    let (i, uint) = detect_parse_uint_notending(i)?;
257
39.5k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
258
35.2k
    Ok((i, uint))
259
41.4k
}
260
261
22.9k
pub fn detect_parse_uint_inclusive<T: DetectIntType>(i: &str) -> IResult<&str, DetectUintData<T>> {
262
22.9k
    let (i, _) = opt(is_a(" "))(i)?;
263
22.9k
    let (i, uint) = alt((
264
22.9k
        detect_parse_uint_start_interval_inclusive,
265
22.9k
        detect_parse_uint_start_equal,
266
22.9k
        detect_parse_uint_start_symbol,
267
22.9k
    ))(i)?;
268
19.6k
    let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?;
269
15.0k
    Ok((i, uint))
270
22.9k
}
271
272
#[no_mangle]
273
41.4k
pub unsafe extern "C" fn rs_detect_u64_parse(
274
41.4k
    ustr: *const std::os::raw::c_char,
275
41.4k
) -> *mut DetectUintData<u64> {
276
41.4k
    let ft_name: &CStr = CStr::from_ptr(ustr); //unsafe
277
41.4k
    if let Ok(s) = ft_name.to_str() {
278
41.4k
        if let Ok((_, ctx)) = detect_parse_uint::<u64>(s) {
279
35.2k
            let boxed = Box::new(ctx);
280
35.2k
            return Box::into_raw(boxed) as *mut _;
281
6.14k
        }
282
0
    }
283
6.14k
    return std::ptr::null_mut();
284
41.4k
}
285
286
#[no_mangle]
287
1.08k
pub unsafe extern "C" fn rs_detect_u64_match(
288
1.08k
    arg: u64, ctx: &DetectUintData<u64>,
289
1.08k
) -> std::os::raw::c_int {
290
1.08k
    if detect_match_uint(ctx, arg) {
291
287
        return 1;
292
802
    }
293
802
    return 0;
294
1.08k
}
295
296
#[no_mangle]
297
35.2k
pub unsafe extern "C" fn rs_detect_u64_free(ctx: *mut std::os::raw::c_void) {
298
    // Just unbox...
299
35.2k
    std::mem::drop(Box::from_raw(ctx as *mut DetectUintData<u64>));
300
35.2k
}
301
302
#[no_mangle]
303
27.8k
pub unsafe extern "C" fn rs_detect_u32_parse(
304
27.8k
    ustr: *const std::os::raw::c_char,
305
27.8k
) -> *mut DetectUintData<u32> {
306
27.8k
    let ft_name: &CStr = CStr::from_ptr(ustr); //unsafe
307
27.8k
    if let Ok(s) = ft_name.to_str() {
308
27.8k
        if let Ok((_, ctx)) = detect_parse_uint::<u32>(s) {
309
25.6k
            let boxed = Box::new(ctx);
310
25.6k
            return Box::into_raw(boxed) as *mut _;
311
2.25k
        }
312
0
    }
313
2.25k
    return std::ptr::null_mut();
314
27.8k
}
315
316
#[no_mangle]
317
22.9k
pub unsafe extern "C" fn rs_detect_u32_parse_inclusive(
318
22.9k
    ustr: *const std::os::raw::c_char,
319
22.9k
) -> *mut DetectUintData<u32> {
320
22.9k
    let ft_name: &CStr = CStr::from_ptr(ustr); //unsafe
321
22.9k
    if let Ok(s) = ft_name.to_str() {
322
22.9k
        if let Ok((_, ctx)) = detect_parse_uint_inclusive::<u32>(s) {
323
15.0k
            let boxed = Box::new(ctx);
324
15.0k
            return Box::into_raw(boxed) as *mut _;
325
7.95k
        }
326
0
    }
327
7.95k
    return std::ptr::null_mut();
328
22.9k
}
329
330
#[no_mangle]
331
22.2k
pub unsafe extern "C" fn rs_detect_u32_match(
332
22.2k
    arg: u32, ctx: &DetectUintData<u32>,
333
22.2k
) -> std::os::raw::c_int {
334
22.2k
    if detect_match_uint(ctx, arg) {
335
14.2k
        return 1;
336
8.02k
    }
337
8.02k
    return 0;
338
22.2k
}
339
340
#[no_mangle]
341
40.6k
pub unsafe extern "C" fn rs_detect_u32_free(ctx: &mut DetectUintData<u32>) {
342
    // Just unbox...
343
40.6k
    std::mem::drop(Box::from_raw(ctx));
344
40.6k
}
345
346
#[no_mangle]
347
37.9k
pub unsafe extern "C" fn rs_detect_u8_parse(
348
37.9k
    ustr: *const std::os::raw::c_char,
349
37.9k
) -> *mut DetectUintData<u8> {
350
37.9k
    let ft_name: &CStr = CStr::from_ptr(ustr); //unsafe
351
37.9k
    if let Ok(s) = ft_name.to_str() {
352
37.9k
        if let Ok((_, ctx)) = detect_parse_uint::<u8>(s) {
353
30.1k
            let boxed = Box::new(ctx);
354
30.1k
            return Box::into_raw(boxed) as *mut _;
355
7.82k
        }
356
0
    }
357
7.82k
    return std::ptr::null_mut();
358
37.9k
}
359
360
#[no_mangle]
361
53.5k
pub unsafe extern "C" fn rs_detect_u8_match(
362
53.5k
    arg: u8, ctx: &DetectUintData<u8>,
363
53.5k
) -> std::os::raw::c_int {
364
53.5k
    if detect_match_uint(ctx, arg) {
365
1.60k
        return 1;
366
51.9k
    }
367
51.9k
    return 0;
368
53.5k
}
369
370
#[no_mangle]
371
30.1k
pub unsafe extern "C" fn rs_detect_u8_free(ctx: &mut DetectUintData<u8>) {
372
    // Just unbox...
373
30.1k
    std::mem::drop(Box::from_raw(ctx));
374
30.1k
}
375
376
#[no_mangle]
377
34.3k
pub unsafe extern "C" fn rs_detect_u16_parse(
378
34.3k
    ustr: *const std::os::raw::c_char,
379
34.3k
) -> *mut DetectUintData<u16> {
380
34.3k
    let ft_name: &CStr = CStr::from_ptr(ustr); //unsafe
381
34.3k
    if let Ok(s) = ft_name.to_str() {
382
34.3k
        if let Ok((_, ctx)) = detect_parse_uint::<u16>(s) {
383
31.7k
            let boxed = Box::new(ctx);
384
31.7k
            return Box::into_raw(boxed) as *mut _;
385
2.66k
        }
386
0
    }
387
2.66k
    return std::ptr::null_mut();
388
34.3k
}
389
390
#[no_mangle]
391
10.9k
pub unsafe extern "C" fn rs_detect_u16_match(
392
10.9k
    arg: u16, ctx: &DetectUintData<u16>,
393
10.9k
) -> std::os::raw::c_int {
394
10.9k
    if detect_match_uint(ctx, arg) {
395
7.10k
        return 1;
396
3.83k
    }
397
3.83k
    return 0;
398
10.9k
}
399
400
#[no_mangle]
401
31.7k
pub unsafe extern "C" fn rs_detect_u16_free(ctx: &mut DetectUintData<u16>) {
402
    // Just unbox...
403
31.7k
    std::mem::drop(Box::from_raw(ctx));
404
31.7k
}
405
406
#[cfg(test)]
407
mod tests {
408
    use super::*;
409
410
    #[test]
411
    fn test_parse_uint_unit() {
412
        let (_, val) = detect_parse_uint::<u64>(" 2kb").unwrap();
413
        assert_eq!(val.arg1, 2048);
414
415
        assert!(detect_parse_uint::<u8>("2kb").is_err());
416
417
        let (_, val) = detect_parse_uint::<u32>("3MB").unwrap();
418
        assert_eq!(val.arg1, 3 * 1024 * 1024);
419
    }
420
}