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
use crc::Crc16;

pub struct CrcBuilder{

}

impl CrcBuilder{
    
    pub fn generate_crc(algorithm: &str) -> Result<Crc16, &'static str> {
        match algorithm {

            "crc16_ccitt_false" => {
                let mut crc =
                Crc16 {
                    divisor: 0x1021,
                    initial_reminder: 0xFFFF,
                    table: Vec::with_capacity(256),
                    reversed_input:false,
                    reverser_output:false,
                    xorout:0x0000};
                crc.create_table();
                Ok(crc)
            },

            "crc16_kermit" => {
                let mut crc =
                Crc16 {
                    divisor: 0x1021,
                    initial_reminder: 0x0000,
                    table: Vec::with_capacity(256),
                    reversed_input:true,
                    reverser_output:true,
                    xorout:0x0000};
                crc.create_table();
                Ok(crc)
            },
            
             _ => Err("Unsupported algoritham specified"),
        }

    }

}