use simple_string_patterns::CharGroupMatch;
#[derive(Debug, Clone, Copy)]
pub struct AuthOptions<'a> {
process_uuid: bool,
api_key: &'a str,
rand_char_str: &'a str,
tolerance: u32,
}
impl<'a> AuthOptions<'a> {
pub fn new(api_key: &'a str) -> Self {
AuthOptions {
process_uuid: false,
api_key,
rand_char_str: "%.,",
tolerance: 300_000 }
}
pub fn set_rand_char_str(&mut self, char_str: &'a str) -> Self {
let is_invalid = char_str.has_alphanumeric() || char_str.contains("_");
if !is_invalid {
self.rand_char_str = char_str;
}
self.to_owned()
}
pub fn key(&self) -> &'a str {
self.api_key
}
pub fn rand_chars(&self) -> Vec<char> {
self.rand_char_str.chars().into_iter().collect::<Vec<char>>()
}
pub fn tolerance(&self) -> i64 {
self.tolerance as i64
}
pub fn should_check_uuid(&self) -> bool {
self.process_uuid
}
pub fn check_uuid(&mut self, val: bool) -> Self {
self.process_uuid = val;
self.to_owned()
}
pub fn set_tolerance(&mut self, millis: u32) -> Self {
self.tolerance = millis;
self.to_owned()
}
pub fn set_tolerance_secs(&mut self, secs: u32) -> Self {
self.tolerance = secs * 1000;
self.to_owned()
}
pub fn set_tolerance_mins(&mut self, mins: u32) -> Self {
self.tolerance = mins * 60 * 1000;
self.to_owned()
}
}