Module rugged.commands.lib.verification_keys

Functions

def get_keyid(key_value: Dict[str, Any]) ‑> str
Expand source code
def get_keyid(key_value: Dict[str, Any]) -> str:
    """ Return the keyid of a given TUF key dict. """

    # See: securesystemslib.keys._get_keyid()
    key_meta = format_keyval_to_metadata(_get_key_type(), _get_key_scheme(), key_value)
    key_update_data: str | None = encode_canonical(key_meta)
    if key_update_data is None:
        raise RuggedKeyError("Error generating KeyID.")

    digest_object = digest("sha256")
    digest_object.update(key_update_data.encode("utf-8"))
    keyid = digest_object.hexdigest()

    return keyid

Return the keyid of a given TUF key dict.

def load_pem_public_key(data, backend=None)
def load_verification_key(key_type: str, path_to_public_key: str) ‑> Tuple[str, Dict[str, Any]]
Expand source code
def load_verification_key(key_type: str, path_to_public_key: str) -> Tuple[str, Dict[str, Any]]:
    """ Load a key from disk and return it as a TUF key. """

    # @TODO: Use match statement once we move to Python 3.10.
    # @TODO: Also, move to Python 3.10.
    if key_type == 'tuf':
        return _load_tuf_verification_key(path_to_public_key)
    elif key_type == 'pem':
        return _load_pem_verification_key(path_to_public_key)
    else:
        log.error(f"The '{key_type}' key type is not supported.")
        sys.exit(os.EX_USAGE)

Load a key from disk and return it as a TUF key.