def dump_top_key_tuple(top_key_tuple, out_func=default_out): """ Debugging function to print a top_key_tuple. """ out_func("--- %s top key tuple---\n" % HDR_BYTES) for index, chk in enumerate(top_key_tuple[0]): out_func("graph_%s:%s\n" % (chr(ord('a') + index), chk)) for index, update in enumerate(top_key_tuple[1]): if update[4] and update[5]: text = "full graph info" elif not (update[4] or update[5]): text = "incomplete parent, head lists" elif not update[4]: text = "incomplete parent list" else: text = "incomplete head list" out_func("update[%i] (%s)\n" % (index, text)) out_func(" length : %i\n" % update[0]) out_func(" parents: %s\n" % ' '.join([ver[:12] for ver in update[1]])) out_func(" heads : %s\n" % ' '.join([ver[:12] for ver in update[2]])) for index, chk in enumerate(update[3]): out_func(" CHK[%i]:%s\n" % (index, chk)) out_func("binary rep sha1:\n0x00:%s\n0xff:%s\n" % (sha1_hexdigest(top_key_tuple_to_bytes(top_key_tuple, 0)), sha1_hexdigest(top_key_tuple_to_bytes(top_key_tuple, 0xff)))) out_func("---\n")
def get_bundle_path(self, index_pair): """ INTERNAL: Get the full path to a bundle file for the given edge. """ bundle_id = sha1_hexdigest( ''.join(self.graph.index_table[index_pair[0]][0]) + '|' # hmmm really needed? + ''.join(self.graph.index_table[index_pair[0]][1]) + ''.join(self.graph.index_table[index_pair[1]][0]) + '|' # hmmm really needed? + ''.join(self.graph.index_table[index_pair[1]][1])) return os.path.join(self.base_dir, "_tmp_%s.hg" % bundle_id)
def get_bundle_path(self, index_pair): """ INTERNAL: Get the full path to a bundle file for the given edge. """ bundle_id = sha1_hexdigest( "".join(self.graph.index_table[index_pair[0]][0]) + "|" # hmmm really needed? + "".join(self.graph.index_table[index_pair[0]][1]) + "".join(self.graph.index_table[index_pair[1]][0]) + "|" # hmmm really needed? + "".join(self.graph.index_table[index_pair[1]][1]) ) return os.path.join(self.base_dir, "_tmp_%s.hg" % bundle_id)
def dump_top_key_tuple(top_key_tuple, out_func=default_out): """ Debugging function to print a top_key_tuple. """ out_func("--- %s top key tuple---\n" % HDR_BYTES) out_func("age: %i\n" % top_key_tuple[2]) for index, block in enumerate(top_key_tuple[0]): out_func("block[%i]\n len: %i max age: %i\n" % (index, block[0], block[2])) for chk in block[1]: out_func(" %s\n" % chk) for index, obj in enumerate(top_key_tuple[1]): out_func("root_sha[%i]: %s %i\n" % (index, sha1_hexdigest(obj[0]), obj[1])) out_func("---\n")
def check_usk_hash(usk, hash_value): """ Returns True if the hash matches, False otherwise. """ return (sha1_hexdigest(get_usk_for_usk_version(usk, 0))[:12] == hash_value)
def get_usk_hash(usk): """ Returns a 12 hex digit hash for a USK which is independant of verison. """ return sha1_hexdigest(get_usk_for_usk_version(usk, 0))[:12]
def chk_file_name(chk): """ Return a file name for the CHK. """ return CHK_NAME_FMT % sha1_hexdigest(chk)