git-next/crates/config/src/webhook/auth.rs

23 lines
574 B
Rust
Raw Normal View History

2024-06-19 07:02:18 +01:00
//
crate::newtype!(WebhookAuth is a ulid::Ulid, derive_more::Display);
impl WebhookAuth {
2024-06-19 07:02:18 +01:00
pub fn try_new(authorisation: &str) -> Result<Self, ulid::DecodeError> {
use std::str::FromStr as _;
let id = ulid::Ulid::from_str(authorisation)?;
tracing::info!("Parse auth token: {}", id);
Ok(Self(id))
}
pub fn generate() -> Self {
Self(ulid::Ulid::new())
}
pub fn header_value(&self) -> String {
format!("Basic {}", self)
}
pub const fn to_bytes(&self) -> [u8; 16] {
self.0.to_bytes()
}
}