Skip to content

Commit cbf42ba

Browse files
authored
Upgrade dependencies (#111)
1 parent c539f93 commit cbf42ba

File tree

84 files changed

+705
-596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+705
-596
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: Google
2+
ColumnLimit: 0

.github/workflows/android.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
e2e:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- id: yarn-cache
16-
uses: actions/cache@v3
16+
uses: actions/cache@v4
1717
with:
1818
path: |
1919
**/node_modules
@@ -22,11 +22,11 @@ jobs:
2222
restore-keys: |
2323
${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
2424
${{ runner.os }}-yarn-
25-
- uses: actions/setup-java@v3
25+
- uses: actions/setup-java@v4
2626
with:
2727
distribution: 'temurin'
2828
java-version: '17'
29-
- uses: android-actions/setup-android@v2
29+
- uses: android-actions/setup-android@v3
3030
- uses: nttld/setup-ndk@v1
3131
id: setup-ndk
3232
with:

.github/workflows/ios.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ name: iOS
22

33
on:
44
workflow_dispatch:
5-
pull_request:
6-
push:
7-
tags:
8-
- 'v*'
5+
# pull_request:
6+
# push:
7+
# tags:
8+
# - 'v*'
99

1010
jobs:
1111
e2e:
1212
runs-on: macos-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- id: yarn-cache
16-
uses: actions/cache@v3
16+
uses: actions/cache@v4
1717
with:
1818
path: |
1919
**/node_modules

.github/workflows/npm.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
13-
- uses: actions/setup-node@v3
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
1414
with:
15-
node-version: '16'
15+
node-version: '22'
1616
registry-url: https://registry.npmjs.org/
1717
- run: yarn install
1818
- run: npm publish --access public

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
with:
1414
fetch-depth: 0
1515
- uses: scottbrenner/generate-changelog-action@master

android/fast-openpgp-adapter.cpp

Lines changed: 76 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,94 @@
1-
#include <jni.h>
2-
#include "react-native-fast-openpgp.h"
31
#include <android/log.h>
2+
#include <jni.h>
43
#include <libopenpgp_bridge.h>
54

6-
extern "C"
7-
JNIEXPORT void JNICALL
8-
Java_com_fastopenpgp_FastOpenpgpModule_initialize(JNIEnv *env, jobject thiz,
9-
jlong jsi_ptr) {
10-
__android_log_print(ANDROID_LOG_VERBOSE, "react-native-fast-openpgp",
11-
"Initializing");
12-
fastOpenPGP::install(*reinterpret_cast<facebook::jsi::Runtime *>(jsi_ptr));
13-
}
14-
15-
extern "C"
16-
JNIEXPORT void JNICALL
17-
Java_com_fastopenpgp_FastOpenpgpModule_destruct(JNIEnv *env, jobject thiz) {
18-
fastOpenPGP::cleanup();
19-
}
20-
extern "C"
21-
JNIEXPORT jbyteArray JNICALL
22-
Java_com_fastopenpgp_FastOpenpgpModule_callNative(JNIEnv *env, jobject thiz,
23-
jstring name, jbyteArray payload) {
5+
#include "react-native-fast-openpgp.h"
246

25-
auto nameConstChar = env->GetStringUTFChars(name, nullptr);
26-
auto payloadBytes = env->GetByteArrayElements(payload, nullptr);
27-
auto size = env->GetArrayLength(payload);
7+
extern "C" JNIEXPORT void JNICALL
8+
Java_com_fastopenpgp_FastOpenpgpModule_initialize(JNIEnv* env,
9+
jobject /* thiz */,
10+
jlong jsContext) {
11+
if (jsContext == 0) {
12+
__android_log_print(ANDROID_LOG_ERROR, "react-native-fast-openpgp", "Failed to initialize: jsContext is null");
13+
jclass Exception = env->FindClass("java/lang/IllegalArgumentException");
14+
env->ThrowNew(Exception, "JSI context is null");
15+
return;
16+
}
2817

29-
auto nameChar = const_cast<char *>(nameConstChar);
30-
auto response = OpenPGPBridgeCall(nameChar, payloadBytes, size);
18+
__android_log_print(ANDROID_LOG_VERBOSE, "react-native-fast-openpgp", "Initializing JSI bindings");
3119

32-
env->ReleaseStringUTFChars(name, nameConstChar);
33-
env->ReleaseByteArrayElements(payload, payloadBytes, 0);
20+
try {
21+
auto* runtime = reinterpret_cast<facebook::jsi::Runtime*>(jsContext);
3422

35-
if (response->error != nullptr) {
36-
auto error = response->error;
37-
free(response);
38-
jclass Exception = env->FindClass("java/lang/Exception");
39-
env->ThrowNew(Exception, error);
40-
return nullptr;
41-
}
23+
fastOpenPGP::install(*runtime);
4224

43-
auto result = env->NewByteArray(response->size);
44-
env->SetByteArrayRegion(result, 0, response->size, (jbyte*) response->message);
45-
free(response);
46-
return result;
25+
__android_log_print(ANDROID_LOG_INFO, "react-native-fast-openpgp", "JSI bindings successfully installed");
26+
} catch (const std::exception& e) {
27+
__android_log_print(ANDROID_LOG_ERROR, "react-native-fast-openpgp", "Exception during initialization: %s", e.what());
28+
jclass Exception = env->FindClass("java/lang/RuntimeException");
29+
env->ThrowNew(Exception, e.what());
30+
} catch (...) {
31+
__android_log_print(ANDROID_LOG_ERROR, "react-native-fast-openpgp", "Unknown error during initialization");
32+
jclass Exception = env->FindClass("java/lang/RuntimeException");
33+
env->ThrowNew(Exception, "Unknown error occurred during JSI initialization");
34+
}
4735
}
36+
extern "C" JNIEXPORT void JNICALL
37+
Java_com_fastopenpgp_FastOpenpgpModule_destruct(JNIEnv* env, jobject thiz) {
38+
fastOpenPGP::cleanup();
39+
}
40+
extern "C" JNIEXPORT jbyteArray JNICALL
41+
Java_com_fastopenpgp_FastOpenpgpModule_callNative(JNIEnv* env,
42+
jobject thiz,
43+
jstring name,
44+
jbyteArray payload) {
45+
if (name == nullptr || payload == nullptr) {
46+
jclass Exception = env->FindClass("java/lang/NullPointerException");
47+
env->ThrowNew(Exception, "Input parameters 'name' or 'payload' cannot be null");
48+
return nullptr;
49+
}
4850

51+
const char* nameConstChar = env->GetStringUTFChars(name, nullptr);
52+
if (nameConstChar == nullptr) {
53+
jclass Exception = env->FindClass("java/lang/OutOfMemoryError");
54+
env->ThrowNew(Exception, "Failed to allocate memory for 'name'");
55+
return nullptr;
56+
}
4957

50-
extern "C"
51-
JNIEXPORT jbyteArray JNICALL
52-
Java_com_fastopenpgp_FastOpenpgpModule_callJSI(JNIEnv *env, jobject thiz, jlong jsi_ptr,
53-
jstring name, jbyteArray payload) {
54-
auto &runtime = *reinterpret_cast<jsi::Runtime *>(jsi_ptr);
55-
auto nameConstChar = env->GetStringUTFChars(name, nullptr);
56-
auto payloadBytes = env->GetByteArrayElements(payload, nullptr);
57-
auto size = env->GetArrayLength(payload);
58-
59-
auto nameValue = jsi::String::createFromAscii(runtime, nameConstChar);
58+
jbyte* payloadBytes = env->GetByteArrayElements(payload, nullptr);
59+
if (payloadBytes == nullptr) {
6060
env->ReleaseStringUTFChars(name, nameConstChar);
61+
jclass Exception = env->FindClass("java/lang/OutOfMemoryError");
62+
env->ThrowNew(Exception, "Failed to allocate memory for 'payload'");
63+
return nullptr;
64+
}
6165

66+
jsize size = env->GetArrayLength(payload);
67+
auto response =
68+
OpenPGPBridgeCall(const_cast<char*>(nameConstChar), payloadBytes, size);
6269

63-
auto arrayBuffer = runtime.global().getPropertyAsFunction(runtime, "ArrayBuffer");
64-
jsi::Object o = arrayBuffer.callAsConstructor(runtime, size).getObject(runtime);
65-
jsi::ArrayBuffer payloadValue = o.getArrayBuffer(runtime);
66-
memcpy(payloadValue.data(runtime), payloadBytes, size);
67-
env->ReleaseByteArrayElements(payload, payloadBytes, 0);
70+
// Release resources
71+
env->ReleaseStringUTFChars(name, nameConstChar);
72+
env->ReleaseByteArrayElements(payload, payloadBytes, JNI_ABORT);
6873

69-
auto response = fastOpenPGP::call(runtime, nameValue, payloadValue);
74+
if (response->error != nullptr) {
75+
const char* error = response->error;
76+
free(response);
77+
jclass Exception = env->FindClass("java/lang/Exception");
78+
env->ThrowNew(Exception, error);
79+
return nullptr;
80+
}
81+
82+
jbyteArray result = env->NewByteArray(response->size);
83+
if (result == nullptr) {
84+
free(response);
85+
jclass Exception = env->FindClass("java/lang/OutOfMemoryError");
86+
env->ThrowNew(Exception, "Failed to allocate memory for result");
87+
return nullptr;
88+
}
7089

71-
if (response.isString()) {
72-
auto error = response.asString(runtime);
73-
jclass Exception = env->FindClass("java/lang/Exception");
74-
env->ThrowNew(Exception, error.utf8(runtime).c_str());
75-
return nullptr;
90+
env->SetByteArrayRegion(result, 0, response->size, reinterpret_cast<jbyte*>(response->message));
91+
free(response);
7692

77-
}
78-
auto byteResult = response.asObject(runtime).getArrayBuffer(runtime);
79-
auto sizeResult = byteResult.size(runtime);
80-
auto result = env->NewByteArray(sizeResult);
81-
env->SetByteArrayRegion(result, 0, sizeResult, (jbyte*) byteResult.data(runtime));
82-
return result;
93+
return result;
8394
}

android/gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FastOpenpgp_kotlinVersion=1.7.0
22
FastOpenpgp_minSdkVersion=21
3-
FastOpenpgp_targetSdkVersion=31
4-
FastOpenpgp_compileSdkVersion=31
5-
FastOpenpgp_ndkversion=21.4.7075529
3+
FastOpenpgp_targetSdkVersion=33
4+
FastOpenpgp_compileSdkVersion=33
5+
FastOpenpgp_ndkversion=23.1.7779620

android/src/main/java/com/fastopenpgp/FastOpenpgpModule.kt

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ internal class FastOpenpgpModule(reactContext: ReactApplicationContext) :
99

1010
val TAG = "[FastOpenPGPModule]"
1111

12-
external fun initialize(jsiPtr: Long);
12+
external fun initialize(jsContext: Long)
1313
external fun destruct();
14-
external fun callJSI(jsiPtr: Long, name: String, payload: ByteArray): ByteArray;
1514
external fun callNative(name: String, payload: ByteArray): ByteArray;
1615

1716
companion object {
@@ -20,64 +19,43 @@ internal class FastOpenpgpModule(reactContext: ReactApplicationContext) :
2019
}
2120
}
2221

23-
@ReactMethod
24-
fun callJSI(name: String, payload: ReadableArray, promise: Promise) {
25-
Thread {
26-
reactApplicationContext.runOnJSQueueThread {
27-
try {
28-
val contextHolder = this.reactApplicationContext.javaScriptContextHolder!!.get()
29-
if (contextHolder.toInt() == 0) {
30-
call(name, payload, promise)
31-
return@runOnJSQueueThread
32-
}
33-
val bytes = ByteArray(payload.size()) { pos -> payload.getInt(pos).toByte() }
34-
val result = callJSI(contextHolder, name, bytes)
35-
val resultList = Arguments.createArray()
36-
for (i in result.indices) {
37-
resultList.pushInt(result[i].toInt())
38-
}
39-
promise.resolve(resultList)
40-
} catch (e: Exception) {
41-
promise.reject(e)
42-
}
43-
}
44-
}.start()
45-
}
46-
4722
@ReactMethod
4823
fun call(name: String, payload: ReadableArray, promise: Promise) {
4924
Thread {
5025
try {
51-
val bytes = ByteArray(payload.size()) { pos -> payload.getInt(pos).toByte() }
26+
val bytes = ByteArray(payload.size()) { index ->
27+
payload.getInt(index).toByte()
28+
}
5229
val result = callNative(name, bytes)
53-
val resultList = Arguments.createArray()
54-
for (i in result.indices) {
55-
resultList.pushInt(result[i].toInt())
30+
val resultList = Arguments.createArray().apply {
31+
result.forEach { pushInt(it.toInt()) }
5632
}
33+
5734
promise.resolve(resultList)
5835
} catch (e: Exception) {
59-
promise.reject(e)
36+
promise.reject("CALL_ERROR", "An error occurred during native call", e)
6037
}
6138
}.start()
6239
}
6340

6441
@ReactMethod(isBlockingSynchronousMethod = true)
6542
fun install(): Boolean {
66-
Log.d(TAG, "installing")
67-
try {
68-
val contextHolder = this.reactApplicationContext.javaScriptContextHolder!!.get()
69-
if (contextHolder.toInt() == 0) {
70-
Log.d(TAG, "context not available")
71-
return false
72-
}
73-
initialize(contextHolder)
74-
Log.i(TAG, "successfully installed")
75-
return true
76-
} catch (exception: java.lang.Exception) {
77-
Log.e(TAG, "failed to install JSI", exception)
78-
return false
43+
Log.d(TAG, "Attempting to install JSI bindings...")
44+
return try {
45+
val contextHolder = reactApplicationContext.javaScriptContextHolder?.get()
46+
if (contextHolder == null || contextHolder.toInt() == 0) {
47+
Log.w(TAG, "JSI context is not available")
48+
false
49+
} else {
50+
initialize(contextHolder)
51+
Log.i(TAG, "JSI bindings successfully installed")
52+
true
53+
}
54+
} catch (e: Exception) {
55+
Log.e(TAG, "Failed to install JSI bindings", e)
56+
false
7957
}
80-
}
58+
}
8159

8260
override fun getName(): String {
8361
return "FastOpenpgp"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

cpp/libopenpgp_bridge.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <stdint.h>
22
#include <stdlib.h>
3-
typedef struct { void* message; int size; char* error; } BytesReturn;
3+
typedef struct {
4+
void* message;
5+
int size;
6+
char* error;
7+
} BytesReturn;
48

59
#ifdef __cplusplus
610
extern "C" {

0 commit comments

Comments
 (0)