use serde::Serialize; #[derive(Serialize)] /// JWTMessage aims to have a generic struct to build JSON HTTP response message with JWT informations pub struct JWTMessage { #[serde(skip_serializing_if = "String::is_empty")] access_token: String, #[serde(skip_serializing_if = "String::is_empty")] refresh_token: String, #[serde(skip_serializing_if = "String::is_empty")] pubkey: String, } impl JWTMessage { pub fn with_access(access_token: String) -> Self { JWTMessage { access_token: access_token, refresh_token: "".to_string(), pubkey: "".to_string(), } } pub fn with_pubkey(pubkey: String) -> Self { JWTMessage { access_token: "".to_string(), refresh_token: "".to_string(), pubkey: base64::encode(pubkey), } } } #[derive(Serialize, Default)] /// ValidationMessage aims to build a JSON HTTP response body for JWT validation pub struct ValidationMessage { valid: bool, #[serde(skip_serializing_if = "String::is_empty")] reason: String, } impl ValidationMessage { pub fn set_valid(&mut self, valid: bool) { self.valid = valid; } pub fn set_reason(&mut self, reason: &str) { self.reason = reason.to_string(); } }