From ef9eaa1848954d6316572871bd9c641d34ab45da Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Fri, 20 Feb 2015 09:01:47 -0500 Subject: Refactored combox.crypto.split_and_encrypt function. Now it accepts an optional third argument `fcontent' (defaults to None) which contains the contents of the file `fpath'. --- combox/crypto.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/combox/crypto.py b/combox/crypto.py index 2d381d0..273de71 100644 --- a/combox/crypto.py +++ b/combox/crypto.py @@ -91,12 +91,16 @@ def decrypt_shards(ciphers, secret): return shards -def split_and_encrypt(fpath, config): - """ - Splits the file, encrypts the shards and writes them to the nodes. +def split_and_encrypt(fpath, config, fcontent=None): + """Splits the file, encrypts the shards and writes them to the nodes. fpath: The path to file that has to be split. config: The dictonary containing the combox configuration information. + fcontent: Contents of the file at `fpath' (optional). + + If `fcontent' is None, then this function reads the contents of + the file; otherwise it just assumes `fcontent' is the content of + the file. """ rel_path = relative_path(fpath, config) @@ -105,8 +109,11 @@ def split_and_encrypt(fpath, config): SHARDS = len(config['nodes_info'].keys()) f = path.join(config['combox_dir'], rel_path) - f_content = read_file(f) - f_shards = split_data(f_content, SHARDS) + + if not fcontent: + fcontent = read_file(f) + + f_shards = split_data(fcontent, SHARDS) # encrypt shards ciphered_shards = encrypt_shards(f_shards, config['topsecret']) -- cgit v1.2.3