/* As much as I'd like to make X509_check_purpose use a "const" X509* I really can't because it does recalculate hashes and do other non-const things.  */
int X509_check_purpose(X509 *x, int id, int ca)
/* As much as I'd like to make X509_check_purpose use a "const" X509* I really can't because it does recalculate hashes and do other non-const things.  */
int X509_check_purpose(X509 *x, int id, int ca)
{
    int idx;
    const X509_PURPOSE *pt;
    if (!(x->ex_flags & EXFLAG_SET)) {
        x509v3_cache_extensions(x);
    }
    if (id == -1)
        return 1;
    idx = X509_PURPOSE_get_by_id(id);
    if (idx == -1)
        return -1;
    pt = X509_PURPOSE_get0(idx);
    return pt->check_purpose(pt, x, ca);
}