Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Support iCloud Keychain #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/iosMain/kotlin/com/liftric/kvault/KVault.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import com.liftric.kvault.impl.KVaultImpl
fun KVault(
serviceName: String? = null,
accessGroup: String? = null,
synchronizable: Boolean = false,
accessibility: KVaultImpl.Accessible = KVaultImpl.Accessible.WhenUnlocked
): KVault = KVaultImpl(serviceName, accessGroup, accessibility)
): KVault = KVaultImpl(serviceName, accessGroup, synchronizable, accessibility)
6 changes: 5 additions & 1 deletion src/iosMain/kotlin/com/liftric/kvault/impl/KVaultImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import platform.Security.kSecAttrAccessibleWhenUnlocked
import platform.Security.kSecAttrAccessibleWhenUnlockedThisDeviceOnly
import platform.Security.kSecAttrAccount
import platform.Security.kSecAttrService
import platform.Security.kSecAttrSynchronizable
import platform.Security.kSecClass
import platform.Security.kSecClassGenericPassword
import platform.Security.kSecMatchLimit
Expand All @@ -59,12 +60,14 @@ import platform.posix.memcpy
*
* @param serviceName Name of the service. Used to categories entries.
* @param accessGroup Name of the access group. Used to share entries between apps.
* @param synchronizable If true, the entries will be synced with iCloud.
* @param accessibility Level of the accessibility for the Keychain instance.
* @constructor Initiates a Keychain with the given parameters.
*/
actual open class KVaultImpl(
private val serviceName: String? = null,
private val accessGroup: String? = null,
private val synchronizable: Boolean = false,
private val accessibility: Accessible = Accessible.WhenUnlocked
): KVault {
/**
Expand Down Expand Up @@ -358,7 +361,8 @@ actual open class KVaultImpl(
private fun <T> context(vararg values: Any?, block: Context.(List<CFTypeRef?>) -> T): T {
val standard = mapOf(
kSecAttrService to CFBridgingRetain(serviceName),
kSecAttrAccessGroup to CFBridgingRetain(accessGroup)
kSecAttrAccessGroup to CFBridgingRetain(accessGroup),
kSecAttrSynchronizable to if (synchronizable) kCFBooleanTrue else kCFBooleanFalse
)
val custom = arrayOf(*values).map { CFBridgingRetain(it) }
return block.invoke(Context(standard), custom).apply {
Expand Down