aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
blob: 9afdbd56880effa290f49e33cdb3afc175b62b38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use std::io;

#[derive(Debug, Eq, PartialEq, Clone)]
pub enum ParseError {
    BufferTooSmall(usize),

    BufferTooSmallForTag {
        available: u16,
        requested: usize,
    },

    InvalidPppoeVersion(u8),
    InvalidPppoeType(u8),
    InvalidPppoeCode(u8),

    UnexpectedCode(u8),

    PayloadLengthOutOfBound {
        actual_packet_length: u16,
        payload_length: u16,
    },
    TagLengthOutOfBound {
        expected_tag_length: u16,
        remaining_payload_length: u16,
    },

    IncompleteTagAtPacketEnd {
        total_packet_length: u16,
        left_over_bytes: u16,
    },

    DataBehindEolTag,
    IncompleteTag(u8),
    TagWithInvalidLength {
        tag_type: u16,
        length: u16,
    },

    #[cfg(feature = "tr101")]
    InvalidTr101TagLength {
        tag_type: u8,
        expected_min_length: u16,
        expected_max_length: u16,
        actual_length: u16,
    },
    #[cfg(feature = "tr101")]
    Tr101LengthOutOfBound {
        remaining_packet_length: u16,
        requested_tag_length: u16,
    },
    #[cfg(feature = "tr101")]
    InvalidTr101Id(u32),
    #[cfg(feature = "tr101")]
    TagIsNotVendorSpecific,
    #[cfg(feature = "tr101")]
    InvalidTr101VendorId(u32),

    DuplicateTag(u16),

    MissingServiceName,
    MissingAcName,

    ServiceNameMismatch,
    AcNameMismatch,

    InvalidPppProtocol(u16),

    InvalidLcpCode(u8),

    InvalidOptionType(u8),
    InvalidOptionLength(u8),

    InvalidQualityProtocol(u16),

    InvalidAuthProtocol(u16),

    InvalidPapCode(u8),
    InvalidChapCode(u8),

    InvalidIpcpCode(u8),
}

#[derive(Debug)]
pub enum Error {
    Io(io::Error),
    ParseError(ParseError),
    TODO,
}

impl From<ParseError> for Error {
    fn from(error: ParseError) -> Self {
        Error::ParseError(error)
    }
}

impl From<io::Error> for Error {
    fn from(error: io::Error) -> Self {
        Error::Io(error)
    }
}

impl From<()> for Error {
    fn from(_: ()) -> Self {
        Error::TODO
    }
}