Coverage Report

Created: 2025-12-31 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/rust/src/quic/error.rs
Line
Count
Source
1
/* Copyright (C) 2021 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::error::{ErrorKind, ParseError};
19
use std::error::Error;
20
use std::fmt;
21
22
#[derive(Debug, PartialEq, Eq)]
23
pub enum QuicError {
24
    StreamTagNoMatch(u32),
25
    InvalidPacket,
26
    Incomplete,
27
    Unhandled,
28
    NomError(ErrorKind),
29
}
30
31
impl<I> ParseError<I> for QuicError {
32
1.27M
    fn from_error_kind(_input: I, kind: ErrorKind) -> Self {
33
1.27M
        QuicError::NomError(kind)
34
1.27M
    }
35
36
4.35k
    fn append(_input: I, kind: ErrorKind, _other: Self) -> Self {
37
4.35k
        QuicError::NomError(kind)
38
4.35k
    }
39
}
40
41
impl fmt::Display for QuicError {
42
0
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43
0
        match self {
44
0
            QuicError::StreamTagNoMatch(tag) => {
45
0
                write!(f, "Could not match stream tag: 0x{:x}", tag)
46
            }
47
0
            QuicError::Incomplete => write!(f, "Incomplete data"),
48
0
            QuicError::InvalidPacket => write!(f, "Invalid packet"),
49
0
            QuicError::Unhandled => write!(f, "Unhandled packet"),
50
0
            QuicError::NomError(e) => write!(f, "Internal parser error {:?}", e),
51
        }
52
0
    }
53
}
54
55
impl Error for QuicError {}
56
57
impl From<nom7::Err<QuicError>> for QuicError {
58
7.26k
    fn from(err: nom7::Err<QuicError>) -> Self {
59
7.26k
        match err {
60
0
            nom7::Err::Incomplete(_) => QuicError::Incomplete,
61
7.26k
            nom7::Err::Error(e) => e,
62
0
            nom7::Err::Failure(e) => e,
63
        }
64
7.26k
    }
65
}