def digests(impl): id = impl.getAttribute('id') if '=' in id: yield id.split('=', 1) for x in xmltools.children(impl, 'manifest-digest'): for name, value in x.attributes.itemsNS(): if name[0] is None: yield name[1], value
def add_digest(impl, alg_name): alg = manifest.get_algorithm(alg_name) # Scan through the existing digests # - If we've already got the one we need, return # - Otherwise, find a cached implementation we can use existing_path = None for a, value in digests(impl): if a in ('sha1', 'sha1new', 'sha256'): digest = '%s=%s' % (a, value) else: digest = '%s_%s' % (a, value) if a == alg_name: return False # Already signed with this algorithm if not existing_path: try: existing_path = stores.lookup(digest) if existing_path: existing_digest = digest except NotStored: pass # OK if existing_path is None: print("No implementations of %s cached; can't calculate new digest" % get_version(impl)) return False info("Verifying %s", existing_path) manifest.verify(existing_path, existing_digest) print("Adding new digest to version %s" % get_version(impl)) new_digest = alg.new_digest() for line in alg.generate_manifest(existing_path): new_digest.update((line + '\n').encode()) for md in xmltools.children(impl, 'manifest-digest'): break else: md = xmltools.create_element(impl, 'manifest-digest') _, digest_value = manifest.splitID(alg.getID(new_digest)) md.setAttribute(alg_name, digest_value) return True
def add_digest(impl, alg_name): alg = manifest.get_algorithm(alg_name) # Scan through the existing digests # - If we've already got the one we need, return # - Otherwise, find a cached implementation we can use existing_path = None for a, value in digests(impl): digest = '%s=%s' % (a, value) if a == alg_name: return False # Already signed with this algorithm if not existing_path: try: existing_path = stores.lookup(digest) if existing_path: existing_digest = digest except NotStored: pass # OK if existing_path is None: print "No implementations of %s cached; can't calculate new digest" % get_version(impl) return False info("Verifying %s", existing_path) manifest.verify(existing_path, existing_digest) print "Adding new digest to version %s" % get_version(impl) new_digest = alg.new_digest() for line in alg.generate_manifest(existing_path): new_digest.update(line + '\n') for md in xmltools.children(impl, 'manifest-digest'): break else: md = xmltools.create_element(impl, 'manifest-digest') md.setAttribute(alg_name, new_digest.hexdigest()) return True