From f1108b8a1cd494c11526d2704e05c18d2528b8c4 Mon Sep 17 00:00:00 2001 From: Atul Kumar Date: Tue, 21 Jul 2026 16:01:57 +0530 Subject: [PATCH] ref: make EvidenceCreationCb satisfy trait FnOnce function type fn() is too limiting for capturing variables in closures. This capability is required with rust-regl where an attester must be called to generate evidence. Use trait FnOnce to define evidence callback functions. Signed-off-by: Atul Kumar --- src/lib.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6e3ae1b..9283f1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,13 +80,6 @@ impl std::fmt::Debug for Error { } } -/// EvidenceCreationCb is the function signature of the application callback. -/// The application is passed the session nonce and the list of supported -/// evidence media types and shall return the computed evidence together with -/// the selected media type. -type EvidenceCreationCb = - fn(nonce: &[u8], accepted: &[String], token: Vec) -> Result<(Vec, String), Error>; - /// A builder for ChallengeResponse objects pub struct ChallengeResponseBuilder { http_client_builder: HttpClientBuilder, @@ -180,12 +173,25 @@ impl ChallengeResponse { /// Run a challenge-response verification session using the supplied nonce /// configuration and evidence creation callback. Returns the raw attestation results, or an /// error on failure. - pub async fn run( + /// + /// EvidenceCreationCb is the function signature of the application callback. + /// The application is passed the session nonce and the list of supported + /// evidence media types and shall return the computed evidence together with + /// the selected media type. + /// + /// # Type Parameters + /// + /// * `EvidenceCreationCb` — called once with `(nonce: &[u8], accepted: &[String], token: Vec)`; + /// returns the evidence bytes and the chosen media type, or an error. + pub async fn run( &self, nonce: Nonce, evidence_creation_cb: EvidenceCreationCb, token: Vec, - ) -> Result { + ) -> Result + where + EvidenceCreationCb: FnOnce(&[u8], &[String], Vec) -> Result<(Vec, String), Error>, + { // create new c/r verification session on the veraison side let (session_url, session) = self.new_session(&nonce).await?;