diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-20 09:01:47 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-20 09:01:47 -0500 |
commit | ef9eaa1848954d6316572871bd9c641d34ab45da (patch) | |
tree | 38291f8b3ab5772e46ad9a6e51f96731f5412d8d | |
parent | 79bc74432d42006ac0cedebc2291e8f6b6d1cddb (diff) |
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'.
-rw-r--r-- | combox/crypto.py | 17 |
1 files 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']) |