-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfshare_test.py
89 lines (72 loc) · 4.16 KB
/
cfshare_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import hashlib
import os
import unittest
from os.path import isfile, join
from cfshare import CFShare, CipherMode
class TestCFShare(unittest.TestCase):
def test_split_reconstruct_AES(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 3, 5, mode=CipherMode.AES)
CFShare.reconstruct_file(['unittest1_5', 'unittest3_5', 'unittest5_5'], 'unittest_rec')
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def test_split_reconstruct_AES_frag(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 5, 5, mode=CipherMode.AES)
CFShare.reconstruct_file(['unittest3_5', 'unittest1_5', 'unittest2_5', 'unittest4_5', 'unittest5_5'], 'unittest_rec')
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def test_split_reconstruct_AES_shares_only(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 3, 5, mode=CipherMode.AES, sharesonly=True)
CFShare.reconstruct_file(['unittest'],'unittest_rec', fshares=['unittest1_5.share', 'unittest3_5.share', 'unittest5_5.share'])
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def test_split_reconstruct_ChaCha20(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 3, 5, mode=CipherMode.ChaCha20)
CFShare.reconstruct_file(['unittest1_5', 'unittest3_5', 'unittest5_5'], 'unittest_rec')
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def test_split_reconstruct_ChaCha20_frag(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 5, 5, mode=CipherMode.ChaCha20)
CFShare.reconstruct_file(['unittest3_5', 'unittest1_5', 'unittest2_5', 'unittest4_5', 'unittest5_5'], 'unittest_rec')
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def test_split_reconstruct_ChaCha20_shares_only(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 3, 5, mode=CipherMode.ChaCha20, sharesonly=True)
CFShare.reconstruct_file(['unittest'],'unittest_rec', fshares=['unittest1_5.share', 'unittest3_5.share', 'unittest5_5.share'])
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def test_split_reconstruct_Camellia(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 3, 5, mode=CipherMode.Camellia)
CFShare.reconstruct_file(['unittest1_5', 'unittest3_5', 'unittest5_5'], 'unittest_rec')
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def test_split_reconstruct_Camellia_frag(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 5, 5, mode=CipherMode.Camellia)
CFShare.reconstruct_file(['unittest3_5', 'unittest1_5', 'unittest2_5', 'unittest4_5', 'unittest5_5'], 'unittest_rec')
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def test_split_reconstruct_Camellia_shares_only(self):
hash_original = _get_sha256_file('setup.py')
CFShare.split_file('setup.py', 'unittest', 3, 5, mode=CipherMode.Camellia, sharesonly=True)
CFShare.reconstruct_file(['unittest'],'unittest_rec', fshares=['unittest1_5.share', 'unittest3_5.share', 'unittest5_5.share'])
self.assertEqual(hash_original, _get_sha256_file('unittest_rec'))
_cleanup()
def _get_sha256_file(file):
with open(file, "rb") as f:
bytes = f.read() # read entire file as bytes
readable_hash = hashlib.sha256(bytes).hexdigest()
return readable_hash
def _cleanup():
pdir = os.path.dirname(os.path.abspath(__file__))
files = [f for f in os.listdir(pdir) if isfile(join(pdir, f)) and f.startswith('unittest')]
for f in files:
os.remove(f)
if __name__ == '__main__':
unittest.main()