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

Add support for changing kSecUseDataProtectionKeychain #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
Copy link
Member

@joshblum joshblum Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SetSynchronizable sets the synchronizable attribute
// SetUseDataProtectionKeychain sets the data protection 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