diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-04-04 14:59:47 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-04-04 14:59:47 +0200 |
commit | 272b93f04a0640e056fe994f48cb2837eacdad46 (patch) | |
tree | 48a0099be9b14e402ca5027f40153ffe918903f5 /aero-collections/src/calendar | |
parent | 2efdd40b8edd83c3fef3d94f7e62b41b86e49959 (diff) | |
download | aerogramme-272b93f04a0640e056fe994f48cb2837eacdad46.tar.gz aerogramme-272b93f04a0640e056fe994f48cb2837eacdad46.zip |
GET logic
Diffstat (limited to 'aero-collections/src/calendar')
-rw-r--r-- | aero-collections/src/calendar/mod.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/aero-collections/src/calendar/mod.rs b/aero-collections/src/calendar/mod.rs index 7e5a8c1..0e0e65f 100644 --- a/aero-collections/src/calendar/mod.rs +++ b/aero-collections/src/calendar/mod.rs @@ -1,6 +1,6 @@ pub mod namespace; -use anyhow::Result; +use anyhow::{anyhow, Result}; use tokio::sync::RwLock; use aero_bayou::Bayou; @@ -66,8 +66,8 @@ impl Calendar { } /// Get a specific event - pub async fn get(&self, evt_id: UniqueIdent, message_key: &Key) -> Result<Vec<u8>> { - self.internal.read().await.get(evt_id, message_key).await + pub async fn get(&self, evt_id: UniqueIdent) -> Result<Vec<u8>> { + self.internal.read().await.get(evt_id).await } /// Put a specific event @@ -103,8 +103,24 @@ impl CalendarInternal { Ok(()) } - async fn get(&self, blob_id: BlobId, message_key: &Key) -> Result<Vec<u8>> { - todo!() + async fn get(&self, blob_id: BlobId) -> Result<Vec<u8>> { + // Fetch message from S3 + let blob_ref = storage::BlobRef(format!("{}/{}", self.cal_path, blob_id)); + let object = self.storage.blob_fetch(&blob_ref).await?; + + // Decrypt message key from headers + let key_encrypted_b64 = object + .meta + .get(MESSAGE_KEY) + .ok_or(anyhow!("Missing key in metadata"))?; + let key_encrypted = base64::engine::general_purpose::STANDARD.decode(key_encrypted_b64)?; + let message_key_raw = cryptoblob::open(&key_encrypted, &self.encryption_key)?; + let message_key = + cryptoblob::Key::from_slice(&message_key_raw).ok_or(anyhow!("Invalid message key"))?; + + // Decrypt body + let body = object.value; + cryptoblob::open(&body, &message_key) } async fn put<'a>(&mut self, entry: IndexEntry, evt: &'a [u8]) -> Result<Token> { |