diff --git a/rust/auth-impls/src/lib.rs b/rust/auth-impls/src/lib.rs index 1cd0182..86c6853 100644 --- a/rust/auth-impls/src/lib.rs +++ b/rust/auth-impls/src/lib.rs @@ -42,16 +42,8 @@ const BEARER_PREFIX: &str = "Bearer "; impl JWTAuthorizer { /// Create new instance of [`JWTAuthorizer`] - pub async fn new(jwt_issuer_key: DecodingKey) -> JWTAuthorizer { - JWTAuthorizer { jwt_issuer_key } - } - - fn extract_token(auth_header: &str) -> Option<&str> { - if auth_header.starts_with(BEARER_PREFIX) { - Some(&auth_header[BEARER_PREFIX.len()..]) - } else { - None - } + pub async fn new(jwt_issuer_key: DecodingKey) -> Self { + Self { jwt_issuer_key } } } @@ -64,7 +56,8 @@ impl Authorizer for JWTAuthorizer { .get("Authorization") .ok_or(VssError::AuthError("Authorization header not found.".to_string()))?; - let token = JWTAuthorizer::extract_token(auth_header) + let token = auth_header + .strip_prefix(BEARER_PREFIX) .ok_or(VssError::AuthError("Invalid token format.".to_string()))?; let claims = diff --git a/rust/impls/src/postgres_store.rs b/rust/impls/src/postgres_store.rs index d7949a7..96f9618 100644 --- a/rust/impls/src/postgres_store.rs +++ b/rust/impls/src/postgres_store.rs @@ -376,8 +376,8 @@ impl KvStore for PostgresBackendImpl { let stmt = "SELECT key, version FROM vss_db WHERE user_token = $1 AND store_id = $2 AND key > $3 AND key LIKE $4 ORDER BY key LIMIT $5"; - let key_like = format!("{}%", key_prefix.as_deref().unwrap_or("")); - let page_token_param = page_token.as_deref().unwrap_or(""); + let key_like = format!("{}%", key_prefix.as_deref().unwrap_or_default()); + let page_token_param = page_token.as_deref().unwrap_or_default(); let params: Vec<&(dyn tokio_postgres::types::ToSql + Sync)> = vec![&user_token, &store_id, &page_token_param, &key_like, &limit]; diff --git a/rust/server/src/vss_service.rs b/rust/server/src/vss_service.rs index bae2e0b..fecba40 100644 --- a/rust/server/src/vss_service.rs +++ b/rust/server/src/vss_service.rs @@ -43,7 +43,7 @@ impl Service> for VssService { let path = req.uri().path().to_owned(); Box::pin(async move { - let prefix_stripped_path = path.strip_prefix(BASE_PATH_PREFIX).unwrap_or(""); + let prefix_stripped_path = path.strip_prefix(BASE_PATH_PREFIX).unwrap_or_default(); match prefix_stripped_path { "/getObject" => { @@ -103,7 +103,7 @@ async fn handle_request< let headers_map = parts .headers .iter() - .map(|(k, v)| (k.as_str().to_string(), v.to_str().unwrap_or("").to_string())) + .map(|(k, v)| (k.as_str().to_string(), v.to_str().unwrap_or_default().to_string())) .collect::>(); let user_token = match authorizer.verify(&headers_map).await {