diff --git a/giterated-models/src/model/authenticated.rs b/giterated-models/src/model/authenticated.rs index a4e7af6..c936935 100644 --- a/giterated-models/src/model/authenticated.rs +++ b/giterated-models/src/model/authenticated.rs @@ -1,4 +1,4 @@ -use std::{any::type_name, fmt::Debug}; +use std::{any::type_name, fmt::Debug, ops::Deref}; use rsa::{ pkcs1::DecodeRsaPrivateKey, @@ -20,9 +20,9 @@ pub struct UserTokenMetadata { } #[derive(Debug)] -pub struct Authenticated<'a, T: Serialize> { +pub struct Authenticated { pub target_instance: Option, - pub source: Vec<&'a dyn AuthenticationSourceProvider>, + pub source: Vec>, pub message_type: String, pub message: T, } @@ -35,8 +35,8 @@ pub struct AuthenticatedPayload { pub payload: Vec, } -impl<'a, T: Serialize> From> for AuthenticatedPayload { - fn from(mut value: Authenticated<'a, T>) -> Self { +impl From> for AuthenticatedPayload { + fn from(mut value: Authenticated) -> Self { let payload = bincode::serialize(&value.message).unwrap(); AuthenticatedPayload { @@ -44,7 +44,7 @@ impl<'a, T: Serialize> From> for AuthenticatedPayload { source: value .source .drain(..) - .map(|provider| provider.authenticate(&payload)) + .map(|provider| provider.as_ref().authenticate(&payload)) .collect::>(), message_type: value.message_type, payload, @@ -81,7 +81,7 @@ where } } -impl<'a, T: Serialize + Debug> Authenticated<'a, T> { +impl Authenticated { pub fn new(message: T) -> Self { Self { source: vec![], @@ -109,7 +109,7 @@ impl<'a, T: Serialize + Debug> Authenticated<'a, T> { } } - pub fn append_authentication(&mut self, authentication: &'a dyn AuthenticationSourceProvider) { + pub fn append_authentication(&mut self, authentication: P) { let message_payload = serde_json::to_vec(&self.message).unwrap(); info!( @@ -117,7 +117,7 @@ impl<'a, T: Serialize + Debug> Authenticated<'a, T> { std::str::from_utf8(&message_payload).unwrap() ); - self.source.push(authentication); + self.source.push(Box::new(authentication) as Box); } pub fn into_payload(self) -> AuthenticatedPayload {