Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests rework #1

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
name: Build Android Example App
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup JDK
uses: actions/setup-java@v3
Expand All @@ -34,10 +34,10 @@ jobs:

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir) >> $GITHUB_OUTPUT"

- name: Restore node_modules from cache
uses: actions/cache@v2
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand All @@ -50,7 +50,7 @@ jobs:
run: yarn install --frozen-lockfile --cwd example

# - name: Restore Gradle cache
# uses: actions/cache@v2
# uses: actions/cache@v4
# with:
# path: |
# ~/.gradle/caches
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jobs:
run:
working-directory: example/ios
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir) >> $GITHUB_OUTPUT"
- name: Restore node_modules from cache
uses: actions/cache@v2
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand All @@ -41,18 +41,18 @@ jobs:
run: yarn install --frozen-lockfile --cwd ..

- name: Restore buildcache
uses: mikehardy/buildcache-action@v1
uses: mikehardy/buildcache-action@v2
continue-on-error: true

- name: Setup Ruby (bundle)
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 3.3
bundler-cache: true
working-directory: example/ios

- name: Restore Pods cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
example/ios/Pods
Expand All @@ -61,8 +61,11 @@ jobs:
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
- name: Install Gems
working-directory: example
run: bundle config set deployment 'true' && bundle install
- name: Install Pods
run: bundle exec pod check || bundle exec pod install
run: bundle exec pod install
- name: Install xcpretty
run: gem install xcpretty
- name: Build App
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/validate-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run:
working-directory: ./android
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup JDK
uses: actions/setup-java@v3
Expand All @@ -33,9 +33,9 @@ jobs:

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir) >> $GITHUB_OUTPUT"
- name: Restore node_modules from cache
uses: actions/cache@v2
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand All @@ -48,7 +48,7 @@ jobs:
run: yarn install --frozen-lockfile --cwd ../example

# - name: Restore Gradle cache
# uses: actions/cache@v2
# uses: actions/cache@v4
# with:
# path: |
# ~/.gradle/caches
Expand All @@ -69,7 +69,7 @@ jobs:
# name: Kotlin Lint
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/checkout@v4
# - name: Run KTLint
# uses: mrousavy/[email protected]
# with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: cpplint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: reviewdog/action-cpplint@master
with:
github_token: ${{ secrets.github_token }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/validate-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ jobs:
name: Compile JS (tsc)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install reviewdog
uses: reviewdog/action-setup@v1

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir) >> $GITHUB_OUTPUT"
- name: Restore node_modules from cache
uses: actions/cache@v2
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand Down Expand Up @@ -71,13 +71,13 @@ jobs:
name: Lint JS (eslint, prettier)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir) >> $GITHUB_OUTPUT"
- name: Restore node_modules from cache
uses: actions/cache@v2
uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand Down
8 changes: 3 additions & 5 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
project(react-native-quick-crypto)
cmake_minimum_required(VERSION 3.9.0)
cmake_minimum_required(VERSION 3.10.2)

set(PACKAGE_NAME "reactnativequickcrypto")
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
set(CMAKE_CXX_STANDARD 17)

# TODO(osp) remove before release
# set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
# set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")

# Consume shared libraries and headers from prefabs
find_package(fbjni REQUIRED CONFIG)
Expand Down
5 changes: 4 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ android {
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all -DON_ANDROID -DANDROID"
abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
arguments '-DANDROID_STL=c++_shared'
arguments (
'-DANDROID_STL=c++_shared',
"-DANDROID_TOOLCHAIN=clang"
)
}
}
}
Expand Down
26 changes: 16 additions & 10 deletions cpp/Cipher/MGLGenerateKeyPairInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,41 @@ FieldDefinition getGenerateKeyPairFieldDefinition(
runtime,
jsi::Function::createFromHostFunction(
runtime, jsi::PropNameID::forAscii(runtime, "executor"), 2,
[arguments, &jsCallInvoker, config](
[&jsCallInvoker, config](
jsi::Runtime &runtime, const jsi::Value &,
const jsi::Value *promiseArgs, size_t) -> jsi::Value {
auto resolve =
std::make_shared<jsi::Value>(runtime, promiseArgs[0]);
auto reject =
std::make_shared<jsi::Value>(runtime, promiseArgs[1]);

std::thread t([&runtime, arguments, resolve, reject,
std::thread t([&runtime, resolve, reject,
jsCallInvoker, config]() {
m.lock();
try {
auto keys = generateRSAKeyPair(runtime, config);
jsCallInvoker->invokeAsync([&runtime, &keys, jsCallInvoker,
resolve]() {
jsCallInvoker->invokeAsync([&runtime, config, resolve]() {
auto keys = generateRSAKeyPair(runtime, config);
auto publicKey = toJSI(runtime, keys.first);
auto privateKey = toJSI(runtime, keys.second);
auto res = jsi::Array::createWithElements(
runtime, jsi::Value::undefined(), publicKey,
privateKey);
runtime,
jsi::Value::undefined(),
publicKey,
privateKey);
resolve->asObject(runtime).asFunction(runtime).call(
runtime, std::move(res));
});
} catch (std::exception e) {
jsCallInvoker->invokeAsync(
[&runtime, &jsCallInvoker, reject]() {
[&runtime, reject]() {
auto res = jsi::Array::createWithElements(
runtime,
jsi::String::createFromUtf8(
runtime, "Error generating key"),
jsi::Value::undefined(),
jsi::Value::undefined());
reject->asObject(runtime).asFunction(runtime).call(
runtime, jsi::String::createFromUtf8(
runtime, "Error generating key"));
runtime, std::move(res));
});
}
m.unlock();
Expand Down
2 changes: 1 addition & 1 deletion cpp/Hash/MGLHashHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void MGLHashHostObject::installMethods() {
if (!arguments[0].isObject() ||
!arguments[0].getObject(runtime).isArrayBuffer(runtime)) {
throw jsi::JSError(runtime,
"HmacHostObject::update: First argument ('message') "
"HashHostObject::update: First argument ('message') "
"has to be of type ArrayBuffer!");
}
auto messageBuffer =
Expand Down
6 changes: 2 additions & 4 deletions cpp/Hash/MGLHashInstaller.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//
// HMAC-JSI-Installer.m
// Hash-JSI-Installer.m
// PinkPanda
//
// Created by Marc Rousavy on 31.10.21.
//

#include "MGLHashInstaller.h"

#include <openssl/hmac.h>

#include <memory>

#ifdef ANDROID
Expand All @@ -29,7 +27,7 @@ FieldDefinition getHashFieldDefinition(
// createHash(hashAlgorithm: 'sha1' | 'sha256' | 'sha512')
return HOST_LAMBDA("createHash", {
if (count != 1 && count != 2) {
throw jsi::JSError(runtime, "createHmac(..) expects 1-2 arguments!");
throw jsi::JSError(runtime, "createHash(..) expects 1-2 arguments!");
}

auto hashAlgorithm = arguments[0].asString(runtime).utf8(runtime);
Expand Down
2 changes: 1 addition & 1 deletion cpp/MGLKeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ jsi::Value KeyObjectHandle::Init(jsi::Runtime &rt) {
break;
}
default:
throw jsi::JSError(rt, "invalid keytype for init(): " + type);
throw jsi::JSError(rt, "invalid keytype for init(): " + std::to_string(type));
}

return true;
Expand Down
6 changes: 6 additions & 0 deletions cpp/MGLQuickCryptoHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ MGLQuickCryptoHostObject::MGLQuickCryptoHostObject(
return jsi::Object::createFromHostObject(runtime, hostObject);
}));

// createSign
this->fields.push_back(getSignFieldDefinition(jsCallInvoker, workerQueue));

// createVerify
this->fields.push_back(getVerifyFieldDefinition(jsCallInvoker, workerQueue));

// subtle API created from a simple jsi::Object
// because this FieldDefinition is only good for returning
// objects and too convoluted
Expand Down
2 changes: 0 additions & 2 deletions cpp/Random/MGLRandomHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ MGLRandomHostObject::MGLRandomHostObject(
}

auto result = arguments[0].asObject(runtime).getArrayBuffer(runtime);
auto resultSize = result.size(runtime);
auto *resultData = result.data(runtime);
auto resultPreventGC =
std::make_shared<jsi::ArrayBuffer>(std::move(result));
Expand Down Expand Up @@ -81,7 +80,6 @@ MGLRandomHostObject::MGLRandomHostObject(
}

auto result = arguments[0].asObject(runtime).getArrayBuffer(runtime);
auto resultSize = result.size(runtime);
auto *resultData = result.data(runtime);
auto offset = (int)arguments[1].asNumber();
auto size = arguments[2].asNumber();
Expand Down
2 changes: 1 addition & 1 deletion cpp/Utils/MGLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jsi::Value toJSI(jsi::Runtime& rt, OptionJSVariant& value) {

jsi::Value toJSI(jsi::Runtime& rt, JSVariant& value) {
if (std::holds_alternative<bool>(value)) {
return std::get<bool>(value);
return jsi::Value(std::get<bool>(value));
} else if (std::holds_alternative<int>(value)) {
return jsi::Value(std::get<int>(value));
} else if (std::holds_alternative<long long>(value)) {
Expand Down
1 change: 1 addition & 0 deletions cpp/Utils/MGLUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string>
#include <utility>
#include <vector>
#include <variant>

namespace margelo {

Expand Down
4 changes: 3 additions & 1 deletion cpp/webcrypto/MGLWebCrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#include <memory>
#include <utility>
#include "MGLKeys.h"
#include "MGLUtils.h"

#ifdef ANDROID
#include "JSIUtils/MGLJSIMacros.h"
#include "webcrypto/crypto_ec.h"
#include "Utils/MGLUtils.h"
#else
#include "MGLUtils.h"
#include "MGLJSIMacros.h"
#include "crypto_ec.h"
#endif
Expand Down
4 changes: 3 additions & 1 deletion example/.bundle/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
BUNDLE_FORCE_RUBY_PLATFORM: "1"
BUNDLE_DEPLOYMENT: "true"
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: "com.android.application"

Check warning on line 1 in example/android/app/build.gradle

View workflow job for this annotation

GitHub Actions / Gradle Lint

Unused resources: The resource `R.integer.react_native_dev_server_port` appears to be unused

Check warning on line 1 in example/android/app/build.gradle

View workflow job for this annotation

GitHub Actions / Gradle Lint

Unused resources: The resource `R.integer.react_native_inspector_proxy_port` appears to be unused
apply plugin: "com.facebook.react"

react {
Expand Down Expand Up @@ -48,7 +48,7 @@
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")

implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
Expand Down
1 change: 0 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"

Check warning on line 13 in example/android/app/src/main/AndroidManifest.xml

View workflow job for this annotation

GitHub Actions / Gradle Lint

Redundant label on activity: Redundant label can be removed
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
Expand Down
9 changes: 4 additions & 5 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

buildscript {
ext {
buildToolsVersion = "33.0.0"
buildToolsVersion = "34.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
compileSdkVersion = 34
targetSdkVersion = 34

// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "23.1.7779620"
ndkVersion = "25.1.8937393"
}
repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 50dd8e47b3ecade8a64d05a35069875c72371690

COCOAPODS: 1.14.2
COCOAPODS: 1.12.0
Loading
Loading