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
//! This module deals with various configurations that can be applied while creating a iso msg like
//! crypto field F52, F64/128 etc

use crate::crypto::pin::PinFormat;
use crate::crypto::mac::{MacAlgo, PaddingType};

pub struct Config {
    pin_format: Option<PinFormat>,
    pin_key: Option<String>,
    mac_algo: Option<MacAlgo>,
    mac_padding: Option<PaddingType>,
    mac_key: Option<String>,
}


impl Config {
    // Creates a new empty Config
    pub fn new() -> Config {
        Config {
            pin_format: None,
            pin_key: None,
            mac_algo: None,
            mac_key: None,
            mac_padding: None,
        }
    }

    /// Returns the PIN block format associated with this config
    pub fn get_pin_fmt(&self) -> &Option<PinFormat> {
        &self.pin_format
    }

    /// Returns the PIN key associated with this config
    pub fn get_pin_key(&self) -> &Option<String> {
        &self.pin_key
    }

    /// Returns the MAC key associated with this config
    pub fn get_mac_key(&self) -> &Option<String> {
        &self.mac_key
    }

    /// Returns the MAC'ing algorithm associated with this config
    pub fn get_mac_algo(&self) -> &Option<MacAlgo> {
        &self.mac_algo
    }

    /// Returns the MAC padding scheme associated with this config
    pub fn get_mac_padding(&self) -> &Option<PaddingType> {
        &self.mac_padding
    }


    /// Use the Config with a builder pattern
    pub fn with_pin(&mut self, fmt: PinFormat, key: String) -> &mut Config {
        self.pin_format = Some(fmt);
        self.pin_key = Some(key);
        self
    }

    /// Use the Config with a builder pattern
    pub fn with_mac(&mut self, algo: MacAlgo, mac_padding: PaddingType, key: String) -> &mut Config {
        self.mac_algo = Some(algo);
        self.mac_key = Some(key);
        self.mac_padding = Some(mac_padding);
        self
    }
}