refactor: combine crypto.rs with utils.rs
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful

This commit is contained in:
Radical 2025-05-04 23:50:38 +02:00
parent c2bface373
commit 77245e98c5
6 changed files with 20 additions and 19 deletions

View file

@ -1,4 +1,6 @@
use actix_web::{cookie::{time::Duration, Cookie, SameSite}, http::header::HeaderMap, HttpResponse};
use getrandom::fill;
use hex::encode;
pub fn get_auth_header(headers: &HeaderMap) -> Result<&str, HttpResponse> {
let auth_token = headers.get(actix_web::http::header::AUTHORIZATION);
@ -30,4 +32,17 @@ pub fn refresh_token_cookie(refresh_token: String) -> Cookie<'static> {
.path("/api")
.max_age(Duration::days(30))
.finish()
}
}
pub fn generate_access_token() -> Result<String, getrandom::Error> {
let mut buf = [0u8; 16];
fill(&mut buf)?;
Ok(encode(buf))
}
pub fn generate_refresh_token() -> Result<String, getrandom::Error> {
let mut buf = [0u8; 32];
fill(&mut buf)?;
Ok(encode(buf))
}