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 committed Jan 28, 2020
1 parent f65a47c commit 230a88a
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 @@ -190,6 +190,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 @@ -303,6 +320,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 230a88a

Please sign in to comment.