Exemple #1
0
//------------------------------------------------------------------------------
string dump_gpgme_error_t(gpgme_error_t err)
{
    string buf;
    size_t n = 1024;
    buf.resize(n);
    const int res = gpgme_strerror_r(err, buf.data(), n);
    if(res != 0)
        return "Failed to fetch error description";
    else
        buf.resize(strlen(buf.c_str()));
    
    return fmt::to_string(buf, " [", gpgme_strsource(err), ']');
}
jboolean UTILS_onErrorThrowException(JNIEnv* env, gpgme_error_t err)
{
    if (err) {
        char exceptionString[BUF_LEN];  /* this is enough */
        int spaceUsed;
        jclass exception =
            (*env)->FindClass(env, "com/freiheit/gnupg/GnuPGException");

        if (exception == NULL) {
            return JNI_TRUE;
        }
        spaceUsed = snprintf(exceptionString, BUF_LEN, "%u: ", err);
        gpgme_strerror_r(err, exceptionString + spaceUsed, BUF_LEN - spaceUsed);
        (*env)->ThrowNew(env, exception, exceptionString);
        (*env)->DeleteLocalRef(env, exception);
        return JNI_TRUE;
    } else {
        return JNI_FALSE;
    }
}