mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-09-10 18:55:57 +03:00
Updated all the crates to the latest version. We can unpin mimalloc, since the musl issues have been fixed Also fix a RUSTSEC https://osv.dev/vulnerability/RUSTSEC-2025-0023 for tokio Fixed some clippy lints reported by nightly. Ensure lints and are also run on the macro crate. This resulted in some lints being triggered, which I fixed. Updated some GHA uses. Signed-off-by: BlackDex <black.dex@gmail.com>
57 lines
1.6 KiB
Rust
57 lines
1.6 KiB
Rust
use proc_macro::TokenStream;
|
|
use quote::quote;
|
|
|
|
#[proc_macro_derive(UuidFromParam)]
|
|
pub fn derive_uuid_from_param(input: TokenStream) -> TokenStream {
|
|
let ast = syn::parse(input).unwrap();
|
|
|
|
impl_derive_uuid_macro(&ast)
|
|
}
|
|
|
|
fn impl_derive_uuid_macro(ast: &syn::DeriveInput) -> TokenStream {
|
|
let name = &ast.ident;
|
|
let gen_derive = quote! {
|
|
#[automatically_derived]
|
|
impl<'r> rocket::request::FromParam<'r> for #name {
|
|
type Error = ();
|
|
|
|
#[inline(always)]
|
|
fn from_param(param: &'r str) -> Result<Self, Self::Error> {
|
|
if uuid::Uuid::parse_str(param).is_ok() {
|
|
Ok(Self(param.to_string()))
|
|
} else {
|
|
Err(())
|
|
}
|
|
}
|
|
}
|
|
};
|
|
gen_derive.into()
|
|
}
|
|
|
|
#[proc_macro_derive(IdFromParam)]
|
|
pub fn derive_id_from_param(input: TokenStream) -> TokenStream {
|
|
let ast = syn::parse(input).unwrap();
|
|
|
|
impl_derive_safestring_macro(&ast)
|
|
}
|
|
|
|
fn impl_derive_safestring_macro(ast: &syn::DeriveInput) -> TokenStream {
|
|
let name = &ast.ident;
|
|
let gen_derive = quote! {
|
|
#[automatically_derived]
|
|
impl<'r> rocket::request::FromParam<'r> for #name {
|
|
type Error = ();
|
|
|
|
#[inline(always)]
|
|
fn from_param(param: &'r str) -> Result<Self, Self::Error> {
|
|
if param.chars().all(|c| matches!(c, 'a'..='z' | 'A'..='Z' |'0'..='9' | '-')) {
|
|
Ok(Self(param.to_string()))
|
|
} else {
|
|
Err(())
|
|
}
|
|
}
|
|
}
|
|
};
|
|
gen_derive.into()
|
|
}
|