dynamic_token/
auth_options.rs1use simple_string_patterns::CharGroupMatch;
2
3#[derive(Debug, Clone, Copy)]
8pub struct AuthOptions<'a> {
9 process_uuid: bool,
10 api_key: &'a str,
11 rand_char_str: &'a str,
12 tolerance: u32,
13}
14
15impl<'a> AuthOptions<'a> {
16 pub fn new(api_key: &'a str) -> Self {
17 AuthOptions {
18 process_uuid: false,
19 api_key,
20 rand_char_str: "%.,",
21 tolerance: 300_000 }
23 }
24
25 pub fn set_rand_char_str(&mut self, char_str: &'a str) -> Self {
26 let is_invalid = char_str.has_alphanumeric() || char_str.contains("_");
27 if !is_invalid {
28 self.rand_char_str = char_str;
29 }
30 self.to_owned()
31 }
32
33 pub fn key(&self) -> &'a str {
35 self.api_key
36 }
37
38 pub fn rand_chars(&self) -> Vec<char> {
40 self.rand_char_str.chars().into_iter().collect::<Vec<char>>()
41 }
42
43 pub fn tolerance(&self) -> i64 {
45 self.tolerance as i64
46 }
47
48 pub fn should_check_uuid(&self) -> bool {
50 self.process_uuid
51 }
52
53 pub fn check_uuid(&mut self, val: bool) -> Self {
55 self.process_uuid = val;
56 self.to_owned()
57 }
58
59 pub fn set_tolerance(&mut self, millis: u32) -> Self {
61 self.tolerance = millis;
62 self.to_owned()
63 }
64
65 pub fn set_tolerance_secs(&mut self, secs: u32) -> Self {
67 self.tolerance = secs * 1000;
68 self.to_owned()
69 }
70
71 pub fn set_tolerance_mins(&mut self, mins: u32) -> Self {
73 self.tolerance = mins * 60 * 1000;
74 self.to_owned()
75 }
76
77}
78
79