def check_public_key(pk):
    """ Checks if a given string is a public (or at least if it is formatted as if it is).

    :param pk: ECDSA public key to be checked.
    :type pk: hex str
    :return: True if the key matches the format, raise exception otherwise.
    :rtype: bool
    """
    prefix = pk[0:2]
    l = len(pk)
    if prefix not in ['02', '03', '04']:
        raise Exception('Wrong public key format.')
    if prefix == '04' and l != 130:
        raise Exception('Wrong length for an uncompressed public key: ' +
            str(l))
    elif prefix in ['02', '03'] and l != 66:
        raise Exception('Wrong length for a compressed public key: ' + str(l))
    else:
        return True
