native.jniutil.bytearrays.c Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-lts8on Show documentation
Show all versions of bcprov-lts8on Show documentation
The Long Term Stable (LTS) Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains the JCA/JCE provider and low-level API for the BC LTS version 2.73.7 for Java 8 and later.
//
//
#include "bytearrays.h"
#include
void init_bytearray_ctx(java_bytearray_ctx *ctx) {
ctx->bytearray = NULL;
ctx->array = NULL;
ctx->size = 0;
ctx->env = NULL;
}
int load_bytearray_ctx(java_bytearray_ctx *ctx, JNIEnv *env, jbyteArray array) {
ctx->env = env;
ctx->array = array;
ctx->size = 0;
ctx->bytearray = NULL;
if (array != NULL) {
ctx->size = (size_t) (*env)->GetArrayLength(env, array);
ctx->bytearray = (uint8_t *) (*env)->GetByteArrayElements(env, array, NULL);
if (ctx->bytearray == NULL) {
return 0;
}
}
return 1;
}
/**
* release_bytearray_ctx releases a java byte ctx back to the jvm
* null safe and unclaimed safe.
* @param ctx
*/
void release_bytearray_ctx(java_bytearray_ctx *ctx) {
if (ctx == NULL || ctx->array == NULL || ctx->bytearray == NULL || ctx->env == NULL) {
return;
}
// ctx->array and ctx->env can't be NULL.
(*(ctx->env))->ReleaseByteArrayElements(ctx->env, ctx->array, (jbyte *) ctx->bytearray, 0);
ctx->bytearray = NULL;
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy