Skip to content

Commit

Permalink
feat: encrypt from file
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and joshuef committed Sep 4, 2023
1 parent 5932d06 commit b7f0a38
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub use self::{
};
use bytes::Bytes;
use itertools::Itertools;
use std::ops::Range;
use std::{fs::File, io::Read, ops::Range, path::Path};
use xor_name::XorName;

// export these because they are used in our public API.
Expand All @@ -134,6 +134,16 @@ pub struct EncryptedChunk {
pub content: Bytes,
}

/// Read a file from the disk to encrypt.
pub fn encrypt_from_file(file_path: &Path) -> Result<(DataMap, Vec<EncryptedChunk>)> {
let mut file = File::open(file_path)?;
let mut bytes = Vec::new();
let _ = file.read_to_end(&mut bytes)?;
let bytes = Bytes::from(bytes);

encrypt(bytes)
}

/// Encrypts a set of bytes and returns the encrypted data together with
/// the data map that is derived from the input data, and is used to later decrypt the encrypted data.
/// Returns an error if the size is too small for self-encryption.
Expand Down

0 comments on commit b7f0a38

Please sign in to comment.