Skip to content

Commit

Permalink
Update kotlin to 1.9.0 (#84)
Browse files Browse the repository at this point in the history
* Update kotlin to 1.9.0

* Update Agp to 8.1.0

* Update benchmark to 0.4.9

* Downgrade jmh to 1.23

* fix
  • Loading branch information
robxyy authored Aug 12, 2023
1 parent 8eee61c commit 15df594
Show file tree
Hide file tree
Showing 26 changed files with 344 additions and 843 deletions.
2 changes: 1 addition & 1 deletion aead/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

kotlin {
android {
androidTarget {
publishLibraryVariants("release")
}
jvm()
Expand Down
7 changes: 5 additions & 2 deletions aead/src/darwinMain/kotlin/diglol/crypto/AesGcm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import diglol.crypto.internal.plusByteArrays
import diglol.crypto.internal.toByteArray
import diglol.crypto.internal.toNSData
import diglol.crypto.random.nextBytes
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.cinterop.UnsafeNumber
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.alloc
import kotlinx.cinterop.convert
Expand All @@ -27,7 +30,7 @@ actual class AesGcm actual constructor(
checkIv()
}

@Suppress("OPT_IN_USAGE")
@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class, BetaInteropApi::class)
actual override suspend fun encrypt(
plaintext: ByteArray,
associatedData: ByteArray
Expand All @@ -53,7 +56,7 @@ actual class AesGcm actual constructor(
}
}

@Suppress("OPT_IN_USAGE")
@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class, BetaInteropApi::class)
actual override suspend fun decrypt(
ciphertext: ByteArray,
associatedData: ByteArray
Expand Down
23 changes: 10 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.dokka.gradle.AbstractDokkaTask
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
Expand Down Expand Up @@ -46,7 +47,7 @@ allprojects {
}

subprojects {
fun CommonExtension<*, *, *, *>.applyAndroid() {
fun CommonExtension<*, *, *, *, *>.applyAndroid() {
lint {
textReport = true
textOutput = file("stdout")
Expand Down Expand Up @@ -154,18 +155,14 @@ allprojects {
}
}

// Workaround for https://github.com/Kotlin/dokka/issues/2977.
// We disable the C Interop IDE metadata task when generating documentation using Dokka.
gradle.taskGraph.whenReady {
val hasDokkaTasks = gradle.taskGraph.allTasks.any {
it is org.jetbrains.dokka.gradle.AbstractDokkaTask
}
if (hasDokkaTasks) {
@Suppress("UNCHECKED_CAST")
tasks.withType(Class.forName("org.jetbrains.kotlin.gradle.targets.native.internal.CInteropMetadataDependencyTransformationTask") as Class<DefaultTask>)
.configureEach {
enabled = false
}
// Workaround for https://github.com/Kotlin/dokka/issues/2977.
// We disable the C Interop IDE metadata task when generating documentation using Dokka.
tasks.withType<AbstractDokkaTask> {
@Suppress("UNCHECKED_CAST")
val taskClass =
Class.forName("org.jetbrains.kotlin.gradle.targets.native.internal.CInteropMetadataDependencyTransformationTask") as Class<Task>
parent?.subprojects?.forEach {
dependsOn(it.tasks.withType(taskClass))
}
}

Expand Down
2 changes: 1 addition & 1 deletion cipher/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

kotlin {
android {
androidTarget {
publishLibraryVariants("release")
}
jvm()
Expand Down
4 changes: 3 additions & 1 deletion cipher/src/darwinMain/kotlin/diglol/crypto/AesCbc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package diglol.crypto
import diglol.crypto.internal.refToOrElse
import diglol.crypto.internal.selfOrCopyOf
import diglol.crypto.random.nextBytes
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.UnsafeNumber
import kotlinx.cinterop.cValue
import kotlinx.cinterop.convert
import kotlinx.cinterop.memScoped
Expand Down Expand Up @@ -42,7 +44,7 @@ actual class AesCbc actual constructor(
return doFinal(kCCDecrypt, key, iv, rawCiphertext)
}

@Suppress("OPT_IN_USAGE")
@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
private fun doFinal(
op: CCOperation,
key: ByteArray,
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

kotlin {
android {
androidTarget {
publishLibraryVariants("release")
}
jvm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package diglol.crypto.internal
import kotlinx.cinterop.ByteVar
import kotlinx.cinterop.COpaquePointer
import kotlinx.cinterop.CValuesRef
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.UnsafeNumber
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.convert
import kotlinx.cinterop.refTo
Expand All @@ -11,11 +13,11 @@ import platform.Foundation.NSData
import platform.Foundation.dataWithBytesNoCopy
import platform.posix.memcpy

@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
fun COpaquePointer?.toByteArray(size: Int): ByteArray {
return if (this != null && size != 0) {
ByteArray(size).apply {
usePinned {
@Suppress("OPT_IN_USAGE")
memcpy(it.addressOf(0), this@toByteArray, size.convert())
}
}
Expand All @@ -24,22 +26,23 @@ fun COpaquePointer?.toByteArray(size: Int): ByteArray {
}
}

@Suppress("OPT_IN_USAGE")
@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
fun NSData.toByteArray(): ByteArray = bytes.toByteArray(length.convert())

@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
fun ByteArray.toNSData(freeWhenDone: Boolean = false): NSData = usePinned {
val bytesPointer = when {
isNotEmpty() -> it.addressOf(0)
else -> null
}
@Suppress("OPT_IN_USAGE")
NSData.dataWithBytesNoCopy(
bytes = bytesPointer,
length = size.convert(),
freeWhenDone = freeWhenDone
)
}

@OptIn(ExperimentalForeignApi::class)
fun ByteArray.refToOrElse(
index: Int,
default: CValuesRef<ByteVar>? = null
Expand Down
2 changes: 1 addition & 1 deletion crypto/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

kotlin {
android {
androidTarget {
publishLibraryVariants("release")
}
jvm()
Expand Down
4 changes: 0 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
org.gradle.parallel=true

# Kotlin
kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.mpp.androidGradlePluginCompatibility.nowarn=true
kotlin.native.ignoreIncorrectDependencies=true

# Android
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.8.22"
benchmark = "0.4.8"
kotlin = "1.9.0"
benchmark = "0.4.9"
kotlinx-coroutines = "1.7.2"

[libraries]
Expand All @@ -11,8 +11,8 @@ dokka-gradle-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", vers
mavenPublish-gradle-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.25.3" }
benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "benchmark" }
benchmark-gradle-plugin = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-plugin", version.ref = "benchmark" }
jmh-core = { module = "org.openjdk.jmh:jmh-core", version = "1.37" }
android-gradle-plugin = { module = "com.android.tools.build:gradle", version = "8.0.2" }
jmh-core = { module = "org.openjdk.jmh:jmh-core", version = "1.23" }
android-gradle-plugin = { module = "com.android.tools.build:gradle", version = "8.1.0" }
cklib-gradle-plugin = { module = "co.touchlab:cklib-gradle-plugin", version = "0.2.4" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
Expand Down
2 changes: 1 addition & 1 deletion hash/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

kotlin {
android {
androidTarget {
publishLibraryVariants("release")
}
jvm()
Expand Down
4 changes: 3 additions & 1 deletion hash/src/darwinMain/kotlin/diglol/crypto/Hash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package diglol.crypto
import diglol.crypto.internal.refToOrElse
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.CValuesRef
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.UByteVar
import kotlinx.cinterop.convert
import kotlinx.cinterop.refTo
Expand All @@ -26,6 +27,8 @@ actual class Hash actual constructor(
SHA512
}

@Suppress("UNCHECKED_CAST")
@OptIn(ExperimentalForeignApi::class)
actual suspend fun hash(data: ByteArray): ByteArray {
val shaFun: (data: CValuesRef<*>?, len: CC_LONG, md: CValuesRef<UByteVar>?) -> CPointer<UByteVar>?
val shaLen: Int
Expand All @@ -51,7 +54,6 @@ actual class Hash actual constructor(
}
}
val result = ByteArray(shaLen)
@Suppress("UNCHECKED_CAST")
shaFun(data.refToOrElse(0), data.size.convert(), result.refTo(0) as CValuesRef<UByteVar>)
return result
}
Expand Down
2 changes: 1 addition & 1 deletion kdf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

kotlin {
android {
androidTarget {
publishLibraryVariants("release")
}
jvm()
Expand Down
4 changes: 3 additions & 1 deletion kdf/src/darwinMain/kotlin/diglol/crypto/Argon2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import diglol.crypto.internal.Argon2_version
import diglol.crypto.internal.argon2_context
import diglol.crypto.internal.argon2_ctx
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.cValue
import kotlinx.cinterop.convert
Expand Down Expand Up @@ -56,11 +57,12 @@ actual class Argon2 actual constructor(
checkParams()
}

@Suppress("UNCHECKED_CAST")
@OptIn(ExperimentalForeignApi::class)
actual override suspend fun deriveKey(password: ByteArray, salt: ByteArray): ByteArray {
checkArgon2Salt(salt)
val result = ByteArray(hashSize)

@Suppress("UNCHECKED_CAST")
val context = cValue<argon2_context> {
out = result.usePinned { it.addressOf(0) } as CPointer<uint8_tVar>
outlen = hashSize.convert()
Expand Down
5 changes: 4 additions & 1 deletion kdf/src/darwinMain/kotlin/diglol/crypto/Pbkdf2.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package diglol.crypto

import kotlinx.cinterop.CValuesRef
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.UnsafeNumber
import kotlinx.cinterop.convert
import kotlinx.cinterop.refTo
import platform.CoreCrypto.CCKeyDerivationPBKDF
Expand All @@ -21,6 +23,8 @@ actual class Pbkdf2 actual constructor(
checkParams()
}

@Suppress("UNCHECKED_CAST")
@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
actual override suspend fun deriveKey(password: ByteArray, salt: ByteArray): ByteArray {
checkPbkdf2Salt(salt)
val passwordString = password.decodeToString()
Expand All @@ -31,7 +35,6 @@ actual class Pbkdf2 actual constructor(
Hmac.Type.SHA512 -> kCCPRFHmacAlgSHA512
}
val result = ByteArray(keySize)
@Suppress("UNCHECKED_CAST", "OPT_IN_USAGE")
CCKeyDerivationPBKDF(
kCCPBKDF2,
passwordString,
Expand Down
Loading

0 comments on commit 15df594

Please sign in to comment.