stackpatrol_core/
token.rs1use thiserror::Error;
2
3pub const TOKEN_PREFIX: &str = "sp_live_";
4pub const TOKEN_SECRET_LEN: usize = 32;
5
6#[derive(Debug, Error)]
7pub enum TokenError {
8 #[error("token must start with `{TOKEN_PREFIX}`")]
9 BadPrefix,
10 #[error("token secret must be {TOKEN_SECRET_LEN} characters")]
11 BadLength,
12}
13
14pub fn validate(token: &str) -> Result<(), TokenError> {
15 let secret = token
16 .strip_prefix(TOKEN_PREFIX)
17 .ok_or(TokenError::BadPrefix)?;
18 if secret.len() != TOKEN_SECRET_LEN {
19 return Err(TokenError::BadLength);
20 }
21 Ok(())
22}