def assemble_file(self, key, passphrase): """ attempts to decrypt and assemble the local file defined by the passed manifest key """ #attempt to load the manifest print('assembling....') with open(MANIFESTDIR + key, 'rb') as f: manifest = json.loads(f.read().decode()) #create eccpgp object epgp = ECCPGP() epgp.generate(passphrase) #attempt to decrypt manifest manenc = manifest['manifest'] mandec = epgp.raw_dec(b64dec(manenc), passphrase.encode()) manifest['manifest'] = json.loads(mandec.decode()) data = b'' #assemble all the blocks fi = Filer() #size = len(manifest['manifest']) #i = 0 for chunk in manifest['manifest']: data += fi.read_chunk(chunk) #print('{}% complete'.format(int((i/size)*100))) #i += 1 #create eccpgp structure and assign data struct = epgp.make_eccpgp_structure() struct['header'] = manifest['header'] struct['payload'] = data.decode() #decrypt the structure into a pgp package pack = epgp.decrypt(struct, passphrase) #write the decrypted package to assembly directory with open(ASSEMBLEDIR + pack['header']['filename'], 'wb') as f: f.write(pack['payload']) print('file assembled:\t' + ASSEMBLEDIR + pack['header']['filename'])
def assemble_file(self, key, passphrase): """ attempts to decrypt and assemble the local file defined by the passed manifest key """ #attempt to load the manifest print('assembling....') with open(MANIFESTDIR+key, 'rb') as f: manifest = json.loads(f.read().decode()) #create eccpgp object epgp = ECCPGP() epgp.generate(passphrase) #attempt to decrypt manifest manenc = manifest['manifest'] mandec = epgp.raw_dec(b64dec(manenc), passphrase.encode()) manifest['manifest'] = json.loads(mandec.decode()) data = b'' #assemble all the blocks fi = Filer() #size = len(manifest['manifest']) #i = 0 for chunk in manifest['manifest']: data += fi.read_chunk(chunk) #print('{}% complete'.format(int((i/size)*100))) #i += 1 #create eccpgp structure and assign data struct = epgp.make_eccpgp_structure() struct['header'] = manifest['header'] struct['payload'] = data.decode() #decrypt the structure into a pgp package pack = epgp.decrypt(struct, passphrase) #write the decrypted package to assembly directory with open(ASSEMBLEDIR+pack['header']['filename'], 'wb') as f: f.write(pack['payload']) print('file assembled:\t'+ASSEMBLEDIR+pack['header']['filename'])