JSSE: new helper functions to throw exceptions (throwWolfSSLJNIException, throwWolfSSLException), avoids calling FindClass unnecessarily, improves performance

pull/257/head
Chris Conlon 2025-04-14 17:17:25 -06:00
parent 767a289113
commit 3aa056c607
3 changed files with 172 additions and 523 deletions

View File

@ -181,6 +181,32 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved)
g_verifyCallbackMethodId = NULL;
}
/**
* Throw WolfSSLJNIException
*/
void throwWolfSSLJNIException(JNIEnv* jenv, const char* msg)
{
jclass excClass = (*jenv)->FindClass(jenv, "com/wolfssl/WolfSSLJNIException");
if (excClass == NULL) {
/* Unable to find exception class, give up trying to throw */
return;
}
(*jenv)->ThrowNew(jenv, excClass, msg);
}
/**
* Throw WolfSSLException
*/
void throwWolfSSLException(JNIEnv* jenv, const char* msg)
{
jclass excClass = (*jenv)->FindClass(jenv, "com/wolfssl/WolfSSLException");
if (excClass == NULL) {
/* Unable to find exception class, give up trying to throw */
return;
}
(*jenv)->ThrowNew(jenv, excClass, msg);
}
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_init
(JNIEnv* jenv, jobject jcl)
{

File diff suppressed because it is too large Load Diff

View File

@ -50,4 +50,8 @@ unsigned int NativePskClientCb(WOLFSSL* ssl, const char* hint, char* identity,
unsigned int NativePskServerCb(WOLFSSL* ssl, const char* identity,
unsigned char* key, unsigned int max_key_len);
/* Helper functions to throw exceptions */
void throwWolfSSLJNIException(JNIEnv* jenv, const char* msg);
void throwWolfSSLException(JNIEnv* jenv, const char* msg);
#endif