mirror of
https://github.com/dani-garcia/vaultwarden.wiki.git
synced 2026-11-23 17:19:38 +02:00
* Modernize Rust code and fix input handling - Adopt newer std APIs, reduce allocations, and consolidate caching on Moka. - Update the Rust toolchain and most dependencies, tighten lints, and expand test coverage. - Fix favicon ranking for URLs with query strings or fragments, and try the next icon when SVG sanitization fails. - Prevent panics when masking 2FA email addresses containing Unicode or missing an @. - Prevent panics on Unicode database paths and recognize short postgres: URLs. - Treat whitespace-only collection and member external IDs as absent and avoid redundant membership updates. - Align stable builds’ global IP classification with Rust’s standard library. Signed-off-by: BlackDex <black.dex@gmail.com> * Update crates and some fixes - Bump Rocket, rocket_ws, Diesel, SQLite bindings, and html5gum. - Reuse WebSocket payload buffers and detect upgrades from the response. - Match favicon rel tokens case-insensitively, honor the first base href, and stop scanning at the end of the head or the start of the body. Signed-off-by: BlackDex <black.dex@gmail.com> --------- Signed-off-by: BlackDex <black.dex@gmail.com>
58 lines
1.6 KiB
Rust
58 lines
1.6 KiB
Rust
use proc_macro::TokenStream;
|
|
use quote::quote;
|
|
use syn::{DeriveInput, parse_macro_input};
|
|
|
|
#[proc_macro_derive(UuidFromParam)]
|
|
pub fn derive_uuid_from_param(input: TokenStream) -> TokenStream {
|
|
let ast = parse_macro_input!(input as DeriveInput);
|
|
|
|
impl_derive_uuid_macro(&ast)
|
|
}
|
|
|
|
fn impl_derive_uuid_macro(ast: &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::try_parse(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 = parse_macro_input!(input as DeriveInput);
|
|
|
|
impl_derive_safestring_macro(&ast)
|
|
}
|
|
|
|
fn impl_derive_safestring_macro(ast: &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()
|
|
}
|