SecItemAdd

Function SecItemAdd 

Source
pub unsafe extern "C-unwind" fn SecItemAdd(
    attributes: &CFDictionary,
    result: *mut *const CFType,
) -> i32
Available on crate feature SecItem only.
Expand description

Add one or more items to a keychain.

Parameter attributes: A dictionary containing an item class specification and optional entries specifying the item’s attribute values. See the “Attribute Key Constants” section for a description of currently defined attributes.

Parameter result: On return, a CFTypeRef reference to the newly added item(s). The exact type of the result is based on the values supplied in attributes, as discussed below. Pass NULL if this result is not required.

Returns: A result code. See “Security Error Codes” (SecBase.h).

Attributes defining an item are specified by adding key/value pairs to the attributes dictionary. To add multiple items to a keychain at once use the kSecUseItemList key with an array of items as its value. This is currently only supported for non password items.

On macOS, to add an item to a particular keychain, supply kSecUseKeychain with a SecKeychainRef as its value.

On iOS, watchOS & tvOS, Certificate, Key, and Identity items may be added by reference, but neither Internet Passwords nor Generic Passwords may be. Similarly, on macOS with either kSecUseDataProtectionKeychain set to true or kSecAttrSynchronizable set to true, Certificate, Key, and Identity items may be added by reference, but neither Internet Passwords nor Generic Passwords may be.

Result types are specified as follows:

To obtain the data of the added item (CFDataRef), specify kSecReturnData with a value of kCFBooleanTrue. To obtain all the attributes of the added item (CFDictionaryRef), specify kSecReturnAttributes with a value of kCFBooleanTrue. To obtain a reference to the added item (SecKeychainItemRef, SecKeyRef, SecCertificateRef, or SecIdentityRef), specify kSecReturnRef with a value of kCFBooleanTrue. See also note about kSecReturnRef and macOS. To obtain a persistent reference to the added item (CFDataRef), specify kSecReturnPersistentRef with a value of kCFBooleanTrue. Note that unlike normal references, a persistent reference may be stored on disk or passed between processes. If more than one of these result types is specified, the result is returned as a CFDictionaryRef containing all the requested data. On iOS, if a result type is not specified, no results are returned. On macOS, the added item is returned.

§Safety

  • attributes generics must be of the correct type.
  • result must be a valid pointer or null.