#hmac #query-parameters #http-request

hmac-predicate

Tower predicate HMAC verification of query params

8 releases (5 breaking)

0.6.0 Aug 18, 2024
0.5.0 Aug 18, 2024
0.4.0 Aug 14, 2024
0.3.2 Aug 19, 2023
0.1.0 Aug 18, 2023

#10 in #query-parameters

Download history 1/week @ 2024-07-04 58/week @ 2024-08-08 271/week @ 2024-08-15 25/week @ 2024-08-22 25/week @ 2024-09-12 28/week @ 2024-09-19 19/week @ 2024-09-26 2/week @ 2024-10-03 2/week @ 2024-10-10

55 downloads per month

GPL-3.0-or-later

9KB
99 lines

Use something like:

use axum::error_handling::HandleErrorLayer;
use axum::Router;
use hmac_predicate::HmacQueryParamValidator;
use reqwest::StatusCode;
use tower::{BoxError, ServiceBuilder};

#[tokio::main]
async fn main() {
	let predicate: HmacQueryParamValidator = HmacQueryParamValidator {
		key: API_SECRET.to_string(),
	};

	let builder = ServiceBuilder::new()
		.layer(HandleErrorLayer::new(handle_error))
		.filter(predicate);

	let app = Router::new()
		.route("/", get(handler))
		.layer(builder);
}

async fn handle_error(err: BoxError) -> (StatusCode, String) {
	(
		StatusCode::INTERNAL_SERVER_ERROR,
		format!("Unhandled internal error: {}", err),
	)
}

Dependencies

~2.2–3MB
~60K SLoC