From 272b93f04a0640e056fe994f48cb2837eacdad46 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 4 Apr 2024 14:59:47 +0200 Subject: GET logic --- aero-collections/src/calendar/mod.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'aero-collections') 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> { - self.internal.read().await.get(evt_id, message_key).await + pub async fn get(&self, evt_id: UniqueIdent) -> Result> { + 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> { - todo!() + async fn get(&self, blob_id: BlobId) -> Result> { + // 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 { -- cgit v1.2.3