chunk_streamer/
chunk_encrypter.rs1use std::time::Instant;
2use ant_core::data::error::{Error, Result};
3use ant_core::data::{DataMap};
4use bytes::Bytes;
5use log::debug;
6use self_encryption::{encrypt, EncryptedChunk};
7
8pub struct ChunkEncrypter {
9}
10
11impl ChunkEncrypter {
12 pub fn new() -> Self {
13 Self {}
14 }
15
16 pub async fn encrypt(
17 &self,
18 is_public: bool,
19 bytes: Bytes
20 ) -> Result<(Vec<EncryptedChunk>, DataMap)> {
21 let start = Instant::now();
22 let (data_map_chunk, chunks) = match encrypt(bytes) {
23 Ok((data_map_chunk, chunks)) => (data_map_chunk, chunks),
24 Err(error) => return Err(Error::Encryption(error.to_string())),
25 };
26
27 debug!("Encryption took: {:.2?}", start.elapsed());
33 Ok((chunks, data_map_chunk))
34 }
35}