use std::collections::HashMap; use anyhow::Error; use giterated_models::model::instance::Instance; #[derive(Default)] pub struct PublicKeyCache { pub keys: HashMap, } impl PublicKeyCache { pub async fn get(&mut self, instance: &Instance) -> Result { if let Some(key) = self.keys.get(instance) { return Ok(key.clone()); } else { let key = reqwest::get(format!("https://{}/.giterated/pubkey.pem", instance.url)) .await? .text() .await?; self.keys.insert(instance.clone(), key); Ok(self.keys.get(instance).unwrap().clone()) } } }