From 347259d764ebeaf6e69da46ec031b8cf40f864a1 Mon Sep 17 00:00:00 2001 From: Ryan Tate Date: Tue, 20 Aug 2024 08:35:17 -0700 Subject: [PATCH] revert validation function async signature to use boxed pin future Signed-off-by: Ryan Tate --- src/verifier/mod.rs | 8 ++++---- tests/jwt_vc.rs | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/verifier/mod.rs b/src/verifier/mod.rs index 725f880..d179856 100644 --- a/src/verifier/mod.rs +++ b/src/verifier/mod.rs @@ -1,4 +1,4 @@ -use std::{fmt::Debug, future::Future, sync::Arc}; +use std::{fmt::Debug, future::Future, pin::Pin, sync::Arc}; use anyhow::{bail, Context, Result}; use client::Client; @@ -119,12 +119,12 @@ impl Verifier { validator_function: F, ) -> Result<()> where - F: FnOnce(Session, AuthorizationResponse) -> Fut, - Fut: Future>, + F: FnOnce(Session, AuthorizationResponse) -> Pin>, + Fut: Future, { let session = self.session_store.get_session(reference).await?; - let outcome = validator_function(session, authorization_response).await?; + let outcome = validator_function(session, authorization_response).await; self.session_store .update_status(reference, Status::Complete(outcome)) diff --git a/tests/jwt_vc.rs b/tests/jwt_vc.rs index af6b7f5..7559b73 100644 --- a/tests/jwt_vc.rs +++ b/tests/jwt_vc.rs @@ -159,17 +159,18 @@ impl AsyncHttpClient for MockHttpClient { id.parse().context("failed to parse id")?, AuthorizationResponse::from_x_www_form_urlencoded(body) .context("failed to parse authorization response request")?, - |session, auth_response| async move { - session - .presentation_definition - .validate_authorization_response(&auth_response) - .await?; - - println!("Session: {:?}", session); - println!("Auth Response: {:?}", auth_response); - - Ok(Outcome::Success { - info: serde_json::Value::Null, + |session, auth_response| { + Box::pin(async move { + match session + .presentation_definition + .validate_authorization_response(&auth_response) + .await + { + Ok(_) => Outcome::Success { + info: serde_json::Value::Null, + }, + Err(e) => Outcome::Error { cause: Arc::new(e) }, + } }) }, )