Skip to content

Commit

Permalink
chore: using xcframework for ios
Browse files Browse the repository at this point in the history
  • Loading branch information
jerson committed May 23, 2024
1 parent 02d5b0d commit 17dc8e8
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 15 deletions.
Binary file modified android/src/main/jniLibs/arm64-v8a/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/armeabi-v7a/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86_64/libopenpgp_bridge.so
Binary file not shown.
48 changes: 48 additions & 0 deletions ios/Openpgp.xcframework/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>libopenpgp_bridge.a</string>
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>libopenpgp_bridge.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>libopenpgp_bridge.a</string>
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>libopenpgp_bridge.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
87 changes: 87 additions & 0 deletions ios/Openpgp.xcframework/ios-arm64/Headers/libopenpgp_bridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package command-line-arguments */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h>

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments. */


#line 3 "main.go"
#include <stdint.h>
#include <stdlib.h>
typedef struct { void* message; int size; char* error; } BytesReturn;

#line 1 "cgo-generated-wrapper"


/* End of preamble from import "C" comments. */


/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef size_t GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
#ifdef _MSC_VER
#include <complex.h>
typedef _Fcomplex GoComplex64;
typedef _Dcomplex GoComplex128;
#else
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif

/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue. */

#ifdef __cplusplus
extern "C" {
#endif

extern BytesReturn* OpenPGPBridgeCall(char* name, void* payload, int payloadSize);

#ifdef __cplusplus
}
#endif
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package command-line-arguments */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h>

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments. */


#line 3 "main.go"
#include <stdint.h>
#include <stdlib.h>
typedef struct { void* message; int size; char* error; } BytesReturn;

#line 1 "cgo-generated-wrapper"


/* End of preamble from import "C" comments. */


/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef size_t GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
#ifdef _MSC_VER
#include <complex.h>
typedef _Fcomplex GoComplex64;
typedef _Dcomplex GoComplex128;
#else
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif

/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue. */

#ifdef __cplusplus
extern "C" {
#endif

extern BytesReturn* OpenPGPBridgeCall(char* name, void* payload, int payloadSize);

#ifdef __cplusplus
}
#endif
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-fast-openpgp",
"version": "2.7.2",
"version": "2.7.3",
"description": "library for use openPGP",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
7 changes: 2 additions & 5 deletions react-native-fast-openpgp.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
shared_lib = File.join(__dir__, "ios/libopenpgp_bridge.a").gsub(/ /, '\ ')

Pod::Spec.new do |s|
s.name = package["name"]
Expand All @@ -16,10 +15,8 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/jerson/react-native-fast-openpgp.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}"
s.vendored_libraries = '*.a'
s.xcconfig = { 'OTHER_LDFLAGS' => "-force_load '#{shared_lib}'"}
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.vendored_framework = 'ios/Openpgp.xcframework'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
Expand Down
7 changes: 3 additions & 4 deletions scripts/upgrade_bridge_libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

REPO="jerson/openpgp-mobile"
NAME="libopenpgp_bridge"
PLATFORMS=("android" "ios" )
PLATFORMS=("android" "ios_xcframework" )
OUTPUT_DIRS=("android/src/main" "ios")
OUTPUT_SUB_DIRS=("" "")
OUTPUT_STRIP_DIRS=(1 1)
Expand Down Expand Up @@ -42,12 +42,12 @@ do
OUTPUT_STRIP_DIR=${OUTPUT_STRIP_DIRS[$INDEX]}

FILE_NAME="${NAME}_${PLATFORM}_${VERSION}.tar.gz"
TMP_FILE="$TMP_DIR/$FILE_NAME"
TMP_FILE="$TMP_DIR/$FILE_NAME"
FILE_URL="https://github.com/${REPO}/releases/download/${VERSION}/${FILE_NAME}"

echo "Platform: $PLATFORM"
echo "Downloading: $FILE_URL to $TMP_FILE"
curl -L -o $TMP_FILE "$FILE_URL"
curl -L -o $TMP_FILE "$FILE_URL"

echo "Extracting: $TMP_FILE to $OUTPUT_DIR"
mkdir -p $OUTPUT_DIR
Expand All @@ -60,4 +60,3 @@ do
done
#
echo "All updated"
rm ios/libopenpgp_bridge.h || echo "."
12 changes: 10 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export default class OpenPGP {
message: string,
privateKey: string,
passphrase: string,
options?: KeyOptions
options?: KeyOptions,
signedEntity?: Entity,
): Promise<string> {
const builder = new flatbuffers.Builder(0);

Expand All @@ -223,9 +224,12 @@ export default class OpenPGP {
const privateKeyOffset = builder.createString(privateKey);

const optionsOffset = this._keyOptions(builder, options);
const signedEntityOffset = this._entity(builder, signedEntity);
DecryptRequest.startDecryptRequest(builder);
typeof optionsOffset !== 'undefined' &&
DecryptRequest.addOptions(builder, optionsOffset);
typeof signedEntityOffset !== 'undefined' &&
DecryptRequest.addSigned(builder, signedEntityOffset);
DecryptRequest.addMessage(builder, messageOffset);
DecryptRequest.addPassphrase(builder, passphraseOffset);
DecryptRequest.addPrivateKey(builder, privateKeyOffset);
Expand All @@ -241,7 +245,8 @@ export default class OpenPGP {
outputFile: string,
privateKey: string,
passphrase: string,
options?: KeyOptions
options?: KeyOptions,
signedEntity?: Entity,
): Promise<number> {
const builder = new flatbuffers.Builder(0);

Expand All @@ -251,9 +256,12 @@ export default class OpenPGP {
const privateKeyOffset = builder.createString(privateKey);

const optionsOffset = this._keyOptions(builder, options);
const signedEntityOffset = this._entity(builder, signedEntity);
DecryptFileRequest.startDecryptFileRequest(builder);
typeof optionsOffset !== 'undefined' &&
DecryptFileRequest.addOptions(builder, optionsOffset);
typeof signedEntityOffset !== 'undefined' &&
DecryptFileRequest.addSigned(builder, signedEntityOffset);
DecryptFileRequest.addInput(builder, inputOffset);
DecryptFileRequest.addOutput(builder, outputOffset);
DecryptFileRequest.addPassphrase(builder, passphraseOffset);
Expand Down
12 changes: 11 additions & 1 deletion src/model/decrypt-bytes-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as flatbuffers from 'flatbuffers';

import { Entity } from '../model/entity';
import { KeyOptions } from '../model/key-options';


Expand Down Expand Up @@ -57,8 +58,13 @@ options(obj?:KeyOptions):KeyOptions|null {
return offset ? (obj || new KeyOptions()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

signed(obj?:Entity):Entity|null {
const offset = this.bb!.__offset(this.bb_pos, 12);
return offset ? (obj || new Entity()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

static startDecryptBytesRequest(builder:flatbuffers.Builder) {
builder.startObject(4);
builder.startObject(5);
}

static addMessage(builder:flatbuffers.Builder, messageOffset:flatbuffers.Offset) {
Expand Down Expand Up @@ -89,6 +95,10 @@ static addOptions(builder:flatbuffers.Builder, optionsOffset:flatbuffers.Offset)
builder.addFieldOffset(3, optionsOffset, 0);
}

static addSigned(builder:flatbuffers.Builder, signedOffset:flatbuffers.Offset) {
builder.addFieldOffset(4, signedOffset, 0);
}

static endDecryptBytesRequest(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
Expand Down
12 changes: 11 additions & 1 deletion src/model/decrypt-file-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as flatbuffers from 'flatbuffers';

import { Entity } from '../model/entity';
import { KeyOptions } from '../model/key-options';


Expand Down Expand Up @@ -56,8 +57,13 @@ options(obj?:KeyOptions):KeyOptions|null {
return offset ? (obj || new KeyOptions()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

signed(obj?:Entity):Entity|null {
const offset = this.bb!.__offset(this.bb_pos, 14);
return offset ? (obj || new Entity()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

static startDecryptFileRequest(builder:flatbuffers.Builder) {
builder.startObject(5);
builder.startObject(6);
}

static addInput(builder:flatbuffers.Builder, inputOffset:flatbuffers.Offset) {
Expand All @@ -80,6 +86,10 @@ static addOptions(builder:flatbuffers.Builder, optionsOffset:flatbuffers.Offset)
builder.addFieldOffset(4, optionsOffset, 0);
}

static addSigned(builder:flatbuffers.Builder, signedOffset:flatbuffers.Offset) {
builder.addFieldOffset(5, signedOffset, 0);
}

static endDecryptFileRequest(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
Expand Down
Loading

0 comments on commit 17dc8e8

Please sign in to comment.