-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_cloud.py
More file actions
43 lines (40 loc) · 1.56 KB
/
local_cloud.py
File metadata and controls
43 lines (40 loc) · 1.56 KB
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
import os, hashlib
class LocalCloudManager:
def __init__(self):
os.makedirs("local_uploads", exist_ok=True)
self.providers = ["LOCAL-AWS", "LOCAL-GCP", "LOCAL-AZURE"]
def upload_file_chunks(self, file_id, encrypted_data):
"""Split file into 3 chunks and save locally"""
size = len(encrypted_data)
part = size // 3
paths = {}
for i in range(3):
start = i * part
end = (i + 1) * part if i < 2 else size
chunk = encrypted_data[start:end]
name = f"{file_id}_chunk{i}.bin"
path = os.path.join("local_uploads", name)
with open(path, "wb") as f:
f.write(chunk)
paths[f"chunk_{i}"] = {
"provider": self.providers[i],
"path": path,
"sha512": hashlib.sha512(chunk).hexdigest()
}
print(f" Saved {name} to {self.providers[i]}")
return paths
def upload_key_shares(self, file_id, shares):
"""Save Shamir key shares locally"""
paths = {}
for i, (idx, share) in enumerate(shares):
name = f"{file_id}_share{idx}.key"
path = os.path.join("local_uploads", name)
with open(path, "wb") as f:
f.write(share)
paths[f"share_{idx}"] = {
"provider": self.providers[i % 3],
"path": path,
"sha512": hashlib.sha512(share).hexdigest()
}
print(f"Stored key share {idx} to {self.providers[i % 3]}")
return paths