#![allow(clippy::extra_unused_lifetimes)]
use std::fmt;
use base64::Engine;
#[aliri_braid::braid(serde)]
pub struct ClientId;
#[aliri_braid::braid(display = "owned", debug = "owned", serde)]
pub struct ClientSecret;
impl fmt::Debug for ClientSecretRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("[redacted client secret]")
}
}
impl fmt::Display for ClientSecretRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("[redacted client secret]")
}
}
#[aliri_braid::braid(display = "owned", debug = "owned", serde)]
pub struct AccessToken;
impl fmt::Debug for AccessTokenRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("[redacted access token]")
}
}
impl fmt::Display for AccessTokenRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("[redacted access token]")
}
}
#[aliri_braid::braid(display = "owned", debug = "owned", serde)]
pub struct RefreshToken;
impl fmt::Debug for RefreshTokenRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("[redacted refresh token]")
}
}
impl fmt::Display for RefreshTokenRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("[redacted refresh token]")
}
}
#[aliri_braid::braid(display = "owned", debug = "owned", serde)]
pub struct CsrfToken;
impl fmt::Debug for CsrfTokenRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("[redacted csrf token]")
}
}
impl fmt::Display for CsrfTokenRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("[redacted csrf token]")
}
}
impl CsrfToken {
pub fn new_random() -> CsrfToken { Self::new_random_len(16) }
pub fn new_random_len(len: u32) -> CsrfToken {
use rand::Rng as _;
let random_bytes: Vec<u8> = (0..len).map(|_| rand::thread_rng().gen::<u8>()).collect();
CsrfToken::new(base64::engine::general_purpose::STANDARD.encode(random_bytes))
}
}
impl ClientSecretRef {
pub fn secret(&self) -> &str { self.as_str() }
}
impl AccessTokenRef {
pub fn secret(&self) -> &str { self.as_str() }
}
impl RefreshTokenRef {
pub fn secret(&self) -> &str { self.as_str() }
}
impl CsrfTokenRef {
pub fn secret(&self) -> &str { self.as_str() }
}