Skip to content

Commit

Permalink
feat: copy/modify kotlin wrapper from Kalium (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel authored Mar 27, 2023
1 parent bf63bfc commit b96507e
Show file tree
Hide file tree
Showing 16 changed files with 1,154 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/25.2.9519653
run: |
cd crypto-ffi
cargo make copy-android-resources
cargo make android
- name: Build package
uses: gradle/gradle-build-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/25.2.9519653
run: |
cd crypto-ffi
cargo make copy-android-resources
cargo make android
- name: Publish package
uses: gradle/gradle-build-action@v2
with:
Expand Down
73 changes: 1 addition & 72 deletions crypto-ffi/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ args = [
"-moduleName", "CoreCrypto",
"-pluginsClasspath",
"../target/_kotlin_docs_tmp/dokka-base-${DOKKA_VERSION}.jar;../target/_kotlin_docs_tmp/dokka-analysis-${DOKKA_VERSION}.jar;../target/_kotlin_docs_tmp/dokka-analysis-intellij-${DOKKA_VERSION}.jar;../target/_kotlin_docs_tmp/dokka-analysis-compiler-${DOKKA_VERSION}.jar;../target/_kotlin_docs_tmp/kotlinx-coroutines-core-1.6.4.jar;../target/_kotlin_docs_tmp/kotlinx-html-jvm-0.8.1.jar;../target/_kotlin_docs_tmp/freemarker-2.3.31.jar",
"-sourceSet", "-src ./bindings/kt",
"-sourceSet", "-src ./bindings/kt/main",
"-outputDir", "../target/doc/core_crypto_ffi/bindings/kotlin",
]

Expand Down Expand Up @@ -209,33 +209,6 @@ to = canonicalize "../sample-projects/android/CoreCryptoTestApp/app/src/main/jav
cp ${from} ${to}
'''

[tasks.copy-android-resources]
dependencies = ["android"]
script_runner = "@duckscript"
script = '''
handle = map
map_put ${handle} "i686-linux-android" "x86"
map_put ${handle} "x86_64-linux-android" "x86_64"
map_put ${handle} "aarch64-linux-android" "arm64-v8a"
map_put ${handle} "armv7-linux-androideabi" "armeabi-v7a"
keys = map_keys ${handle}
libname = set "libcore_crypto_ffi.so"
for rust_target in ${keys}
android_target = map_get ${handle} ${rust_target}
println -c bright_blue "cp rust-${rust_target}/${libname} -> android-jniLibs/${android_target}/${libname}"
from = canonicalize "../target/${rust_target}/release/${libname}"
to = canonicalize "../kotlin/android/src/main/jniLibs/${android_target}/${libname}"
mkdir dirname ${to}
cp ${from} ${to}
end
release ${handle}
println -c bright_blue "cp ./bindings/kt/com/wire/crypto/CoreCrypto.kt -> ../kotlin/android/src/main/java/com/wire/crypto/CoreCrypto.kt"
from = canonicalize "./bindings/kt/com/wire/crypto/CoreCrypto.kt"
to = canonicalize "../kotlin/android/src/main/kotlin/com/wire/crypto/CoreCrypto.kt"
cp ${from} ${to}
'''

#################################### JVM ####################################

[tasks.jvm-x86-darwin]
Expand All @@ -256,50 +229,6 @@ condition = { platforms = ["linux"] }
[tasks.jvm]
dependencies = ["jvm-aarch64-darwin", "jvm-x86-darwin", "jvm-x86-linux"]

[tasks.copy-jvm-resources]
dependencies = ["jvm"]
script_runner = "@duckscript"
script = '''
handle = map
platform = os_family
if eq ${platform} "mac"
map_put ${handle} "x86_64-apple-darwin" "darwin-x86-64"
map_put ${handle} "aarch64-apple-darwin" "darwin-aarch64"
end
if eq ${platform} "linux"
map_put ${handle} "x86_64-unknown-linux-gnu" "linux-x86-64"
end
lib_handle = map
if eq ${platform} "mac"
map_put ${lib_handle} "x86_64-apple-darwin" "libcore_crypto_ffi.dylib"
map_put ${lib_handle} "aarch64-apple-darwin" "libcore_crypto_ffi.dylib"
end
if eq ${platform} "linux"
map_put ${lib_handle} "x86_64-unknown-linux-gnu" "libcore_crypto_ffi.so"
end
keys = map_keys ${handle}
for rust_target in ${keys}
jvm_target = map_get ${handle} ${rust_target}
libname = map_get ${lib_handle} ${rust_target}
println -c bright_blue "cp rust-${rust_target}/${libname} -> resources/${jvm_target}/${libname}"
from = canonicalize "../target/${rust_target}/release/${libname}"
to = canonicalize "../kotlin/jvm/src/main/resources/${jvm_target}/${libname}"
mkdir dirname ${to}
cp ${from} ${to}
end
release ${handle}
println -c bright_blue "cp ./bindings/kt/com/wire/crypto/CoreCrypto.kt -> ../kotlin/jvm/src/main/kotlin/com/wire/crypto/CoreCrypto.kt"
from = canonicalize "./bindings/kt/com/wire/crypto/CoreCrypto.kt"
to = canonicalize "../kotlin/jvm/src/main/kotlin/com/wire/crypto/CoreCrypto.kt"
cp ${from} ${to}
'''

#################################### Mobile ###################################
[tasks.mobile]
dependencies = ["android", "ios"]
Expand Down
14 changes: 0 additions & 14 deletions crypto-ffi/bindings/kt/CoreCrypto.test.kt

This file was deleted.

5 changes: 0 additions & 5 deletions crypto-ffi/bindings/kt/CoreCrypto.test.kts

This file was deleted.

34 changes: 0 additions & 34 deletions crypto-ffi/bindings/kt/build.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.wire.crypto.client

import com.wire.crypto.ClientId
import com.wire.crypto.ConversationId
import com.wire.crypto.CoreCrypto
import com.wire.crypto.CoreCryptoCallbacks
import java.io.File

private class Callbacks: CoreCryptoCallbacks {

override fun authorize(
conversationId: List<UByte>,
clientId: List<UByte>): Boolean {
return true
}

override fun userAuthorize(
conversationId: ConversationId,
externalClientId: ClientId,
existingClients: List<ClientId>
): Boolean {
return true
}

override fun clientIsExistingGroupUser(
conversationId: ConversationId,
clientId: ClientId,
existingClients: List<ClientId>,
parentConversationClients: List<ClientId>?
): Boolean {
return true
}
}

@Suppress("TooManyFunctions")
class CoreCryptoCentral constructor(
private val rootDir: String,
databaseKey: String
) {
private val path: String = "$rootDir/$KEYSTORE_NAME"
private val coreCrypto: CoreCrypto
init {
File(rootDir).mkdirs()
coreCrypto = CoreCrypto.deferredInit(path, databaseKey, null)
coreCrypto.setCallbacks(Callbacks())
}

fun proteusClient(): ProteusClient {
return ProteusClientImpl(coreCrypto, rootDir)
}

fun mlsClient(clientId: String): MLSClient {
return MLSClientImpl(coreCrypto, clientId)
}

companion object {
const val KEYSTORE_NAME = "keystore"
}
}

Loading

0 comments on commit b96507e

Please sign in to comment.