ampr_api/auth.rs
1use serde::{Deserialize, Serialize};
2
3/// An Auth token used for all requests to the AMPR API.
4#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
5pub struct Auth {
6 /// User's callsign
7 pub(crate) callsign: String,
8
9 /// User's API key
10 pub(crate) api_key: String,
11}
12
13impl Auth {
14 /// Construct a new Auth object.
15 pub fn new(callsign: String, api_key: String) -> Self {
16 Self { callsign, api_key }
17 }
18
19 /// Check if an API key follows AMPR's key format rules
20 pub fn is_key_valid(&self) -> bool {
21 self.api_key.len() == 32
22 && self
23 .api_key
24 .chars()
25 .into_iter()
26 .all(|c| c.is_numeric() || c.is_ascii_uppercase())
27 }
28}