def to_dict(self, pickle_key): s = SymEnc(pickle_key) return { 'algo': self.algo, 'mode': self.mode, 'block_size': self.block_size, 'encrypt': s.encrypt(self.encrypt).to_dict(), 'hmac': s.encrypt(self.hmac).to_dict() }
def txs(self): self.check_key() if self.cached_txs is not None: for tx in self.cached_txs: yield tx else: self.cached_txs = [] encor = SymEnc(self.key) for data, commit in self.walk_branch('txs'): tx = yaml.safe_load(data) tx['who'] = commit.author tx['when'] = commit.commit_time tx['amount'] = int(encor.decrypt(EncResult.from_dict(tx['amount']))) tx['description'] = encor.decrypt(EncResult.from_dict(tx['description'])) self.cached_txs.append(tx) yield tx
def create_tx(self, from_account, to_account, description, amount): self.check_key() encor = SymEnc(self.key) description = encor.encrypt(description) amount = encor.encrypt(str(amount)) tx = { 'description': description.to_dict(), 'amount': amount.to_dict(), 'to_account': to_account, 'from_account': from_account, } tx_yaml = yaml.dump(tx, default_flow_style = False) self.commit('txs',"Added Tx", data=tx_yaml)
def from_dict(pickle_key, state): s = SymEnc(pickle_key) state['encrypt'] = s.decrypt(EncResult.from_dict(state['encrypt'])) state['hmac'] = s.decrypt(EncResult.from_dict(state['hmac'])) return SymEncKey(state)