use anyhow::Error; use giterated_models::instance::Instance; use std::collections::HashMap; #[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) { Ok(key.clone()) } else { let key = reqwest::get(format!("https://{}/.giterated/pubkey.pem", instance)) .await? .text() .await?; self.keys.insert(instance.clone(), key); Ok(self.keys.get(instance).unwrap().clone()) } } }