All Downloads are FREE. Search and download functionalities are using the official Maven repository.

native.jniutil.longarraycritical.c Maven / Gradle / Ivy

Go to download

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.1 for Java 8 and later.

There is a newer version: 2.73.6
Show newest version
//

//

#include 
#include 
#include 
#include "longarraycritical.h"


void init_critical_long_ctx(critical_longarray_ctx *ctx, JNIEnv *env, jlongArray array) {

    ctx->env = env;
    ctx->array = array;
    ctx->size = 0;
    ctx->critical = NULL;

    if (array != NULL) {
        ctx->size = (size_t) (*env)->GetArrayLength(env, array);
    }
}


/**
 * Get the critical array ptr if necessary from the jvm if not already claimed, and not a null long array.
 * @param ctx pointer to the java_longarray_ctx
 * @return true if, the underlying array is null, the array has already been claimed, or claiming was successful.
 * false if the jvm was expected to return a pointer but did not do so.
 */
bool load_critical_long_ctx(critical_longarray_ctx *ctx) {
    if (ctx == NULL) {
        return false; // fail on no context
    }

    if (ctx->array == NULL || ctx->critical != NULL) {
        return true; // Already claimed from jvm or the java side passed a null array.
    }


    ctx->critical = (*(ctx->env))->GetPrimitiveArrayCritical(ctx->env, ctx->array, NULL);
    if (ctx->critical == NULL) {
        return false; // We didn't get a valid array.
    }

    return true;
}


/**
 * release_critical_ctx releases a java byte ctx back to the jvm
 * null safe and unclaimed safe.
 * @param ctx
 */
void release_critical_long_ctx(critical_longarray_ctx *ctx) {
    if (ctx == NULL || ctx->array == NULL || ctx->critical == NULL || ctx->env == NULL) {
        return;
    }


    // ctx->array and ctx->env can't be NULL.
    (*(ctx->env))->ReleasePrimitiveArrayCritical(ctx->env, ctx->array, (jlong *) ctx->critical, 0);
    ctx->critical = NULL;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy