hmac-predicate

Crates.iohmac-predicate
lib.rshmac-predicate
version0.3.2
sourcesrc
created_at2023-08-18 23:58:50.30724
updated_at2023-08-19 00:53:48.447275
descriptionTower predicate HMAC verification of query params
homepagehttps://github.com/tobymurray/hmac-predicate
repositoryhttps://github.com/tobymurray/hmac-predicate
max_upload_size
id948406
size5,160
Toby Murray (tobymurray)

documentation

README

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),
	)
}
Commit count: 9

cargo fmt