From 5cc1dc560ff605a6d582ea0d94ed65b0295cf324 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 13 May 2022 08:25:34 +0300 Subject: change put to take a vector of bytes Sponsored-by: author --- src/chunkstore.rs | 16 +++++----------- src/client.rs | 3 ++- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/chunkstore.rs b/src/chunkstore.rs index 1f67e2f..cb78891 100644 --- a/src/chunkstore.rs +++ b/src/chunkstore.rs @@ -6,7 +6,6 @@ use crate::chunkid::ChunkId; use crate::chunkmeta::ChunkMeta; -use crate::cipher::EncryptedChunk; use crate::config::{ClientConfig, ClientConfigError}; use crate::index::{Index, IndexError}; @@ -50,11 +49,7 @@ impl ChunkStore { /// Store a chunk in the store. /// /// The store chooses an id for the chunk. - pub async fn put( - &mut self, - chunk: EncryptedChunk, - meta: &ChunkMeta, - ) -> Result { + pub async fn put(&mut self, chunk: Vec, meta: &ChunkMeta) -> Result { match self { Self::Local(store) => store.put(chunk, meta), Self::Remote(store) => store.put(chunk, meta).await, @@ -90,7 +85,7 @@ impl LocalStore { .map_err(StoreError::Index) } - fn put(&mut self, chunk: EncryptedChunk, meta: &ChunkMeta) -> Result { + fn put(&mut self, chunk: Vec, meta: &ChunkMeta) -> Result { let id = ChunkId::new(); let (dir, filename) = self.filename(&id); @@ -98,8 +93,7 @@ impl LocalStore { std::fs::create_dir_all(&dir).map_err(|err| StoreError::ChunkMkdir(dir, err))?; } - let data = chunk.ciphertext().to_vec(); - std::fs::write(&filename, &data) + std::fs::write(&filename, &chunk) .map_err(|err| StoreError::WriteChunk(filename.clone(), err))?; self.index .insert_meta(id.clone(), meta.clone()) @@ -162,12 +156,12 @@ impl RemoteStore { Ok(ids) } - async fn put(&self, chunk: EncryptedChunk, meta: &ChunkMeta) -> Result { + async fn put(&self, chunk: Vec, meta: &ChunkMeta) -> Result { let res = self .client .post(&self.chunks_url()) .header("chunk-meta", meta.to_json()) - .body(chunk.ciphertext().to_vec()) + .body(chunk) .send() .await .map_err(StoreError::ReqwestError)?; diff --git a/src/client.rs b/src/client.rs index 7b15bba..7ae6581 100644 --- a/src/client.rs +++ b/src/client.rs @@ -131,7 +131,8 @@ impl BackupClient { /// Upload a data chunk to the server. pub async fn upload_chunk(&mut self, chunk: DataChunk) -> Result { let enc = self.cipher.encrypt_chunk(&chunk)?; - let id = self.store.put(enc, chunk.meta()).await?; + let data = enc.ciphertext().to_vec(); + let id = self.store.put(data, chunk.meta()).await?; Ok(id) } -- cgit v1.2.1