use super::{ChecksumResult, ChecksumValidator};
pub struct GitlabTokenValidator;
impl ChecksumValidator for GitlabTokenValidator {
fn validator_id(&self) -> &str {
"gitlab-token"
}
fn validate(&self, credential: &str) -> ChecksumResult {
if let Some(payload) = credential.strip_prefix("glpat-") {
if payload.len() == 20 && payload.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_') {
return ChecksumResult::Valid;
}
return ChecksumResult::Invalid;
}
if let Some(payload) = credential.strip_prefix("glcbt-").or_else(|| credential.strip_prefix("glrt-")) {
if payload.len() >= 16 && payload.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_') {
return ChecksumResult::Valid;
}
return ChecksumResult::Invalid;
}
ChecksumResult::NotApplicable
}
}