find_jws(struct tang_keys_info* tki, const char* thp)
{
    if (!tki) {
        return NULL;
    }

    if (thp == NULL) {
        /* Default advertisement. */
        json_auto_t* jws = jwk_sign(tki->m_payload, tki->m_sign);
        if (!jws) {
            return NULL;
        }
        return json_incref(jws);
    }

    json_auto_t* jwk = find_by_thp(tki, thp);
    if (!jwk_valid_for_signing(jwk)) {
        return NULL;
    }

    json_auto_t* sign = json_deep_copy(tki->m_sign);
    if (json_array_append(sign, jwk) == -1) {
        return NULL;
    }
    json_auto_t* jws = jwk_sign(tki->m_payload, sign);
    if (!jws) {
        return NULL;
    }
    return json_incref(jws);
}
find_jws(struct tang_keys_info* tki, const char* thp)
{
    if (!tki) {
        return NULL;
    }

    if (thp == NULL) {
         
        json_auto_t* jws = jwk_sign(tki->m_payload, tki->m_sign);
        if (!jws) {
            return NULL;
        }
        return json_incref(jws);
    }

    json_auto_t* jwk = find_by_thp(tki, thp);
    if (!jwk_valid_for_signing(jwk)) {
        return NULL;
    }

    json_auto_t* sign = json_deep_copy(tki->m_sign);
    if (json_array_append(sign, jwk) == -1) {
        return NULL;
    }
    json_auto_t* jws = jwk_sign(tki->m_payload, sign);
    if (!jws) {
        return NULL;
    }
    return json_incref(jws);
}