def include_admin_info(self, dat, admin_info, keypair): if keypair is not None: dat[KeyType. admin_info] = message_key_types.make_TLV_formatted_message( admin_info) digest = hashlib.sha256(dat[KeyType.admin_info]).digest() dat[KeyType.nodekey_signature] = keypair.sign(digest) else: dat.update(admin_info)
def include_admin_info_into_message_if_needed(self, domain_id, msg, admin_info): """Serialize admin info into one binary object and add signature""" admin_info[KeyType.message_seq] = self.domains[domain_id]["neighbor"].admin_sequence_number + 1 self.domains[domain_id]["neighbor"].admin_sequence_number += 1 if "keypair" in self.domains[domain_id] and self.domains[domain_id]["keypair"] is not None: msg[KeyType.admin_info] = message_key_types.make_TLV_formatted_message(admin_info) digest = hashlib.sha256(msg[KeyType.admin_info]).digest() msg[KeyType.nodekey_signature] = self.domains[domain_id]["keypair"]['keys'][0].sign(digest) else: msg.update(admin_info)
def test_01_serialize(self): print("\n-----", sys._getframe().f_code.co_name, "-----") msg = { KeyType.source_node_id: bbclib.get_new_id("aaa"), KeyType.destination_node_id: bbclib.get_new_id("bbb"), KeyType.status: True, KeyType.random: int(8000).to_bytes(4, "little") } pprint.pprint(msg) global msg_data msg_data = message_key_types.make_TLV_formatted_message(msg)