style: use const generic for token length instead of multiple functions
Simplifies codebase a bit and avoids having to add another function in future if we need another length of token
This commit is contained in:
parent
f752cddd73
commit
407460d2aa
6 changed files with 16 additions and 22 deletions
10
src/utils.rs
10
src/utils.rs
|
@ -115,14 +115,8 @@ pub fn new_refresh_token_cookie(config: &Config, refresh_token: String) -> Cooki
|
|||
.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];
|
||||
pub fn generate_token<const N: usize>() -> Result<String, getrandom::Error> {
|
||||
let mut buf = [0u8; N];
|
||||
fill(&mut buf)?;
|
||||
Ok(encode(buf))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue