jvmMain.dev.datlag.sekret.common.ExtendSystem.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sekret-jvm Show documentation
Show all versions of sekret-jvm Show documentation
Deeply hide secrets with Kotlin Multiplatform
The newest version!
package dev.datlag.sekret.common
import java.io.File
internal fun systemProperty(key: String): String? = runCatching {
System.getProperty(key).ifEmpty {
null
}
}.getOrNull()
@Suppress("UnsafeDynamicallyLoadedCode")
internal fun systemLoadLibrary(value: String, onError: () -> Unit = { }) {
if (runCatching {
System.loadLibrary(value)
}.isFailure) {
onError()
}
}
@Suppress("UnsafeDynamicallyLoadedCode")
internal fun systemLoadLibrary(value: File, onError: () -> Unit = { }) {
systemLoadLibrary(value.canonicalPath) {
systemLoadLibrary(value.path, onError)
}
}
@Suppress("UnsafeDynamicallyLoadedCode")
internal fun systemLoad(value: String, onError: () -> Unit = { }) {
if (runCatching {
System.load(value)
}.isFailure) {
onError()
}
}
@Suppress("UnsafeDynamicallyLoadedCode")
internal fun systemLoad(value: File, onError: () -> Unit = { }) {
systemLoad(value.canonicalPath) {
systemLoad(value.path, onError)
}
}