From a46d5c66c952168020b05c0e664fe253b08c78ec Mon Sep 17 00:00:00 2001 From: Alex McLeod Date: Mon, 27 Jan 2020 21:30:06 -0800 Subject: [PATCH] Add support for changing kSecUseDataProtectionKeychain Rename variables and functions to match Apple --- keychain.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/keychain.go b/keychain.go index 7d0a1ac..7eff9c8 100644 --- a/keychain.go +++ b/keychain.go @@ -209,6 +209,23 @@ var syncTypeRef = map[Synchronizable]C.CFTypeRef{ SynchronizableNo: C.CFTypeRef(C.kCFBooleanFalse), } +// DataProtection is the items data protection status +type UseDataProtectionKeychain int + +const ( + // UseDataProtectionKeychainYes enables data protection mode + UseDataProtectionKeychainYes = 1 + // UseDataProtectionKeychainNo disables data protection mode + UseDataProtectionKeychainNo = 2 +) + +// DataProtectionKey is the key type for DataProtection +var UseDataProtectionKey = attrKey(C.CFTypeRef(C.kSecUseDataProtectionKeychain)) +var dataProtectionTypeRef = map[UseDataProtectionKeychain]C.CFTypeRef{ + UseDataProtectionKeychainYes: C.CFTypeRef(C.kCFBooleanTrue), + UseDataProtectionKeychainNo: C.CFTypeRef(C.kCFBooleanFalse), +} + // Accessible is the items accessibility type Accessible int @@ -362,6 +379,11 @@ func (k *Item) SetSynchronizable(sync Synchronizable) { } } +// SetSynchronizable sets the synchronizable attribute +func (k *Item) SetUseDataProtectionKeychain(dataProtection UseDataProtectionKeychain) { + k.attr[UseDataProtectionKey] = dataProtectionTypeRef[dataProtection] +} + // SetAccessible sets the accessible attribute func (k *Item) SetAccessible(accessible Accessible) { if accessible != AccessibleDefault {