Skip to content

Commit

Permalink
Merge pull request #31 from Liftric/feat/custom-filename
Browse files Browse the repository at this point in the history
Feature: custom file name
  • Loading branch information
Jan authored Feb 17, 2022
2 parents 81fa632 + 641c874 commit efb24b8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@ sourceSets {
#### Android

```kotlin
val store = KVault(context)
val store = KVault(context, "<fileName>")
```

| Parameter | Description |
| :------------------ | :---------------------------------- |
| fileName (optional) | Name of the shared preferences file |

#### iOS

```kotlin
val store = KVault(serviceName = null, accessGroup = null)
val store = KVault("<serviceName>", "<accessGroup>")
```

| Parameter | Description |
| :----------- | :---------------------------------- |
| serviceName | Used to categories objects. |
| accessGroup | Used to share objects between apps. |
| Parameter | Description |
| :--------------------- | :---------------------------------- |
| serviceName (optional) | Used to categories objects |
| accessGroup (optional) | Used to share objects between apps |

### Setting

Expand Down
8 changes: 4 additions & 4 deletions buildSrc/src/main/java/Libs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ object Android {
}

object Versions {
const val Gradle = "7.0.0"
const val Kotlin = "1.5.30"
const val Versioning = "2.14.0"
const val Gradle = "7.1.1"
const val Kotlin = "1.6.10"
const val Versioning = "2.15.1"
const val Crypto = "1.1.0-alpha03"
const val RoboElectric = "4.5.1"
const val TestCore = "1.2.0"
const val TestCore = "1.4.0"
}

object Libs {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/androidMain/kotlin/com/liftric/kvault/KVault.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import android.content.SharedPreferences
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey

actual open class KVault(context: Context) {
actual open class KVault(context: Context, fileName: String? = null) {
private val encSharedPrefs: SharedPreferences

init {
val masterKey = MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build()
encSharedPrefs = EncryptedSharedPreferences.create(
context,
"secure-shared-preferences",
fileName ?: "secure-shared-preferences",
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
Expand Down
18 changes: 1 addition & 17 deletions src/iosMain/kotlin/com/liftric/kvault/KVault.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import platform.Security.*
import platform.darwin.OSStatus
import platform.darwin.noErr

internal val NSBundle.Companion.mainIdentifier
get() = this.mainBundle.bundleIdentifier?: "com.liftric.KVault"

/**
* Keychain wrapper.
* Note: Using the deprecated init() the service name was the apps bundle identifier or if null "com.liftric.KVault".
*
* @param serviceName Name of the service. Used to categories entries.
* @param accessGroup Name of the access group. Used to share entries between apps.
Expand All @@ -21,20 +19,6 @@ actual open class KVault(
val serviceName: String? = null,
val accessGroup: String? = null
) {
/**
* Initiates a Keychain with the main bundle identifier as the service name and without an access group.
* If the main bundle identifier is null, it will fallback to `com.liftric.KVault`.
*/
@Deprecated(
"""
Will be removed in a future version,
please use the primary constructor.
Check your service name before migrating.
""",
level = DeprecationLevel.WARNING
)
constructor() : this(NSBundle.mainIdentifier, null)

/**
* Saves a string value in the Keychain.
* @param key The key to store
Expand Down

0 comments on commit efb24b8

Please sign in to comment.