Skip to content

Commit

Permalink
Add support for changing kSecUseDataProtectionKeychain
Browse files Browse the repository at this point in the history
Rename variables and functions to match Apple
  • Loading branch information
alex-mcleod authored and mmoyerfigma committed May 19, 2024
1 parent b6777a4 commit a46d5c6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a46d5c6

Please sign in to comment.