14 int processStatus(JNIEnv *env, jint
status)
17 jmethodID exConstructor;
20 if (status >= cryptlib_crypt_OK)
23 exClass = (*env)->FindClass(env,
"cryptlib/CryptException");
26 printf(
"java_jni.c:processStatus - no class?!\n");
30 exConstructor = (*env)->GetMethodID(env, exClass,
"<init>",
"(I)V");
31 if (exConstructor == 0)
33 printf(
"java_jni.c:processStatus - no constructor?!\n");
37 obj = (*env)->NewObject(env, exClass, exConstructor, status);
40 printf(
"java_jni.c:processStatus - no object?!\n");
44 if ((*env)->Throw(env, obj) < 0)
46 printf(
"java_jni.c:processStatus - failed to throw?!\n");
52 jobject processStatusReturnCryptQueryInfo(JNIEnv *env,
int status,
CRYPT_QUERY_INFO returnValue)
55 jmethodID exConstructor;
59 if (status < cryptlib_crypt_OK)
62 exClass = (*env)->FindClass(env,
"cryptlib/CRYPT_QUERY_INFO");
65 printf(
"java_jni.c:processStatusReturnCryptQueryInfo - no class?!\n");
69 exConstructor = (*env)->GetMethodID(env, exClass,
"<init>",
"(Ljava/lang/String;IIII)V");
70 if (exConstructor == 0)
72 printf(
"java_jni.c:processStatusReturnCryptQueryInfo - no constructor?!\n");
76 algoName = (*env)->NewStringUTF(env, returnValue.
algoName);
81 printf(
"java_jni.c:processStatusReturnCryptQueryInfo - no object?!\n");
88 jobject processStatusReturnCryptObjectInfo(JNIEnv *env,
int status,
CRYPT_OBJECT_INFO returnValue)
91 jmethodID exConstructor;
95 if (status < cryptlib_crypt_OK)
98 exClass = (*env)->FindClass(env,
"cryptlib/CRYPT_OBJECT_INFO");
101 printf(
"java_jni.c:processStatusReturnCryptObjectInfo - no class?!\n");
105 exConstructor = (*env)->GetMethodID(env, exClass,
"<init>",
"(IIII[B)V");
106 if (exConstructor == 0)
108 printf(
"java_jni.c:processStatusReturnCryptObjectInfo - no constructor?!\n");
112 salt = (*env)->NewByteArray(env, returnValue.
saltSize);
113 (*env)->SetByteArrayRegion(env, salt, 0, returnValue.
saltSize, returnValue.
salt);
118 printf(
"java_jni.c:processStatusReturnCryptObjectInfo - no object?!\n");
125 int checkIndicesArray(JNIEnv *env, jbyteArray array,
int sequenceOffset,
int sequenceLength)
132 if (sequenceOffset == 0)
136 exClass = (*env)->FindClass(env,
"java/lang/ArrayIndexOutOfBoundsException");
138 printf(
"java_jni.c:checkIndicesArray - no class?!\n");
140 if ((*env)->ThrowNew(env, exClass,
"") < 0)
141 printf(
"java_jni.c:checkIndicesArray - failed to throw?!\n");
146 arrayLength = (*env)->GetArrayLength(env, array);
148 if (sequenceOffset < 0 ||
149 sequenceOffset >= arrayLength ||
150 sequenceOffset + sequenceLength > arrayLength)
152 exClass = (*env)->FindClass(env,
"java/lang/ArrayIndexOutOfBoundsException");
154 printf(
"java_jni.c:checkIndicesArray - no class?!\n");
156 if ((*env)->ThrowNew(env, exClass,
"") < 0)
157 printf(
"java_jni.c:checkIndicesArray - failed to throw?!\n");
163 int getPointerArray(JNIEnv* env, jbyteArray array, jbyte** bytesPtrPtr)
169 (*bytesPtrPtr) = NULL;
173 (*bytesPtrPtr) = (*env)->GetByteArrayElements(env, array, &isCopy);
175 if (*bytesPtrPtr == NULL)
177 printf(
"java_jni.c:getPointer - failed to get elements of array?!\n");
183 void releasePointerArray(JNIEnv* env,jbyteArray array, jbyte* bytesPtr)
185 if (bytesPtr == NULL)
187 (*env)->ReleaseByteArrayElements(env, array, bytesPtr, 0);
190 int checkIndicesNIO(JNIEnv *env, jobject byteBuffer,
int sequenceOffset,
int sequenceLength)
192 jlong byteBufferLength;
195 if (byteBuffer == NULL)
197 if (sequenceOffset == 0)
201 exClass = (*env)->FindClass(env,
"java/lang/ArrayIndexOutOfBoundsException");
203 printf(
"java_jni.c:checkIndicesNIO - no class?!\n");
205 if ((*env)->ThrowNew(env, exClass,
"") < 0)
206 printf(
"java_jni.c:checkIndicesNIO - failed to throw?!\n");
211 byteBufferLength = (*env)->GetDirectBufferCapacity(env, byteBuffer);
212 if (byteBufferLength == -1)
214 exClass = (*env)->FindClass(env,
"java/lang/UnsupportedOperationException");
216 printf(
"java_jni.c:checkIndicesNIO - no class?!\n");
218 if ((*env)->ThrowNew(env, exClass,
219 "Either a non-direct ByteBuffer was passed or your JVM doesn't support JNI access to direct ByteBuffers") < 0)
220 printf(
"java_jni.c:checkIndicesNIO - failed to throw?!\n");
224 if (sequenceOffset < 0 ||
225 sequenceOffset >= byteBufferLength ||
226 sequenceOffset + sequenceLength > byteBufferLength)
228 exClass = (*env)->FindClass(env,
"java/lang/ArrayIndexOutOfBoundsException");
230 printf(
"java_jni.c:checkIndicesNIO - no class?!\n");
232 if ((*env)->ThrowNew(env, exClass,
"") < 0)
233 printf(
"java_jni.c:checkIndicesNIO - failed to throw?!\n");
239 int getPointerNIO(JNIEnv* env, jobject byteBuffer, jbyte** bytesPtrPtr)
243 if (byteBuffer == NULL)
245 (*bytesPtrPtr) = NULL;
249 (*bytesPtrPtr) = (*env)->GetDirectBufferAddress(env, byteBuffer);
251 if (*bytesPtrPtr == NULL)
253 exClass = (*env)->FindClass(env,
"java/lang/UnsupportedOperationException");
255 printf(
"java_jni.c:getPointerNIO - no class?!\n");
257 if ((*env)->ThrowNew(env, exClass,
"Your JVM doesn't support JNI access to direct ByteBuffers") < 0)
258 printf(
"java_jni.c:getPointerNIO - failed to throw?!\n");
264 void releasePointerNIO(JNIEnv* env,jbyteArray array, jbyte* bytesPtr)
268 int getPointerString(JNIEnv* env, jstring str, jbyte** bytesPtrPtr)
272 const jbyte* rawBytesPtr;
281 (*bytesPtrPtr) = NULL;
285 rawBytesPtr = (*env)->GetStringUTFChars(env, str, &isCopy);
287 if (rawBytesPtr == NULL)
289 printf(
"java_jni.c:getPointerString - failed to get elements of String?!\n");
293 strLength = (*env)->GetStringUTFLength(env, str);
296 (*bytesPtrPtr) = (jbyte*)malloc(strLength*2+2);
298 (*bytesPtrPtr) = (jbyte*)malloc(strLength+1);
301 if (*bytesPtrPtr == NULL)
303 exClass = (*env)->FindClass(env,
"java/lang/OutOfMemoryError");
305 printf(
"java_jni.c:getPointerString - no class?!\n");
307 if ((*env)->ThrowNew(env, exClass,
"") < 0)
308 printf(
"java_jni.c:getPointerString - failed to throw?!\n");
309 (*env)->ReleaseStringUTFChars(env, str, rawBytesPtr);
314 status = asciiToUnicode (*bytesPtrPtr, strLength*2+2, rawBytesPtr, strLength+1);
316 (*env)->ReleaseStringUTFChars(env, str, rawBytesPtr);
320 memcpy(*bytesPtrPtr, rawBytesPtr, strLength);
321 (*bytesPtrPtr)[strLength] = 0;
324 (*env)->ReleaseStringUTFChars(env, str, rawBytesPtr);
329 void releasePointerString(JNIEnv* env, jstring str, jbyte* bytesPtr)
331 if (bytesPtr == NULL)