rsa_msg_packets/util/
modes.rs

1#[derive(Copy, Clone)]
2pub enum Modes {
3    SetPubkey,
4    To,
5    From,
6    Name,
7    WantUid,
8    UidReply,
9    Error,
10    SymmKey,
11    WantSymmKey,
12    // Initial Request from client to other client for asking them wether they want to receive the file or not
13    SendFileQuestion,
14    // Self-explanatory
15    SendFileQuestionReply,
16    // Message when other chunk of data is ready to be downloaded
17    SendFileChunkReady,
18    // Message when the receiver has downloaded the chunk and is ready for the next one
19    SendFileChunkDownloaded,
20    // Sent from server to sending client, to retrieve file size etc
21    SendFileStartProcessing,
22    SendFileAbort
23}
24
25impl Modes {
26    pub fn get_indicator(self) -> u8 {
27        match self {
28            Self::SetPubkey => 0,
29            Self::To => 1,
30            Self::From => 2,
31            Self::Name => 3,
32            Self::WantUid => 4,
33            Self::UidReply => 5,
34            Self::Error => 6,
35            Self::SendFileQuestion => 7,
36            Self::SendFileQuestionReply => 8,
37            Self::SendFileChunkReady => 9,
38            Self::SendFileChunkDownloaded => 10,
39            Self::SendFileStartProcessing => 11,
40            Self::SendFileAbort => 12,
41            Self::SymmKey => 13,
42            Self::WantSymmKey => 14
43        }
44    }
45
46    pub fn is_indicator(self, b: &u8) -> bool {
47        let ind = self.get_indicator();
48        return ind.eq(b);
49    }
50
51    pub fn get_send(self, end: &[u8]) -> Vec<u8> {
52        let ind = self.get_indicator();
53
54        let mut el = end.to_vec().clone();
55        el.reverse();
56
57        el.push(ind);
58
59        el.reverse();
60
61        return el;
62    }
63}