-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
224 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
sekret-lib/src/commonMain/kotlin/dev/datlag/sekret/EncryptedSecret.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.datlag.sekret | ||
|
||
class EncryptedSecret private constructor( | ||
private val data: IntArray | ||
) { | ||
fun decrypt(key: String): String { | ||
return SekretHelper.getNativeValue(data, key) | ||
} | ||
|
||
companion object { | ||
operator fun invoke(data: IntArray?): EncryptedSecret? { | ||
return if (data == null || data.isEmpty()) { | ||
null | ||
} else { | ||
EncryptedSecret(data) | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
sekret-lib/src/commonMain/kotlin/dev/datlag/sekret/SekretConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package dev.datlag.sekret | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Configure Sekret decryption behavior. | ||
* | ||
* @param jni specify JNI related configuration (Android and Desktop JVM) | ||
*/ | ||
@Serializable | ||
data class SekretConfig( | ||
val jni: JNI = JNI() | ||
) { | ||
/** | ||
* Configure decryption behavior on JNI. | ||
* | ||
* @param decryptDirectly if true decrypts directly in native code, might expose keys to JNI tracing. | ||
* @param fallbackToDirectDecryption if true decrypts in native code if non-native decryption fails. | ||
* See [decryptDirectly] | ||
*/ | ||
@Serializable | ||
data class JNI( | ||
val decryptDirectly: Boolean = false, | ||
val fallbackToDirectDecryption: Boolean = true, | ||
) { | ||
class Builder { | ||
var decryptDirectly: Boolean = false | ||
var fallbackToDirectDecryption: Boolean = true | ||
|
||
fun build(): JNI = JNI(decryptDirectly, fallbackToDirectDecryption) | ||
} | ||
} | ||
|
||
class Builder { | ||
var jni: JNI = JNI() | ||
private set | ||
|
||
fun jni(block: JNI.Builder.() -> Unit) = apply { | ||
jni = JNI.Builder().apply(block).build() | ||
} | ||
|
||
fun build(): SekretConfig = SekretConfig(jni) | ||
} | ||
} | ||
|
||
fun SekretConfig(block: SekretConfig.Builder.() -> Unit) = SekretConfig.Builder().apply(block).build() |