Merge pull request #38 from ionspin/kotlin-1.9.0

Kotlin 1.9.10
This commit is contained in:
Ugljesa Jovanovic 2023-09-23 14:38:33 +02:00 committed by GitHub
commit 4a96c32418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 1214 additions and 2861 deletions

View File

@ -1,10 +1,27 @@
## Descriptive changelog
(All dates are DD.MM.YYYY)
#### 0.8.9-SNAPSHOT - Current development snapshot
#### 0.9.1-SNAPSHO - current development snapshot
#### 0.9.0-SNAPSHOT - 23.9.2023
- Breaking changes:
- PasswordHash.str now returns String
- PasswordHash.strNeedsRehash and PasswordHash.strVerify now take String type for `passwordHash` parameter
- Update to latest stable build of libsodium
- Update to kotlin 1.9.10
- Targets deprecated by kotlin 1.9.10 and therefore removed from this library:
- iosArm32
- watchosX86
- wasm32
- mingwX86
- linuxArm32Hfp
#### 0.8.9-SNAPSHOT - 26.3.2023
- Update to latest stable build of libsodium
- Update to kotlin 1.8.10
#### 0.8.8 - 9.10.2022
- Fix for missing mingw target in published library modules.xml (#29)

View File

@ -17,6 +17,12 @@
buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10")
classpath("com.android.tools.build:gradle:7.2.2")
classpath ("org.jetbrains.dokka:dokka-gradle-plugin:1.8.20")
}
repositories {
mavenCentral()
google()

View File

@ -28,9 +28,9 @@ repositories {
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10")
implementation("com.android.tools.build:gradle:7.2.2")
implementation ("org.jetbrains.dokka:dokka-gradle-plugin:1.8.10")
implementation ("org.jetbrains.dokka:dokka-gradle-plugin:1.8.20")
}
System.setProperty("PROJECT_PATH", project.projectDir.parentFile.toString())

View File

@ -15,16 +15,14 @@
*/
object Versions {
val kotlinCoroutines = "1.7.0-Beta"
val kotlin = "1.8.10"
val kotlinSerialization = "1.5.0"
val kotlinCoroutines = "1.7.3"
val kotlin = "1.9.10"
val kotlinSerialization = "1.6.0"
val kotlinSerializationPlugin = kotlin
val nodePlugin = "1.3.0"
val dokkaPlugin = kotlin
val taskTreePlugin = "1.5"
val kotlinBigNumVersion = "0.3.7"
val jna = "5.13.0"
val kotlinPoet = "1.6.0"
val sampleLibsodiumBindings = "0.8.8-SNAPSHOT"
val ktor = "1.3.2"
val timber = "4.7.1"
@ -61,27 +59,14 @@ object Deps {
object Js {
object JsVersions {
val react = "17.0.2-pre.218-kotlin-1.5.21"
val reactNpm = "17.0.2"
val styled = "5.3.0-pre.218-kotlin-1.5.21"
val styledNpm = "5.3.0"
}
val stdLib = "stdlib-js"
val test = "test-js"
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Versions.kotlinCoroutines}"
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Versions.kotlinSerialization}"
val ktorClient = "io.ktor:ktor-client-js:${Versions.ktor}"
val ktorClientSerialization = "io.ktor:ktor-client-serialization-js:${Versions.ktor}"
val ktorClientWebSockets = "io.ktor:ktor-client-websockets-js:${Versions.ktor}"
object Npm {
val libsodium = Pair("libsodium-wrappers-sumo", "0.7.9")
//val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "file:${getProjectPath()}/multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz")
val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.9")
val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.13")
}
@ -92,13 +77,10 @@ object Deps {
val test = "test"
val testJUnit = "test-junit"
val reflection = "reflect"
val coroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}"
val coroutinesjdk8 = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:${Versions.kotlinCoroutines}"
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Versions.kotlinSerialization}"
val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.kotlinCoroutines}"
val kotlinPoet = "com.squareup:kotlinpoet:${Versions.kotlinPoet}"
val resourceLoader = "com.goterl:resource-loader:${Versions.resourceLoader}"
object Delegated {
@ -119,9 +101,7 @@ object Deps {
object Android {
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.kotlinCoroutines}"
val ktorClientOkHttp = "io.ktor:ktor-client-okhttp:${Versions.ktor}"
val ktorClient = "io.ktor:ktor-client-android:${Versions.ktor}"
val ktorClientSerialization = "io.ktor:ktor-client-serialization-jvm:${Versions.ktor}"
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Versions.kotlinSerialization}"
val timber = "com.jakewharton.timber:timber:${Versions.timber}"
val jna = "net.java.dev.jna:jna:${Versions.jna}@aar"
@ -135,7 +115,6 @@ object Deps {
object AndroidPluginConfiguration {
val sdkVersion = 31
val targetVersion = 31
val minVersion = 24
}

File diff suppressed because it is too large Load Diff

View File

@ -17,9 +17,7 @@
@file:Suppress("UnstableApiUsage")
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
import org.jetbrains.dokka.Platform
plugins {
kotlin(PluginsDeps.multiplatform)
@ -74,20 +72,12 @@ kotlin {
}
}
linuxArm32Hfp() {
binaries {
staticLib {
}
}
}
}
runningOnMacos {
iosX64()
iosArm64()
iosArm32()
iosSimulatorArm64()
macosX64()
@ -99,13 +89,11 @@ kotlin {
watchosArm64()
watchosArm32()
watchosX86()
watchosSimulatorArm64()
}
runningOnWindows {
mingwX64()
mingwX86()
}
@ -163,10 +151,6 @@ kotlin {
dependsOn(commonMain)
}
val watchosX86Main by getting {
dependsOn(commonMain)
}
val watchosArm64Main by getting {
dependsOn(commonMain)
}

View File

@ -56,10 +56,10 @@ version = ReleaseInfo.bindingsVersion
val ideaActive = isInIdea()
println("Idea active: $ideaActive")
android {
compileSdkVersion(AndroidPluginConfiguration.sdkVersion)
compileSdk = AndroidPluginConfiguration.sdkVersion
defaultConfig {
minSdkVersion(AndroidPluginConfiguration.minVersion)
targetSdkVersion(AndroidPluginConfiguration.sdkVersion)
minSdk = AndroidPluginConfiguration.minVersion
targetSdk = AndroidPluginConfiguration.sdkVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
@ -73,13 +73,17 @@ android {
sourceSets.getByName("main") {
// jniLibs.srcDir("src/androidMain/libs")
}
lint {
abortOnError = false
}
}
kotlin {
val hostOsName = getHostOsName()
android() {
androidTarget() {
publishLibraryVariants("release", "debug")
}
@ -89,7 +93,7 @@ kotlin {
println("Configuring Linux X86-64 targets")
js(IR) {
js {
browser {
testTask {
useKarma {
@ -129,15 +133,6 @@ kotlin {
}
}
}
// Linux 32 is using target-sysroot-2-raspberrypi which is missing getrandom and explicit_bzero in stdlib
// so konanc can't build klib because getrandom missing will cause sodium_misuse()
// ld.lld: error: undefined symbol: explicit_bzero
// >>> referenced by utils.c
// >>> libsodium_la-utils.o:(sodium_memzero) in archive /tmp/included11051337748775083797/libsodium.a
//
// ld.lld: error: undefined symbol: getrandom
// >>> referenced by randombytes_sysrandom.c
// >>> libsodium_la-randombytes_sysrandom.o:(_randombytes_linux_getrandom) in archive /tmp/included11051337748775083797/libsodium.a
}
}
@ -167,13 +162,7 @@ kotlin {
}
}
}
iosArm32() {
binaries {
framework {
optimized = true
}
}
}
iosSimulatorArm64() {
binaries {
framework {
@ -233,13 +222,7 @@ kotlin {
}
}
}
watchosX86() {
binaries {
framework {
optimized = true
}
}
}
watchosSimulatorArm64() {
binaries {
framework {
@ -347,16 +330,13 @@ kotlin {
""
}
)
val linux32Bit = setOf(
"" // "linuxArm32Hfp"
)
//iosArm32, iosArm64, iosX64, macosX64, metadata, tvosArm64, tvosX64, watchosArm32, watchosArm64, watchosX86
//iosArm64, iosX64, macosX64, metadata, tvosArm64, tvosX64, watchosArm32, watchosArm64
val macos64Bit = setOf(
"macosX64", "macosArm64"
)
val iosArm = setOf(
"iosArm64", "iosArm32"
"iosArm64",
)
val iosSimulator = setOf(
"iosX64", "iosSimulatorArm64"
@ -373,10 +353,10 @@ kotlin {
)
val watchosArm = setOf(
"watchosArm32", "watchosArm64"
"watchosArm64", "watchosArm32"
)
val watchosSimulator = setOf(
"watchosX86", "watchosSimulatorArm64"
"watchosSimulatorArm64"
)
targets.withType<KotlinNativeTarget> {
@ -404,14 +384,7 @@ kotlin {
)
}
}
if (linux32Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(
createWorkaroundNativeMainSourceSet(
this@withType.name,
nativeDependencies
)
)
}
if (macos64Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(
createWorkaroundNativeMainSourceSet(
@ -557,7 +530,7 @@ kotlin {
}
}
val androidTest by getting {
val androidUnitTest by getting {
dependencies {
}
}
@ -636,10 +609,6 @@ kotlin {
dependsOn(commonMain)
}
val watchosX86Main by getting {
dependsOn(commonMain)
}
val watchosArm64Main by getting {
dependsOn(commonMain)
}
@ -672,6 +641,7 @@ kotlin {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.optIn("kotlin.ExperimentalUnsignedTypes")
languageSettings.optIn("kotlin.ExperimentalStdlibApi")
languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi")
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) IonSpin UG Ugljesa Jovanovic 2021-2022
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ionspin.common.client">
</manifest>

View File

@ -55,7 +55,7 @@ expect object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray
fun str(password: String, opslimit: ULong, memlimit: Int): String
/**
* Check if a password verification string str matches the parameters opslimit and memlimit, and the current default algorithm.
@ -63,13 +63,13 @@ expect object PasswordHash {
* The function returns 0 if the parameters already match the given ones.
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
fun strNeedsRehash(passwordHash: UByteArray, opslimit: ULong, memlimit: Int): Int
fun strNeedsRehash(passwordHash: String, opslimit: ULong, memlimit: Int): Int
/**
* his function verifies that str is a valid password verification string (as generated by crypto_pwhash_str()) for passwd whose length is passwdlen.
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
fun strVerify(passwordHash: UByteArray, password: String): Boolean
fun strVerify(passwordHash: String, password: String): Boolean
}

View File

@ -6,6 +6,7 @@ import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
import kotlin.test.fail
/**
* Created by Ugljesa Jovanovic

View File

@ -44,7 +44,7 @@ class PasswordHashTest {
crypto_pwhash_OPSLIMIT_MIN,
crypto_pwhash_MEMLIMIT_MIN
)
println("Hashed password for storage: ${hashedPassword.toHexString()}")
println("Hashed password for storage: ${hashedPassword}")
assertTrue {
PasswordHash.strVerify(

View File

@ -45,7 +45,7 @@ actual object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
if (opslimit > UInt.MAX_VALUE) {
throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit")
}
@ -53,7 +53,7 @@ actual object PasswordHash {
password.encodeToUByteArray().toUInt8Array(),
opslimit.toUInt(),
memlimit.toUInt()
).encodeToUByteArray()
)
}
/**
@ -63,7 +63,7 @@ actual object PasswordHash {
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
actual fun strNeedsRehash(
passwordHash: UByteArray,
passwordHash: String,
opslimit: ULong,
memlimit: Int
): Int {
@ -72,7 +72,7 @@ actual object PasswordHash {
}
return if (
getSodium().crypto_pwhash_str_needs_rehash(
passwordHash.asByteArray().decodeToString(),
passwordHash,
opslimit.toUInt(),
memlimit.toUInt()
)
@ -88,9 +88,9 @@ actual object PasswordHash {
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
actual fun strVerify(passwordHash: String, password: String): Boolean {
return getSodium().crypto_pwhash_str_verify(
passwordHash.asByteArray().decodeToString(),
passwordHash,
password.encodeToUByteArray().toUInt8Array()
)
}

View File

@ -1108,7 +1108,7 @@ interface JnaLibsodiumInterface : Library {
// int crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES],
// unsigned long long opslimit, size_t memlimit)
fun crypto_pwhash_str_needs_rehash(
output: ByteArray,
output: String,
opslimit: Long,
memlimit: Long
) : Int
@ -1116,7 +1116,7 @@ interface JnaLibsodiumInterface : Library {
// const char * const passwd,
// unsigned long long passwdlen)
fun crypto_pwhash_str_verify(
hash: ByteArray,
hash: String,
password: String,
passwordLength: Long
) : Int

View File

@ -1,7 +1,6 @@
package com.ionspin.kotlin.crypto.pwhash
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
import com.sun.jna.NativeLong
actual object PasswordHash {
/**
@ -46,7 +45,7 @@ actual object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
val output = ByteArray(crypto_pwhash_STRBYTES)
sodiumJna.crypto_pwhash_str(
output,
@ -55,7 +54,7 @@ actual object PasswordHash {
opslimit.toLong(),
memlimit.toLong()
)
return output.asUByteArray()
return output.decodeToString()
}
/**
@ -65,12 +64,12 @@ actual object PasswordHash {
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
actual fun strNeedsRehash(
passwordHash: UByteArray,
passwordHash: String,
opslimit: ULong,
memlimit: Int
): Int {
return sodiumJna.crypto_pwhash_str_needs_rehash(
passwordHash.asByteArray(),
passwordHash,
opslimit.toLong(),
memlimit.toLong()
)
@ -81,9 +80,9 @@ actual object PasswordHash {
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
actual fun strVerify(passwordHash: String, password: String): Boolean {
val result = sodiumJna.crypto_pwhash_str_verify(
passwordHash.asByteArray(),
passwordHash,
password,
password.length.toLong()
)

View File

@ -18,6 +18,6 @@ class JnaLibraryLoaderTest {
LibsodiumInitializer.initialize()
val version = sodiumJna.sodium_version_string()
println("Got loaded sodium version: $version")
assertEquals("1.0.18", version)
assertEquals("1.0.19", version)
}
}

View File

@ -4,7 +4,6 @@ import com.ionspin.kotlin.crypto.util.toPtr
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.convert
import kotlinx.cinterop.pin
import kotlinx.cinterop.toCValues
import libsodium.crypto_pwhash
import libsodium.crypto_pwhash_str
import libsodium.crypto_pwhash_str_needs_rehash
@ -61,7 +60,7 @@ actual object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
val output = ByteArray(crypto_pwhash_STRBYTES)
val outputPinned = output.pin()
crypto_pwhash_str(
@ -73,7 +72,7 @@ actual object PasswordHash {
)
outputPinned.unpin()
return output.asUByteArray()
return output.decodeToString()
}
/**
@ -83,12 +82,12 @@ actual object PasswordHash {
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
actual fun strNeedsRehash(
passwordHash: UByteArray,
passwordHash: String,
opslimit: ULong,
memlimit: Int
): Int {
val result = crypto_pwhash_str_needs_rehash(
passwordHash.asByteArray().toCValues(),
passwordHash,
opslimit,
memlimit.convert()
)
@ -102,9 +101,9 @@ actual object PasswordHash {
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
actual fun strVerify(passwordHash: String, password: String): Boolean {
val result = crypto_pwhash_str_verify(
passwordHash.asByteArray().toCValues(),
passwordHash,
password,
password.length.convert()
)

View File

@ -24,7 +24,6 @@ import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
plugins {
kotlin(PluginsDeps.multiplatform)
id(PluginsDeps.kapt)
id(PluginsDeps.androidApplication)
id(PluginsDeps.mavenPublish)
id(PluginsDeps.signing)
@ -56,7 +55,7 @@ kotlin {
"windows" -> mingwX64("native")
}
}
android()
androidTarget()
runningOnLinuxx86_64 {
jvm()
js(IR) {
@ -208,7 +207,7 @@ kotlin {
// implementation("androidx.compose:compose-runtime:$composeDevVersion")
}
}
val androidTest by getting {
val androidUnitTest by getting {
dependencies {
implementation(kotlin(Deps.Jvm.test))
implementation(kotlin(Deps.Jvm.testJUnit))
@ -396,6 +395,11 @@ android {
}
}
lint {
abortOnError = false
}
// buildFeatures {
// // Enables Jetpack Compose for this module
// this.compose = true

View File

@ -6,8 +6,6 @@ package com.ionspin.kotlin.crypto.sample
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
import com.ionspin.kotlin.crypto.TmpAccessor
import com.ionspin.kotlin.crypto.box.Box
import com.ionspin.kotlin.crypto.box.BoxCorruptedOrTamperedDataException
import com.ionspin.kotlin.crypto.box.crypto_box_NONCEBYTES
@ -15,7 +13,6 @@ import com.ionspin.kotlin.crypto.hash.Hash
import com.ionspin.kotlin.crypto.util.decodeFromUByteArray
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString
import kotlinx.android.synthetic.main.activity_main.*
import java.lang.StringBuilder
import kotlin.random.Random
import kotlin.random.nextUBytes
@ -45,7 +42,7 @@ class MainActivity : AppCompatActivity() {
} catch (exception : Exception) {
builder.appendLine("And caught tamper")
}
helloWorldTextView.setText(builder.toString())
}
}

View File

@ -0,0 +1,7 @@
config.resolve = {
fallback: {
fs: false,
path: false,
crypto: false,
},
};

@ -1 +1 @@
Subproject commit 0c5ac65576f67c41cb72802d46d5f12394ea48d6
Subproject commit 49c37e8f604b493af51d05721e4ac69f180cf925