From 9a9b9728ef3709ca7046d08716be27a4716fdcfa Mon Sep 17 00:00:00 2001 From: Matthew Nelson Date: Mon, 20 Nov 2023 09:58:39 -0800 Subject: [PATCH] Bump dependencies to latest stable versions (#6) --- .github/workflows/CI.yml | 13 +++++------ .kotlin-js-store/yarn.lock | 21 +++++++++--------- .../main/kotlin/-KmpConfigurationExtension.kt | 4 ++-- .../src/main/kotlin/configuration.gradle.kts | 7 ++++-- .../src/main/kotlin/publication.gradle.kts | 5 +++++ build.gradle.kts | 8 +++---- gradle.properties | 4 +--- gradle/libs.versions.toml | 12 +++++----- gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/README.md | 4 ++-- sample/build.gradle.kts | 22 +++++++------------ .../kotlin/org/kotlincrypto/SecureRandom.kt | 2 ++ .../internal/SecRandomDelegate.kt | 9 ++++---- .../kotlin/org/kotlincrypto/SecureRandom.kt | 2 ++ .../kotlin/org/kotlincrypto/SecureRandom.kt | 2 ++ .../internal/-SecureRandomLinuxAndroid.kt | 6 ++--- .../org/kotlincrypto/internal/GetRandom.kt | 4 +--- .../internal/SecRandomDelegate.kt | 4 ++++ .../internal/SecRandomSynchronized.kt | 8 +++---- .../org/kotlincrypto/internal/URandom.kt | 7 +++--- .../internal/FillCompletelyUnitTest.kt | 3 +++ .../internal/SecRandomSynchronizedUnitTest.kt | 9 ++++---- .../internal/-SecureRandomMingw.kt | 6 ++--- .../internal/SecRandomDelegate.kt | 10 ++++----- .../kotlin/org/kotlincrypto/SecureRandom.kt | 4 ++++ .../internal/-SecureRandomCinterop.kt | 2 ++ .../internal/SecRandomDelegate.kt | 4 ++++ 27 files changed, 99 insertions(+), 87 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c4d3cfe..999cb5f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -11,7 +11,6 @@ jobs: fail-fast: false matrix: os: [ macos-latest, ubuntu-latest, windows-latest ] - job: [ test ] runs-on: ${{ matrix.os }} @@ -50,17 +49,17 @@ jobs: java-version: 11 - name: Run macOS Tests - if: matrix.os == 'macos-latest' && matrix.job == 'test' + if: matrix.os == 'macos-latest' run: > ./gradlew check --stacktrace - -PKMP_TARGETS="JVM,JS,IOS_ARM32,IOS_ARM64,IOS_X64,IOS_SIMULATOR_ARM64,MACOS_ARM64,MACOS_X64,TVOS_ARM64,TVOS_X64,TVOS_SIMULATOR_ARM64,WATCHOS_ARM32,WATCHOS_ARM64,WATCHOS_DEVICE_ARM64,WATCHOS_X64,WATCHOS_X86,WATCHOS_SIMULATOR_ARM64,WASM,WASM_32" + -PKMP_TARGETS="JVM,JS,IOS_ARM64,IOS_X64,IOS_SIMULATOR_ARM64,MACOS_ARM64,MACOS_X64,TVOS_ARM64,TVOS_X64,TVOS_SIMULATOR_ARM64,WATCHOS_ARM32,WATCHOS_ARM64,WATCHOS_DEVICE_ARM64,WATCHOS_X64,WATCHOS_SIMULATOR_ARM64,WASM_JS,WASM_WASI" - name: Run Linux Tests - if: matrix.os == 'ubuntu-latest' && matrix.job == 'test' + if: matrix.os == 'ubuntu-latest' run: > ./gradlew check --stacktrace - -PKMP_TARGETS="JVM,JS,ANDROID,ANDROID_ARM32,ANDROID_ARM64,ANDROID_X64,ANDROID_X86,LINUX_ARM32HFP,LINUX_ARM64,LINUX_MIPS32,LINUX_MIPSEL32,LINUX_X64,WASM,WASM_32" + -PKMP_TARGETS="JVM,JS,ANDROID,ANDROID_ARM32,ANDROID_ARM64,ANDROID_X64,ANDROID_X86,LINUX_ARM64,LINUX_X64,WASM_JS,WASM_WASI" - name: Run Windows Tests - if: matrix.os == 'windows-latest' && matrix.job == 'test' + if: matrix.os == 'windows-latest' run: > ./gradlew check --stacktrace - -PKMP_TARGETS="JVM,JS,MINGW_X64,MINGW_X86,WASM,WASM_32" + -PKMP_TARGETS="JVM,JS,MINGW_X64,WASM_JS,WASM_WASI" diff --git a/.kotlin-js-store/yarn.lock b/.kotlin-js-store/yarn.lock index ff32adc..510dcd5 100644 --- a/.kotlin-js-store/yarn.lock +++ b/.kotlin-js-store/yarn.lock @@ -2,11 +2,6 @@ # yarn lockfile v1 -"@ungap/promise-all-settled@1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" - integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q== - ansi-colors@4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" @@ -185,7 +180,7 @@ flat@^5.0.2: resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== -format-util@1.0.5: +format-util@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.5.tgz#1ffb450c8a03e7bccffe40643180918cc297d271" integrity sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg== @@ -322,12 +317,11 @@ minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" -mocha@10.0.0: - version "10.0.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.0.0.tgz#205447d8993ec755335c4b13deba3d3a13c4def9" - integrity sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA== +mocha@10.2.0: + version "10.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" + integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== dependencies: - "@ungap/promise-all-settled" "1.1.2" ansi-colors "4.1.1" browser-stdout "1.3.1" chokidar "3.5.3" @@ -492,6 +486,11 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" +typescript@5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" + integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== + workerpool@6.2.1: version "6.2.1" resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" diff --git a/build-logic/src/main/kotlin/-KmpConfigurationExtension.kt b/build-logic/src/main/kotlin/-KmpConfigurationExtension.kt index a8c139c..c41699e 100644 --- a/build-logic/src/main/kotlin/-KmpConfigurationExtension.kt +++ b/build-logic/src/main/kotlin/-KmpConfigurationExtension.kt @@ -33,8 +33,8 @@ fun KmpConfigurationExtension.configureShared( } js() -// wasm() -// wasmNativeAll() +// wasmJs {} +// wasmWasi {} androidNativeAll() diff --git a/build-logic/src/main/kotlin/configuration.gradle.kts b/build-logic/src/main/kotlin/configuration.gradle.kts index 4064a86..091fc37 100644 --- a/build-logic/src/main/kotlin/configuration.gradle.kts +++ b/build-logic/src/main/kotlin/configuration.gradle.kts @@ -17,16 +17,19 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED +import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR +import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT import org.gradle.api.tasks.testing.logging.TestLogEvent.STARTED plugins { id("io.matthewnelson.kmp.configuration") } -tasks.withType { +tasks.withType { testLogging { exceptionFormat = TestExceptionFormat.FULL - events(STARTED, PASSED, SKIPPED, FAILED) + events(STARTED, PASSED, SKIPPED, FAILED, STANDARD_ERROR, STANDARD_OUT) showStandardStreams = true + showStackTraces = true } } diff --git a/build-logic/src/main/kotlin/publication.gradle.kts b/build-logic/src/main/kotlin/publication.gradle.kts index 921cf46..4cb96ec 100644 --- a/build-logic/src/main/kotlin/publication.gradle.kts +++ b/build-logic/src/main/kotlin/publication.gradle.kts @@ -24,3 +24,8 @@ if (!version.toString().endsWith("-SNAPSHOT")) { useGpgCmd() } } + +tasks.withType().configureEach { + isPreserveFileTimestamps = false + isReproducibleFileOrder = true +} diff --git a/build.gradle.kts b/build.gradle.kts index a2bf331..f67bfce 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,6 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension -@Suppress("DSL_SCOPE_VIOLATION") plugins { alias(libs.plugins.multiplatform) apply(false) alias(libs.plugins.binaryCompat) @@ -52,7 +51,7 @@ apiValidation { } fun isNonStable(version: String): Boolean { - val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) } + val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) } val regex = "^[0-9,.v-]+(-r)?$".toRegex() val isStable = stableKeyword || regex.matches(version) return isStable.not() @@ -72,11 +71,12 @@ tasks.withType { // Example 3: using the full syntax resolutionStrategy { componentSelection { - all { + @Suppress("RedundantSamConstructor") + all(Action { if (isNonStable(candidate.version) && !isNonStable(currentVersion)) { reject("Release candidate") } - } + }) } } } diff --git a/gradle.properties b/gradle.properties index 08ed326..4e559c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,8 @@ org.gradle.parallel=true org.gradle.caching=true kotlin.code.style=official -kotlin.js.compiler=both -kotlin.mpp.enableCompatibilityMetadataVariant=true +kotlin.mpp.applyDefaultHierarchyTemplate=false kotlin.mpp.stability.nowarn=true -kotlin.native.binary.memoryModel=experimental kotlin.native.ignoreDisabledTargets=true SONATYPE_HOST=S01 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index dbfea51..ab6ec43 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,10 +1,10 @@ [versions] -binaryCompat = "0.13.0" -configuration = "0.1.1" -coroutines = "1.6.4" -gradleVersions = "0.46.0" -kotlin = "1.8.10" -publish = "0.24.0" +binaryCompat = "0.13.2" +configuration = "0.1.5" +coroutines = "1.7.3" +gradleVersions = "0.50.0" +kotlin = "1.9.20" +publish = "0.25.3" [libraries] gradle-kmp-configuration = { module = "io.matthewnelson:gradle-kmp-configuration-plugin", version.ref = "configuration" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bca0f67..a2b81f7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -4,5 +4,5 @@ zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME # https://gradle.org/release-checksums/ -distributionSha256Sum=948d1e4ccc2f6ae36cbfa087d827aaca51403acae5411e664a6000bb47946f22 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip +distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip diff --git a/sample/README.md b/sample/README.md index 59754c4..56c2b75 100644 --- a/sample/README.md +++ b/sample/README.md @@ -7,10 +7,10 @@ then print random bytes. Java: ```shell -./gradlew :sample:run -PKMP_TARGETS="JVM" +./gradlew :sample:jvmRun -PKMP_TARGETS="JVM" ``` Native: ```shell -./gradlew :sample:runDebugExecutableNativeSample -PKMP_TARGETS="LINUX_ARM64,LINUX_X64,MACOS_ARM64,MACOS_X64,MINGW_X64,MINGW_X86" +./gradlew :sample:runDebugExecutableNativeSample -PKMP_TARGETS="LINUX_ARM64,LINUX_X64,MACOS_ARM64,MACOS_X64,MINGW_X64" ``` diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index ea0a6e0..9c2f1f9 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget plugins { @@ -22,9 +23,14 @@ plugins { kmpConfiguration { configure { jvm { - pluginIds("application") + target { + withJava() - target { withJava() } + @OptIn(ExperimentalKotlinGradlePluginApi::class) + mainRun { + mainClass.set("MainKt") + } + } kotlinJvmTarget = JavaVersion.VERSION_1_8 compileSourceCompatibility = JavaVersion.VERSION_1_8 @@ -79,10 +85,8 @@ kmpConfiguration { } } os.isWindows -> { - @Suppress("DEPRECATION") when (arch) { X64 -> mingwX64(targetName) { target { setup() } } - X86 -> mingwX86(targetName) { target { setup() } } } } } @@ -94,15 +98,5 @@ kmpConfiguration { } } } - - kotlin { - sourceSets { - findByName("jvmMain")?.let { - extensions.configure("application") { - mainClass.set("MainKt") - } - } - } - } } } diff --git a/secure-random/src/commonMain/kotlin/org/kotlincrypto/SecureRandom.kt b/secure-random/src/commonMain/kotlin/org/kotlincrypto/SecureRandom.kt index 7353d3a..8c19cc3 100644 --- a/secure-random/src/commonMain/kotlin/org/kotlincrypto/SecureRandom.kt +++ b/secure-random/src/commonMain/kotlin/org/kotlincrypto/SecureRandom.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") + package org.kotlincrypto /** diff --git a/secure-random/src/darwinMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt b/secure-random/src/darwinMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt index 8cecedb..8304503 100644 --- a/secure-random/src/darwinMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt +++ b/secure-random/src/darwinMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") + package org.kotlincrypto.internal -import kotlinx.cinterop.Pinned -import kotlinx.cinterop.addressOf -import kotlinx.cinterop.UnsafeNumber -import kotlinx.cinterop.convert +import kotlinx.cinterop.* import platform.Security.SecRandomCopyBytes import platform.Security.kSecRandomDefault import org.kotlincrypto.SecRandomCopyException @@ -26,6 +25,7 @@ import org.kotlincrypto.SecRandomCopyException /** * https://developer.apple.com/documentation/security/1399291-secrandomcopybytes * */ +@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class) internal actual abstract class SecRandomDelegate private actual constructor() { @Throws(SecRandomCopyException::class) @@ -33,7 +33,6 @@ internal actual abstract class SecRandomDelegate private actual constructor() { internal actual companion object: SecRandomDelegate() { - @OptIn(UnsafeNumber::class) @Throws(SecRandomCopyException::class) actual override fun nextBytesCopyTo(bytes: Pinned, size: Int) { // kSecRandomDefault is synonymous to NULL diff --git a/secure-random/src/jsMain/kotlin/org/kotlincrypto/SecureRandom.kt b/secure-random/src/jsMain/kotlin/org/kotlincrypto/SecureRandom.kt index 6d77531..d7bdc3a 100644 --- a/secure-random/src/jsMain/kotlin/org/kotlincrypto/SecureRandom.kt +++ b/secure-random/src/jsMain/kotlin/org/kotlincrypto/SecureRandom.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT", "EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") + package org.kotlincrypto import org.kotlincrypto.internal.commonNextBytesOf diff --git a/secure-random/src/jvmAndroidMain/kotlin/org/kotlincrypto/SecureRandom.kt b/secure-random/src/jvmAndroidMain/kotlin/org/kotlincrypto/SecureRandom.kt index 3b29854..788e3f6 100644 --- a/secure-random/src/jvmAndroidMain/kotlin/org/kotlincrypto/SecureRandom.kt +++ b/secure-random/src/jvmAndroidMain/kotlin/org/kotlincrypto/SecureRandom.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING", "ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT") + package org.kotlincrypto import org.kotlincrypto.internal.commonNextBytesOf diff --git a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/-SecureRandomLinuxAndroid.kt b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/-SecureRandomLinuxAndroid.kt index f752dd3..67e2144 100644 --- a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/-SecureRandomLinuxAndroid.kt +++ b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/-SecureRandomLinuxAndroid.kt @@ -15,10 +15,7 @@ **/ package org.kotlincrypto.internal -import kotlinx.cinterop.ByteVar -import kotlinx.cinterop.CPointer -import kotlinx.cinterop.Pinned -import kotlinx.cinterop.addressOf +import kotlinx.cinterop.* import platform.posix.EINTR import platform.posix.errno @@ -29,6 +26,7 @@ import platform.posix.errno * this ensures that the call is repeated until it has been * completely filled. * */ +@OptIn(ExperimentalForeignApi::class) internal inline fun Pinned.fillCompletely( size: Int, block: (ptr: CPointer, length: Int) -> Int diff --git a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/GetRandom.kt b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/GetRandom.kt index 0cfac3e..cc248cc 100644 --- a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/GetRandom.kt +++ b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/GetRandom.kt @@ -36,6 +36,7 @@ import platform.posix.* * @see [isAvailable] * @see [getrandom] * */ +@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class) internal class GetRandom private constructor(): SecRandomSynchronized() { internal companion object { @@ -54,7 +55,6 @@ internal class GetRandom private constructor(): SecRandomSynchronized() { * */ internal fun isAvailable(): Boolean { return synchronizedRemember { buf, size -> - @OptIn(UnsafeNumber::class) val result = getrandom(buf, size.toULong().convert(), GRND_NONBLOCK) if (result < 0) { when (errno) { @@ -74,7 +74,6 @@ internal class GetRandom private constructor(): SecRandomSynchronized() { * Must always call [isAvailable] beforehand to ensure * availability on the system. * */ - @OptIn(UnsafeNumber::class) @Throws(SecRandomCopyException::class) internal fun getrandom(buf: Pinned, buflen: Int) { buf.fillCompletely(buflen) { ptr, len -> @@ -82,7 +81,6 @@ internal class GetRandom private constructor(): SecRandomSynchronized() { } } - @OptIn(UnsafeNumber::class) private fun getrandom( buf: CPointer, buflen: size_t, diff --git a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt index 7ad2743..5e286e9 100644 --- a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt +++ b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt @@ -13,11 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") + package org.kotlincrypto.internal +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.Pinned import org.kotlincrypto.SecRandomCopyException +@OptIn(ExperimentalForeignApi::class) internal actual abstract class SecRandomDelegate private actual constructor() { @Throws(SecRandomCopyException::class) diff --git a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/SecRandomSynchronized.kt b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/SecRandomSynchronized.kt index c5ae3b8..e0f3118 100644 --- a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/SecRandomSynchronized.kt +++ b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/SecRandomSynchronized.kt @@ -15,12 +15,10 @@ **/ package org.kotlincrypto.internal -import kotlinx.cinterop.ByteVar -import kotlinx.cinterop.CPointer -import kotlinx.cinterop.addressOf -import kotlinx.cinterop.usePinned -import kotlin.native.concurrent.AtomicInt +import kotlinx.cinterop.* +import kotlin.concurrent.AtomicInt +@OptIn(ExperimentalForeignApi::class) internal abstract class SecRandomSynchronized { private companion object { diff --git a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/URandom.kt b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/URandom.kt index 6aaf93a..d82fe73 100644 --- a/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/URandom.kt +++ b/secure-random/src/linuxAndroidMain/kotlin/org/kotlincrypto/internal/URandom.kt @@ -18,9 +18,9 @@ package org.kotlincrypto.internal import kotlinx.cinterop.* -import kotlin.native.concurrent.AtomicInt import org.kotlincrypto.SecRandomCopyException import platform.posix.* +import kotlin.concurrent.AtomicInt /** * Helper for: @@ -35,6 +35,7 @@ import platform.posix.* * @see [SecRandomSynchronized] * @see [readBytesTo] * */ +@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class) internal class URandom private constructor(): SecRandomSynchronized() { internal companion object { @@ -56,7 +57,6 @@ internal class URandom private constructor(): SecRandomSynchronized() { ensureSeeded() lock.withLock { - @OptIn(UnsafeNumber::class) withReadOnlyFD("/dev/urandom") { fd -> buf.fillCompletely(buflen) { ptr, length -> read(fd, ptr, length.toULong().convert()).convert() @@ -84,8 +84,7 @@ internal class URandom private constructor(): SecRandomSynchronized() { } while (true) { - @OptIn(UnsafeNumber::class) - val result = poll(pollFd.ptr, 1, INFINITE_TIMEOUT) + val result = poll(pollFd.ptr, 1u, INFINITE_TIMEOUT) if (result >= 0) { break } diff --git a/secure-random/src/linuxAndroidTest/kotlin/org/kotlincrypto/internal/FillCompletelyUnitTest.kt b/secure-random/src/linuxAndroidTest/kotlin/org/kotlincrypto/internal/FillCompletelyUnitTest.kt index 314089b..3004b9d 100644 --- a/secure-random/src/linuxAndroidTest/kotlin/org/kotlincrypto/internal/FillCompletelyUnitTest.kt +++ b/secure-random/src/linuxAndroidTest/kotlin/org/kotlincrypto/internal/FillCompletelyUnitTest.kt @@ -15,12 +15,15 @@ **/ package org.kotlincrypto.internal +import kotlinx.cinterop.ExperimentalForeignApi +import kotlinx.cinterop.UnsafeNumber import kotlinx.cinterop.set import kotlinx.cinterop.usePinned import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue +@OptIn(ExperimentalForeignApi::class) class FillCompletelyUnitTest { @Test diff --git a/secure-random/src/linuxX64Test/kotlin/org/kotlincrypto/internal/SecRandomSynchronizedUnitTest.kt b/secure-random/src/linuxX64Test/kotlin/org/kotlincrypto/internal/SecRandomSynchronizedUnitTest.kt index 72ac1dd..cb62ead 100644 --- a/secure-random/src/linuxX64Test/kotlin/org/kotlincrypto/internal/SecRandomSynchronizedUnitTest.kt +++ b/secure-random/src/linuxX64Test/kotlin/org/kotlincrypto/internal/SecRandomSynchronizedUnitTest.kt @@ -17,15 +17,16 @@ package org.kotlincrypto.internal +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.coroutines.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.test.runTest -import kotlin.native.concurrent.AtomicInt +import kotlin.concurrent.AtomicInt import kotlin.test.Test import kotlin.test.assertEquals -@OptIn(ExperimentalCoroutinesApi::class) +@OptIn(ExperimentalCoroutinesApi::class, ExperimentalForeignApi::class) class SecRandomSynchronizedUnitTest { private class TestSynchronized: SecRandomSynchronized() { @@ -45,7 +46,7 @@ class SecRandomSynchronizedUnitTest { } if (calledBefore) { - loadedCount.increment() + loadedCount.incrementAndGet() } } @@ -61,7 +62,7 @@ class SecRandomSynchronizedUnitTest { true } - invocationCount.increment() + invocationCount.incrementAndGet() } } diff --git a/secure-random/src/mingwMain/kotlin/org/kotlincrypto/internal/-SecureRandomMingw.kt b/secure-random/src/mingwMain/kotlin/org/kotlincrypto/internal/-SecureRandomMingw.kt index ce48f4d..9ca61f8 100644 --- a/secure-random/src/mingwMain/kotlin/org/kotlincrypto/internal/-SecureRandomMingw.kt +++ b/secure-random/src/mingwMain/kotlin/org/kotlincrypto/internal/-SecureRandomMingw.kt @@ -15,10 +15,7 @@ **/ package org.kotlincrypto.internal -import kotlinx.cinterop.ByteVarOf -import kotlinx.cinterop.allocArray -import kotlinx.cinterop.memScoped -import kotlinx.cinterop.toKStringFromUtf8 +import kotlinx.cinterop.* import platform.windows.DWORD import platform.windows.FORMAT_MESSAGE_FROM_SYSTEM import platform.windows.FORMAT_MESSAGE_IGNORE_INSERTS @@ -27,6 +24,7 @@ import platform.windows.SUBLANG_DEFAULT import platform.windows.FormatMessageA /* https://github.com/square/okio/blob/master/okio/src/mingwX64Main/kotlin/okio/-Windows.kt */ +@OptIn(ExperimentalForeignApi::class) internal fun errorToString(error: DWORD): String { memScoped { val messageMaxSize = 2048 diff --git a/secure-random/src/mingwMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt b/secure-random/src/mingwMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt index ebf7609..4ce6ee2 100644 --- a/secure-random/src/mingwMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt +++ b/secure-random/src/mingwMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") + package org.kotlincrypto.internal -import kotlinx.cinterop.Pinned -import kotlinx.cinterop.addressOf -import kotlinx.cinterop.convert -import kotlinx.cinterop.reinterpret +import kotlinx.cinterop.* import org.kotlincrypto.SecRandomCopyException import platform.windows.BCRYPT_USE_SYSTEM_PREFERRED_RNG import platform.windows.BCryptGenRandom @@ -28,6 +27,7 @@ import platform.windows.STATUS_INVALID_PARAMETER /** * https://learn.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom * */ +@OptIn(ExperimentalForeignApi::class) internal actual abstract class SecRandomDelegate private actual constructor() { @Throws(SecRandomCopyException::class) @@ -41,7 +41,7 @@ internal actual abstract class SecRandomDelegate private actual constructor() { null, bytes.addressOf(0).reinterpret(), size.toULong().convert(), - BCRYPT_USE_SYSTEM_PREFERRED_RNG, + BCRYPT_USE_SYSTEM_PREFERRED_RNG.convert(), ).toUInt() when (status) { diff --git a/secure-random/src/nativeMain/kotlin/org/kotlincrypto/SecureRandom.kt b/secure-random/src/nativeMain/kotlin/org/kotlincrypto/SecureRandom.kt index a918bd7..14b68f4 100644 --- a/secure-random/src/nativeMain/kotlin/org/kotlincrypto/SecureRandom.kt +++ b/secure-random/src/nativeMain/kotlin/org/kotlincrypto/SecureRandom.kt @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") + package org.kotlincrypto +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.usePinned import org.kotlincrypto.internal.commonNextBytesOf import org.kotlincrypto.internal.ifNotNullOrEmpty @@ -49,6 +52,7 @@ public actual class SecureRandom { @Throws(SecRandomCopyException::class) public actual fun nextBytesCopyTo(bytes: ByteArray?) { bytes.ifNotNullOrEmpty { + @OptIn(ExperimentalForeignApi::class) usePinned { pinned -> delegate.nextBytesCopyTo(pinned, size) } diff --git a/secure-random/src/nativeMain/kotlin/org/kotlincrypto/internal/-SecureRandomCinterop.kt b/secure-random/src/nativeMain/kotlin/org/kotlincrypto/internal/-SecureRandomCinterop.kt index e42dfbb..ba442d0 100644 --- a/secure-random/src/nativeMain/kotlin/org/kotlincrypto/internal/-SecureRandomCinterop.kt +++ b/secure-random/src/nativeMain/kotlin/org/kotlincrypto/internal/-SecureRandomCinterop.kt @@ -15,10 +15,12 @@ **/ package org.kotlincrypto.internal +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.toKStringFromUtf8 import org.kotlincrypto.SecRandomCopyException import platform.posix.strerror +@OptIn(ExperimentalForeignApi::class) internal fun errnoToSecRandomCopyException(errno: Int): SecRandomCopyException { val message = strerror(errno)?.toKStringFromUtf8() ?: "errno: $errno" return SecRandomCopyException(message) diff --git a/secure-random/src/nativeMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt b/secure-random/src/nativeMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt index 85b0e7c..2c4112e 100644 --- a/secure-random/src/nativeMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt +++ b/secure-random/src/nativeMain/kotlin/org/kotlincrypto/internal/SecRandomDelegate.kt @@ -13,11 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") + package org.kotlincrypto.internal +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.Pinned import org.kotlincrypto.SecRandomCopyException +@OptIn(ExperimentalForeignApi::class) internal expect abstract class SecRandomDelegate private constructor() { @Throws(SecRandomCopyException::class)