//
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-3.0-only
//

// Generated by zkgroup/codegen/codegen.py - do not edit

#![allow(non_snake_case)]

use std::panic;

use crate::ffi::constants::*;

extern crate jni;

use super::simpleapi;

use jni::sys::jint;

// This is the interface to the JVM that we'll
// call the majority of our methods on.
use jni::JNIEnv;

// These objects are what you should use as arguments to your native function.
// They carry extra lifetime information to prevent them escaping this context
// and getting used after being GC'd.
use jni::objects::JClass;

// This is just a pointer. We'll be returning it from our function.
// We can't return one of the objects with lifetime information because the
// lifetime checker won't let us.
use jni::sys::jbyteArray;

fn u8toi8(input: Vec<u8>) -> Vec<i8> {
    let mut out: Vec<i8> = Default::default();
    for &i in &input {
        out.push(i as i8);
    }
    out
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyGetCommitmentJNI(
    env: JNIEnv,
    _class: JClass,
    profileKey: jbyteArray,
    uuid: jbyteArray,
    profileKeyCommitmentOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key = env.convert_byte_array(profileKey).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let mut profile_key_commitment: Vec<u8> =
            vec![0; env.get_array_length(profileKeyCommitmentOut).unwrap() as usize];

        let ffi_return =
            simpleapi::ProfileKey_getCommitment(&profile_key, &uuid, &mut profile_key_commitment);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            profileKeyCommitmentOut,
            0,
            &u8toi8(profile_key_commitment)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyGetProfileKeyVersionJNI(
    env: JNIEnv,
    _class: JClass,
    profileKey: jbyteArray,
    uuid: jbyteArray,
    profileKeyVersionOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key = env.convert_byte_array(profileKey).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let mut profile_key_version: Vec<u8> =
            vec![0; env.get_array_length(profileKeyVersionOut).unwrap() as usize];

        let ffi_return = simpleapi::ProfileKey_getProfileKeyVersion(
            &profile_key,
            &uuid,
            &mut profile_key_version,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(profileKeyVersionOut, 0, &u8toi8(profile_key_version)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCommitmentCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCommitment: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_commitment = env.convert_byte_array(profileKeyCommitment).unwrap();

        let ffi_return =
            simpleapi::ProfileKeyCommitment_checkValidContents(&profile_key_commitment);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsGenerateDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    randomness: jbyteArray,
    groupSecretParamsOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let randomness = env.convert_byte_array(randomness).unwrap();
        let mut group_secret_params: Vec<u8> =
            vec![0; env.get_array_length(groupSecretParamsOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_generateDeterministic(
            &randomness,
            &mut group_secret_params,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(groupSecretParamsOut, 0, &u8toi8(group_secret_params)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsDeriveFromMasterKeyJNI(
    env: JNIEnv,
    _class: JClass,
    groupMasterKey: jbyteArray,
    groupSecretParamsOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_master_key = env.convert_byte_array(groupMasterKey).unwrap();
        let mut group_secret_params: Vec<u8> =
            vec![0; env.get_array_length(groupSecretParamsOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_deriveFromMasterKey(
            &group_master_key,
            &mut group_secret_params,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(groupSecretParamsOut, 0, &u8toi8(group_secret_params)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();

        let ffi_return = simpleapi::GroupSecretParams_checkValidContents(&group_secret_params);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsGetMasterKeyJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
    groupMasterKeyOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let mut group_master_key: Vec<u8> =
            vec![0; env.get_array_length(groupMasterKeyOut).unwrap() as usize];

        let ffi_return =
            simpleapi::GroupSecretParams_getMasterKey(&group_secret_params, &mut group_master_key);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(groupMasterKeyOut, 0, &u8toi8(group_master_key)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsGetPublicParamsJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
    groupPublicParamsOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let mut group_public_params: Vec<u8> =
            vec![0; env.get_array_length(groupPublicParamsOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_getPublicParams(
            &group_secret_params,
            &mut group_public_params,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(groupPublicParamsOut, 0, &u8toi8(group_public_params)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsEncryptUuidJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
    uuid: jbyteArray,
    uuidCiphertextOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let mut uuid_ciphertext: Vec<u8> =
            vec![0; env.get_array_length(uuidCiphertextOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_encryptUuid(
            &group_secret_params,
            &uuid,
            &mut uuid_ciphertext,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(uuidCiphertextOut, 0, &u8toi8(uuid_ciphertext)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsDecryptUuidJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
    uuidCiphertext: jbyteArray,
    uuidOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let uuid_ciphertext = env.convert_byte_array(uuidCiphertext).unwrap();
        let mut uuid: Vec<u8> = vec![0; env.get_array_length(uuidOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_decryptUuid(
            &group_secret_params,
            &uuid_ciphertext,
            &mut uuid,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(uuidOut, 0, &u8toi8(uuid)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsEncryptProfileKeyJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
    profileKey: jbyteArray,
    uuid: jbyteArray,
    profileKeyCiphertextOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let profile_key = env.convert_byte_array(profileKey).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let mut profile_key_ciphertext: Vec<u8> =
            vec![0; env.get_array_length(profileKeyCiphertextOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_encryptProfileKey(
            &group_secret_params,
            &profile_key,
            &uuid,
            &mut profile_key_ciphertext,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            profileKeyCiphertextOut,
            0,
            &u8toi8(profile_key_ciphertext)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsDecryptProfileKeyJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
    profileKeyCiphertext: jbyteArray,
    uuid: jbyteArray,
    profileKeyOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let profile_key_ciphertext = env.convert_byte_array(profileKeyCiphertext).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let mut profile_key: Vec<u8> =
            vec![0; env.get_array_length(profileKeyOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_decryptProfileKey(
            &group_secret_params,
            &profile_key_ciphertext,
            &uuid,
            &mut profile_key,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(profileKeyOut, 0, &u8toi8(profile_key)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsEncryptBlobDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
    randomness: jbyteArray,
    plaintext: jbyteArray,
    blobCiphertextOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let randomness = env.convert_byte_array(randomness).unwrap();
        let plaintext = env.convert_byte_array(plaintext).unwrap();
        let mut blob_ciphertext: Vec<u8> =
            vec![0; env.get_array_length(blobCiphertextOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_encryptBlobDeterministic(
            &group_secret_params,
            &randomness,
            &plaintext,
            &mut blob_ciphertext,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(blobCiphertextOut, 0, &u8toi8(blob_ciphertext)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupSecretParamsDecryptBlobJNI(
    env: JNIEnv,
    _class: JClass,
    groupSecretParams: jbyteArray,
    blobCiphertext: jbyteArray,
    plaintextOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let blob_ciphertext = env.convert_byte_array(blobCiphertext).unwrap();
        let mut plaintext: Vec<u8> = vec![0; env.get_array_length(plaintextOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupSecretParams_decryptBlob(
            &group_secret_params,
            &blob_ciphertext,
            &mut plaintext,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(plaintextOut, 0, &u8toi8(plaintext)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverSecretParamsGenerateDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    randomness: jbyteArray,
    serverSecretParamsOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let randomness = env.convert_byte_array(randomness).unwrap();
        let mut server_secret_params: Vec<u8> =
            vec![0; env.get_array_length(serverSecretParamsOut).unwrap() as usize];

        let ffi_return = simpleapi::ServerSecretParams_generateDeterministic(
            &randomness,
            &mut server_secret_params,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(serverSecretParamsOut, 0, &u8toi8(server_secret_params)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverSecretParamsCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    serverSecretParams: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_secret_params = env.convert_byte_array(serverSecretParams).unwrap();

        let ffi_return = simpleapi::ServerSecretParams_checkValidContents(&server_secret_params);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverSecretParamsGetPublicParamsJNI(
    env: JNIEnv,
    _class: JClass,
    serverSecretParams: jbyteArray,
    serverPublicParamsOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_secret_params = env.convert_byte_array(serverSecretParams).unwrap();
        let mut server_public_params: Vec<u8> =
            vec![0; env.get_array_length(serverPublicParamsOut).unwrap() as usize];

        let ffi_return = simpleapi::ServerSecretParams_getPublicParams(
            &server_secret_params,
            &mut server_public_params,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(serverPublicParamsOut, 0, &u8toi8(server_public_params)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverSecretParamsSignDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    serverSecretParams: jbyteArray,
    randomness: jbyteArray,
    message: jbyteArray,
    notarySignatureOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_secret_params = env.convert_byte_array(serverSecretParams).unwrap();
        let randomness = env.convert_byte_array(randomness).unwrap();
        let message = env.convert_byte_array(message).unwrap();
        let mut notary_signature: Vec<u8> =
            vec![0; env.get_array_length(notarySignatureOut).unwrap() as usize];

        let ffi_return = simpleapi::ServerSecretParams_signDeterministic(
            &server_secret_params,
            &randomness,
            &message,
            &mut notary_signature,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(notarySignatureOut, 0, &u8toi8(notary_signature)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverPublicParamsReceiveAuthCredentialJNI(
    env: JNIEnv,
    _class: JClass,
    serverPublicParams: jbyteArray,
    uuid: jbyteArray,
    redemptionTime: jint,
    authCredentialResponse: jbyteArray,
    authCredentialOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_public_params = env.convert_byte_array(serverPublicParams).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let redemption_time = redemptionTime as u32;
        let auth_credential_response = env.convert_byte_array(authCredentialResponse).unwrap();
        let mut auth_credential: Vec<u8> =
            vec![0; env.get_array_length(authCredentialOut).unwrap() as usize];

        let ffi_return = simpleapi::ServerPublicParams_receiveAuthCredential(
            &server_public_params,
            &uuid,
            redemption_time,
            &auth_credential_response,
            &mut auth_credential,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(authCredentialOut, 0, &u8toi8(auth_credential)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverPublicParamsCreateAuthCredentialPresentationDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    serverPublicParams: jbyteArray,
    randomness: jbyteArray,
    groupSecretParams: jbyteArray,
    authCredential: jbyteArray,
    authCredentialPresentationOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_public_params = env.convert_byte_array(serverPublicParams).unwrap();
        let randomness = env.convert_byte_array(randomness).unwrap();
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let auth_credential = env.convert_byte_array(authCredential).unwrap();
        let mut auth_credential_presentation: Vec<u8> =
            vec![0; env.get_array_length(authCredentialPresentationOut).unwrap() as usize];

        let ffi_return =
            simpleapi::ServerPublicParams_createAuthCredentialPresentationDeterministic(
                &server_public_params,
                &randomness,
                &group_secret_params,
                &auth_credential,
                &mut auth_credential_presentation,
            );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            authCredentialPresentationOut,
            0,
            &u8toi8(auth_credential_presentation)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverPublicParamsCreateProfileKeyCredentialRequestContextDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    serverPublicParams: jbyteArray,
    randomness: jbyteArray,
    uuid: jbyteArray,
    profileKey: jbyteArray,
    profileKeyCredentialRequestContextOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_public_params = env.convert_byte_array(serverPublicParams).unwrap();
        let randomness = env.convert_byte_array(randomness).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let profile_key = env.convert_byte_array(profileKey).unwrap();
        let mut profile_key_credential_request_context: Vec<u8> = vec![
            0;
            env.get_array_length(profileKeyCredentialRequestContextOut)
                .unwrap()
                as usize
        ];

        let ffi_return =
            simpleapi::ServerPublicParams_createProfileKeyCredentialRequestContextDeterministic(
                &server_public_params,
                &randomness,
                &uuid,
                &profile_key,
                &mut profile_key_credential_request_context,
            );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            profileKeyCredentialRequestContextOut,
            0,
            &u8toi8(profile_key_credential_request_context)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverPublicParamsReceiveProfileKeyCredentialJNI(
    env: JNIEnv,
    _class: JClass,
    serverPublicParams: jbyteArray,
    profileKeyCredentialRequestContext: jbyteArray,
    profileKeyCredentialResponse: jbyteArray,
    profileKeyCredentialOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_public_params = env.convert_byte_array(serverPublicParams).unwrap();
        let profile_key_credential_request_context = env
            .convert_byte_array(profileKeyCredentialRequestContext)
            .unwrap();
        let profile_key_credential_response = env
            .convert_byte_array(profileKeyCredentialResponse)
            .unwrap();
        let mut profile_key_credential: Vec<u8> =
            vec![0; env.get_array_length(profileKeyCredentialOut).unwrap() as usize];

        let ffi_return = simpleapi::ServerPublicParams_receiveProfileKeyCredential(
            &server_public_params,
            &profile_key_credential_request_context,
            &profile_key_credential_response,
            &mut profile_key_credential,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            profileKeyCredentialOut,
            0,
            &u8toi8(profile_key_credential)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverPublicParamsCreateProfileKeyCredentialPresentationDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    serverPublicParams: jbyteArray,
    randomness: jbyteArray,
    groupSecretParams: jbyteArray,
    profileKeyCredential: jbyteArray,
    profileKeyCredentialPresentationOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_public_params = env.convert_byte_array(serverPublicParams).unwrap();
        let randomness = env.convert_byte_array(randomness).unwrap();
        let group_secret_params = env.convert_byte_array(groupSecretParams).unwrap();
        let profile_key_credential = env.convert_byte_array(profileKeyCredential).unwrap();
        let mut profile_key_credential_presentation: Vec<u8> = vec![
            0;
            env.get_array_length(profileKeyCredentialPresentationOut)
                .unwrap()
                as usize
        ];

        let ffi_return =
            simpleapi::ServerPublicParams_createProfileKeyCredentialPresentationDeterministic(
                &server_public_params,
                &randomness,
                &group_secret_params,
                &profile_key_credential,
                &mut profile_key_credential_presentation,
            );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            profileKeyCredentialPresentationOut,
            0,
            &u8toi8(profile_key_credential_presentation)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverSecretParamsIssueAuthCredentialDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    serverSecretParams: jbyteArray,
    randomness: jbyteArray,
    uuid: jbyteArray,
    redemptionTime: jint,
    authCredentialResponseOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_secret_params = env.convert_byte_array(serverSecretParams).unwrap();
        let randomness = env.convert_byte_array(randomness).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let redemption_time = redemptionTime as u32;
        let mut auth_credential_response: Vec<u8> =
            vec![0; env.get_array_length(authCredentialResponseOut).unwrap() as usize];

        let ffi_return = simpleapi::ServerSecretParams_issueAuthCredentialDeterministic(
            &server_secret_params,
            &randomness,
            &uuid,
            redemption_time,
            &mut auth_credential_response,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            authCredentialResponseOut,
            0,
            &u8toi8(auth_credential_response)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverSecretParamsVerifyAuthCredentialPresentationJNI(
    env: JNIEnv,
    _class: JClass,
    serverSecretParams: jbyteArray,
    groupPublicParams: jbyteArray,
    authCredentialPresentation: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_secret_params = env.convert_byte_array(serverSecretParams).unwrap();
        let group_public_params = env.convert_byte_array(groupPublicParams).unwrap();
        let auth_credential_presentation =
            env.convert_byte_array(authCredentialPresentation).unwrap();

        let ffi_return = simpleapi::ServerSecretParams_verifyAuthCredentialPresentation(
            &server_secret_params,
            &group_public_params,
            &auth_credential_presentation,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverSecretParamsIssueProfileKeyCredentialDeterministicJNI(
    env: JNIEnv,
    _class: JClass,
    serverSecretParams: jbyteArray,
    randomness: jbyteArray,
    profileKeyCredentialRequest: jbyteArray,
    uuid: jbyteArray,
    profileKeyCommitment: jbyteArray,
    profileKeyCredentialResponseOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_secret_params = env.convert_byte_array(serverSecretParams).unwrap();
        let randomness = env.convert_byte_array(randomness).unwrap();
        let profile_key_credential_request =
            env.convert_byte_array(profileKeyCredentialRequest).unwrap();
        let uuid = env.convert_byte_array(uuid).unwrap();
        let profile_key_commitment = env.convert_byte_array(profileKeyCommitment).unwrap();
        let mut profile_key_credential_response: Vec<u8> = vec![
            0;
            env.get_array_length(profileKeyCredentialResponseOut)
                .unwrap() as usize
        ];

        let ffi_return = simpleapi::ServerSecretParams_issueProfileKeyCredentialDeterministic(
            &server_secret_params,
            &randomness,
            &profile_key_credential_request,
            &uuid,
            &profile_key_commitment,
            &mut profile_key_credential_response,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            profileKeyCredentialResponseOut,
            0,
            &u8toi8(profile_key_credential_response)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverSecretParamsVerifyProfileKeyCredentialPresentationJNI(
    env: JNIEnv,
    _class: JClass,
    serverSecretParams: jbyteArray,
    groupPublicParams: jbyteArray,
    profileKeyCredentialPresentation: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_secret_params = env.convert_byte_array(serverSecretParams).unwrap();
        let group_public_params = env.convert_byte_array(groupPublicParams).unwrap();
        let profile_key_credential_presentation = env
            .convert_byte_array(profileKeyCredentialPresentation)
            .unwrap();

        let ffi_return = simpleapi::ServerSecretParams_verifyProfileKeyCredentialPresentation(
            &server_secret_params,
            &group_public_params,
            &profile_key_credential_presentation,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupPublicParamsCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    groupPublicParams: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_public_params = env.convert_byte_array(groupPublicParams).unwrap();

        let ffi_return = simpleapi::GroupPublicParams_checkValidContents(&group_public_params);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_groupPublicParamsGetGroupIdentifierJNI(
    env: JNIEnv,
    _class: JClass,
    groupPublicParams: jbyteArray,
    groupIdentifierOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let group_public_params = env.convert_byte_array(groupPublicParams).unwrap();
        let mut group_identifier: Vec<u8> =
            vec![0; env.get_array_length(groupIdentifierOut).unwrap() as usize];

        let ffi_return = simpleapi::GroupPublicParams_getGroupIdentifier(
            &group_public_params,
            &mut group_identifier,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(groupIdentifierOut, 0, &u8toi8(group_identifier)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverPublicParamsCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    serverPublicParams: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_public_params = env.convert_byte_array(serverPublicParams).unwrap();

        let ffi_return = simpleapi::ServerPublicParams_checkValidContents(&server_public_params);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_serverPublicParamsVerifySignatureJNI(
    env: JNIEnv,
    _class: JClass,
    serverPublicParams: jbyteArray,
    message: jbyteArray,
    notarySignature: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let server_public_params = env.convert_byte_array(serverPublicParams).unwrap();
        let message = env.convert_byte_array(message).unwrap();
        let notary_signature = env.convert_byte_array(notarySignature).unwrap();

        let ffi_return = simpleapi::ServerPublicParams_verifySignature(
            &server_public_params,
            &message,
            &notary_signature,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_authCredentialResponseCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    authCredentialResponse: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let auth_credential_response = env.convert_byte_array(authCredentialResponse).unwrap();

        let ffi_return =
            simpleapi::AuthCredentialResponse_checkValidContents(&auth_credential_response);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_authCredentialCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    authCredential: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let auth_credential = env.convert_byte_array(authCredential).unwrap();

        let ffi_return = simpleapi::AuthCredential_checkValidContents(&auth_credential);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_authCredentialPresentationCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    authCredentialPresentation: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let auth_credential_presentation =
            env.convert_byte_array(authCredentialPresentation).unwrap();

        let ffi_return =
            simpleapi::AuthCredentialPresentation_checkValidContents(&auth_credential_presentation);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_authCredentialPresentationGetUuidCiphertextJNI(
    env: JNIEnv,
    _class: JClass,
    authCredentialPresentation: jbyteArray,
    uuidCiphertextOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let auth_credential_presentation =
            env.convert_byte_array(authCredentialPresentation).unwrap();
        let mut uuid_ciphertext: Vec<u8> =
            vec![0; env.get_array_length(uuidCiphertextOut).unwrap() as usize];

        let ffi_return = simpleapi::AuthCredentialPresentation_getUuidCiphertext(
            &auth_credential_presentation,
            &mut uuid_ciphertext,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(uuidCiphertextOut, 0, &u8toi8(uuid_ciphertext)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_authCredentialPresentationGetRedemptionTimeJNI(
    env: JNIEnv,
    _class: JClass,
    authCredentialPresentation: jbyteArray,
    redemptionTimeOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let auth_credential_presentation =
            env.convert_byte_array(authCredentialPresentation).unwrap();
        let mut redemption_time: Vec<u8> =
            vec![0; env.get_array_length(redemptionTimeOut).unwrap() as usize];

        let ffi_return = simpleapi::AuthCredentialPresentation_getRedemptionTime(
            &auth_credential_presentation,
            &mut redemption_time,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(redemptionTimeOut, 0, &u8toi8(redemption_time)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCredentialRequestContextCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCredentialRequestContext: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_credential_request_context = env
            .convert_byte_array(profileKeyCredentialRequestContext)
            .unwrap();

        let ffi_return = simpleapi::ProfileKeyCredentialRequestContext_checkValidContents(
            &profile_key_credential_request_context,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCredentialRequestContextGetRequestJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCredentialRequestContext: jbyteArray,
    profileKeyCredentialRequestOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_credential_request_context = env
            .convert_byte_array(profileKeyCredentialRequestContext)
            .unwrap();
        let mut profile_key_credential_request: Vec<u8> = vec![
            0;
            env.get_array_length(profileKeyCredentialRequestOut)
                .unwrap() as usize
        ];

        let ffi_return = simpleapi::ProfileKeyCredentialRequestContext_getRequest(
            &profile_key_credential_request_context,
            &mut profile_key_credential_request,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            profileKeyCredentialRequestOut,
            0,
            &u8toi8(profile_key_credential_request)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCredentialRequestCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCredentialRequest: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_credential_request =
            env.convert_byte_array(profileKeyCredentialRequest).unwrap();

        let ffi_return = simpleapi::ProfileKeyCredentialRequest_checkValidContents(
            &profile_key_credential_request,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCredentialResponseCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCredentialResponse: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_credential_response = env
            .convert_byte_array(profileKeyCredentialResponse)
            .unwrap();

        let ffi_return = simpleapi::ProfileKeyCredentialResponse_checkValidContents(
            &profile_key_credential_response,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCredentialCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCredential: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_credential = env.convert_byte_array(profileKeyCredential).unwrap();

        let ffi_return =
            simpleapi::ProfileKeyCredential_checkValidContents(&profile_key_credential);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCredentialPresentationCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCredentialPresentation: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_credential_presentation = env
            .convert_byte_array(profileKeyCredentialPresentation)
            .unwrap();

        let ffi_return = simpleapi::ProfileKeyCredentialPresentation_checkValidContents(
            &profile_key_credential_presentation,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCredentialPresentationGetUuidCiphertextJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCredentialPresentation: jbyteArray,
    uuidCiphertextOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_credential_presentation = env
            .convert_byte_array(profileKeyCredentialPresentation)
            .unwrap();
        let mut uuid_ciphertext: Vec<u8> =
            vec![0; env.get_array_length(uuidCiphertextOut).unwrap() as usize];

        let ffi_return = simpleapi::ProfileKeyCredentialPresentation_getUuidCiphertext(
            &profile_key_credential_presentation,
            &mut uuid_ciphertext,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(uuidCiphertextOut, 0, &u8toi8(uuid_ciphertext)[..])
            .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCredentialPresentationGetProfileKeyCiphertextJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCredentialPresentation: jbyteArray,
    profileKeyCiphertextOut: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_credential_presentation = env
            .convert_byte_array(profileKeyCredentialPresentation)
            .unwrap();
        let mut profile_key_ciphertext: Vec<u8> =
            vec![0; env.get_array_length(profileKeyCiphertextOut).unwrap() as usize];

        let ffi_return = simpleapi::ProfileKeyCredentialPresentation_getProfileKeyCiphertext(
            &profile_key_credential_presentation,
            &mut profile_key_ciphertext,
        );
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }

        env.set_byte_array_region(
            profileKeyCiphertextOut,
            0,
            &u8toi8(profile_key_ciphertext)[..],
        )
        .unwrap();
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_uuidCiphertextCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    uuidCiphertext: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let uuid_ciphertext = env.convert_byte_array(uuidCiphertext).unwrap();

        let ffi_return = simpleapi::UuidCiphertext_checkValidContents(&uuid_ciphertext);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_profileKeyCiphertextCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    profileKeyCiphertext: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let profile_key_ciphertext = env.convert_byte_array(profileKeyCiphertext).unwrap();

        let ffi_return =
            simpleapi::ProfileKeyCiphertext_checkValidContents(&profile_key_ciphertext);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_randomnessCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    randomness: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let randomness = env.convert_byte_array(randomness).unwrap();

        let ffi_return = simpleapi::Randomness_checkValidContents(&randomness);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}

#[no_mangle]
pub extern "system" fn Java_org_signal_zkgroup_internal_Native_uuidCheckValidContentsJNI(
    env: JNIEnv,
    _class: JClass,
    uuid: jbyteArray,
) -> i32 {
    let result = panic::catch_unwind(|| {
        let uuid = env.convert_byte_array(uuid).unwrap();

        let ffi_return = simpleapi::Uuid_checkValidContents(&uuid);
        if ffi_return != FFI_RETURN_OK {
            return ffi_return;
        }
        FFI_RETURN_OK
    });

    match result {
        Ok(result) => result,
        Err(_) => FFI_RETURN_INTERNAL_ERROR,
    }
}
