cbsk/data/
verify_data.rs

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
/// verify result data
#[derive(Debug)]
pub struct VerifyData {
    /// verify fail frame
    pub error_frame: Vec<u8>,
    /// verify success frame
    pub data_frame: Vec<u8>,
    /// verify first frame success, but the remaining bytes are too short<br />
    /// the bytes with insufficient length are stored here
    pub too_short_frame: Vec<u8>,
    /// loop verification failed, data that needs to be verified next time
    pub next_verify_frame: Vec<u8>,
}

/// custom method
impl VerifyData {
    /// just verify fail
    pub fn fail(error_frame: Vec<u8>) -> Self {
        Self::new(error_frame, Vec::new())
    }

    /// just verify success
    pub fn success(data_frame: Vec<u8>) -> Self {
        Self::new(Vec::new(), data_frame)
    }

    /// just too short
    pub fn too_short(error_frame: Vec<u8>, too_short_frame: Vec<u8>) -> Self {
        Self::new_with_too_short_frame(error_frame, Vec::new(), too_short_frame)
    }

    /// just next next verify
    pub fn next_verify(error_frame: Vec<u8>, next_verify_frame: Vec<u8>) -> Self {
        Self { error_frame, data_frame: Vec::new(), too_short_frame: Vec::new(), next_verify_frame }
    }

    /// new verify data
    pub fn new(error_frame: Vec<u8>, data_frame: Vec<u8>) -> Self {
        Self::new_with_too_short_frame(error_frame, data_frame, Vec::new())
    }

    pub fn new_with_too_short_frame(error_frame: Vec<u8>, data_frame: Vec<u8>, too_short_frame: Vec<u8>) -> Self {
        Self { error_frame, data_frame, too_short_frame, next_verify_frame: Vec::new() }
    }
}