objc2-security 0.3.2

Bindings to the Security framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

/// Specifies a keychain item's class code.
///
///
///
/// Note: AppleShare passwords are no longer used by macOS, starting in Leopard (10.5). Use of this item class is deprecated in OS X 10.9 and later; kSecInternetPasswordItemClass should be used instead when storing or looking up passwords for an Apple Filing Protocol (AFP) server.
///
///
///
///
///
/// The SecItemClass enumeration defines constants your application can use to specify the type of the keychain item you wish to create, dispose, add, delete, update, copy, or locate. You can also use these constants with the tag constant SecItemAttr.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/secitemclass?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SecItemClass(pub FourCharCode);
impl SecItemClass {
    #[doc(alias = "kSecInternetPasswordItemClass")]
    pub const InternetPasswordItemClass: Self = Self(0x696e6574);
    #[doc(alias = "kSecGenericPasswordItemClass")]
    pub const GenericPasswordItemClass: Self = Self(0x67656e70);
    #[doc(alias = "kSecAppleSharePasswordItemClass")]
    #[deprecated]
    pub const AppleSharePasswordItemClass: Self = Self(0x61736870);
    #[doc(alias = "kSecCertificateItemClass")]
    pub const CertificateItemClass: Self = Self(0x80001000);
    #[doc(alias = "kSecPublicKeyItemClass")]
    pub const PublicKeyItemClass: Self = Self(0x0000000F);
    #[doc(alias = "kSecPrivateKeyItemClass")]
    pub const PrivateKeyItemClass: Self = Self(0x00000010);
    #[doc(alias = "kSecSymmetricKeyItemClass")]
    pub const SymmetricKeyItemClass: Self = Self(0x00000011);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for SecItemClass {
    const ENCODING: Encoding = FourCharCode::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for SecItemClass {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Specifies keychain item attributes.
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
/// To obtain information about a certificate, use the CDSA Certificate Library (CL) API. To obtain information about a key, use the SecKeyGetCSSMKey function and the CDSA Cryptographic Service Provider (CSP) API.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/security/secitemattr?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SecItemAttr(pub FourCharCode);
impl SecItemAttr {
    #[doc(alias = "kSecCreationDateItemAttr")]
    pub const CreationDateItemAttr: Self = Self(0x63646174);
    #[doc(alias = "kSecModDateItemAttr")]
    pub const ModDateItemAttr: Self = Self(0x6d646174);
    #[doc(alias = "kSecDescriptionItemAttr")]
    pub const DescriptionItemAttr: Self = Self(0x64657363);
    #[doc(alias = "kSecCommentItemAttr")]
    pub const CommentItemAttr: Self = Self(0x69636d74);
    #[doc(alias = "kSecCreatorItemAttr")]
    pub const CreatorItemAttr: Self = Self(0x63727472);
    #[doc(alias = "kSecTypeItemAttr")]
    pub const TypeItemAttr: Self = Self(0x74797065);
    #[doc(alias = "kSecScriptCodeItemAttr")]
    pub const ScriptCodeItemAttr: Self = Self(0x73637270);
    #[doc(alias = "kSecLabelItemAttr")]
    pub const LabelItemAttr: Self = Self(0x6c61626c);
    #[doc(alias = "kSecInvisibleItemAttr")]
    pub const InvisibleItemAttr: Self = Self(0x696e7669);
    #[doc(alias = "kSecNegativeItemAttr")]
    pub const NegativeItemAttr: Self = Self(0x6e656761);
    #[doc(alias = "kSecCustomIconItemAttr")]
    pub const CustomIconItemAttr: Self = Self(0x63757369);
    #[doc(alias = "kSecAccountItemAttr")]
    pub const AccountItemAttr: Self = Self(0x61636374);
    #[doc(alias = "kSecServiceItemAttr")]
    pub const ServiceItemAttr: Self = Self(0x73766365);
    #[doc(alias = "kSecGenericItemAttr")]
    pub const GenericItemAttr: Self = Self(0x67656e61);
    #[doc(alias = "kSecSecurityDomainItemAttr")]
    pub const SecurityDomainItemAttr: Self = Self(0x73646d6e);
    #[doc(alias = "kSecServerItemAttr")]
    pub const ServerItemAttr: Self = Self(0x73727672);
    #[doc(alias = "kSecAuthenticationTypeItemAttr")]
    pub const AuthenticationTypeItemAttr: Self = Self(0x61747970);
    #[doc(alias = "kSecPortItemAttr")]
    pub const PortItemAttr: Self = Self(0x706f7274);
    #[doc(alias = "kSecPathItemAttr")]
    pub const PathItemAttr: Self = Self(0x70617468);
    #[doc(alias = "kSecVolumeItemAttr")]
    pub const VolumeItemAttr: Self = Self(0x766c6d65);
    #[doc(alias = "kSecAddressItemAttr")]
    pub const AddressItemAttr: Self = Self(0x61646472);
    #[doc(alias = "kSecSignatureItemAttr")]
    pub const SignatureItemAttr: Self = Self(0x73736967);
    #[doc(alias = "kSecProtocolItemAttr")]
    pub const ProtocolItemAttr: Self = Self(0x7074636c);
    #[doc(alias = "kSecCertificateType")]
    pub const CertificateType: Self = Self(0x63747970);
    #[doc(alias = "kSecCertificateEncoding")]
    pub const CertificateEncoding: Self = Self(0x63656e63);
    #[doc(alias = "kSecCrlType")]
    pub const CrlType: Self = Self(0x63727470);
    #[doc(alias = "kSecCrlEncoding")]
    pub const CrlEncoding: Self = Self(0x63726e63);
    #[doc(alias = "kSecAlias")]
    pub const Alias: Self = Self(0x616c6973);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for SecItemAttr {
    const ENCODING: Encoding = FourCharCode::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for SecItemAttr {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

#[cfg(feature = "SecBase")]
unsafe impl ConcreteType for SecKeychainItem {
    /// Returns the type identifier of SecKeychainItem instances.
    ///
    /// Returns: The CFTypeID of SecKeychainItem instances.
    #[doc(alias = "SecKeychainItemGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn SecKeychainItemGetTypeID() -> CFTypeID;
        }
        unsafe { SecKeychainItemGetTypeID() }
    }
}

#[cfg(feature = "SecBase")]
impl SecKeychainItem {
    /// Updates an existing keychain item after changing its attributes or data.
    ///
    /// Parameter `itemRef`: A reference to the keychain item to modify.
    ///
    /// Parameter `attrList`: The list of attributes to modify, along with their new values. Pass NULL if you don't need to modify any attributes.
    ///
    /// Parameter `length`: The length of the buffer pointed to by data.
    ///
    /// Parameter `data`: Pointer to a buffer containing the data to store. Pass NULL if you don't need to modify the data.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// The keychain item is written to the keychain's permanent data store. If the keychain item has not previously been added to a keychain, a call to the SecKeychainItemModifyContent function does nothing and returns errSecSuccess.
    ///
    /// # Safety
    ///
    /// - `attr_list` must be a valid pointer or null.
    /// - `data` must be a valid pointer or null.
    #[doc(alias = "SecKeychainItemModifyAttributesAndData")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn modify_attributes_and_data(
        &self,
        attr_list: *const SecKeychainAttributeList,
        length: u32,
        data: *const c_void,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemModifyAttributesAndData(
                item_ref: &SecKeychainItem,
                attr_list: *const SecKeychainAttributeList,
                length: u32,
                data: *const c_void,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemModifyAttributesAndData(self, attr_list, length, data) }
    }

    /// Creates a new keychain item from the supplied parameters.
    ///
    /// Parameter `itemClass`: A constant identifying the class of item to create.
    ///
    /// Parameter `attrList`: The list of attributes of the item to create.
    ///
    /// Parameter `length`: The length of the buffer pointed to by data.
    ///
    /// Parameter `data`: A pointer to a buffer containing the data to store.
    ///
    /// Parameter `initialAccess`: A reference to the access for this keychain item.
    ///
    /// Parameter `keychainRef`: A reference to the keychain in which to add the item.
    ///
    /// Parameter `itemRef`: On return, a pointer to a reference to the newly created keychain item (optional). When the item reference is no longer required, call CFRelease to deallocate memory occupied by the item.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h). In addition, errSecParam (-50) may be returned if not enough valid parameters are supplied, or errSecAllocate (-108) if there is not enough memory in the current heap zone to create the object.
    ///
    /// # Safety
    ///
    /// - `attr_list` must be a valid pointer.
    /// - `data` must be a valid pointer or null.
    /// - `item_ref` must be a valid pointer or null.
    #[doc(alias = "SecKeychainItemCreateFromContent")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn create_from_content(
        item_class: SecItemClass,
        attr_list: NonNull<SecKeychainAttributeList>,
        length: u32,
        data: *const c_void,
        keychain_ref: Option<&SecKeychain>,
        initial_access: Option<&SecAccess>,
        item_ref: *mut *mut SecKeychainItem,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemCreateFromContent(
                item_class: SecItemClass,
                attr_list: NonNull<SecKeychainAttributeList>,
                length: u32,
                data: *const c_void,
                keychain_ref: Option<&SecKeychain>,
                initial_access: Option<&SecAccess>,
                item_ref: *mut *mut SecKeychainItem,
            ) -> OSStatus;
        }
        unsafe {
            SecKeychainItemCreateFromContent(
                item_class,
                attr_list,
                length,
                data,
                keychain_ref,
                initial_access,
                item_ref,
            )
        }
    }

    /// Updates an existing keychain item after changing its attributes or data. This call should only be used in conjunction with SecKeychainItemCopyContent().
    ///
    /// Parameter `itemRef`: A reference to the keychain item to modify.
    ///
    /// Parameter `attrList`: The list of attributes to modify, along with their new values. Pass NULL if you don't need to modify any attributes.
    ///
    /// Parameter `length`: The length of the buffer pointed to by data.
    ///
    /// Parameter `data`: A pointer to a buffer containing the data to store. Pass NULL if you don't need to modify the data.
    ///
    /// Returns: A result code.  See "Security Error Codes" (SecBase.h).
    ///
    /// # Safety
    ///
    /// - `attr_list` must be a valid pointer or null.
    /// - `data` must be a valid pointer or null.
    #[doc(alias = "SecKeychainItemModifyContent")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn modify_content(
        &self,
        attr_list: *const SecKeychainAttributeList,
        length: u32,
        data: *const c_void,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemModifyContent(
                item_ref: &SecKeychainItem,
                attr_list: *const SecKeychainAttributeList,
                length: u32,
                data: *const c_void,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemModifyContent(self, attr_list, length, data) }
    }

    /// Copies the data and/or attributes stored in the given keychain item. It is recommended that you use SecKeychainItemCopyAttributesAndData(). You must call SecKeychainItemFreeContent when you no longer need the attributes and data. If you want to modify the attributes returned here, use SecKeychainModifyContent().
    ///
    /// Parameter `itemRef`: A reference to the keychain item to modify.
    ///
    /// Parameter `itemClass`: On return, the item's class. Pass NULL if you don't require this information.
    ///
    /// Parameter `attrList`: On input, the list of attributes to retrieve. On output, the attributes are filled in. Pass NULL if you don't need to retrieve any attributes. You must call SecKeychainItemFreeContent when you no longer need the attributes.
    ///
    /// Parameter `length`: On return, the length of the buffer pointed to by outData.
    ///
    /// Parameter `outData`: On return, a pointer to a buffer containing the data in this item. Pass NULL if you don't need to retrieve the data. You must call SecKeychainItemFreeContent when you no longer need the data.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h). In addition, errSecParam (-50) may be returned if not enough valid parameters are supplied.
    ///
    /// # Safety
    ///
    /// - `item_class` must be a valid pointer or null.
    /// - `attr_list` must be a valid pointer or null.
    /// - `length` must be a valid pointer or null.
    /// - `out_data` must be a valid pointer or null.
    #[doc(alias = "SecKeychainItemCopyContent")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn copy_content(
        &self,
        item_class: *mut SecItemClass,
        attr_list: *mut SecKeychainAttributeList,
        length: *mut u32,
        out_data: *mut *mut c_void,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemCopyContent(
                item_ref: &SecKeychainItem,
                item_class: *mut SecItemClass,
                attr_list: *mut SecKeychainAttributeList,
                length: *mut u32,
                out_data: *mut *mut c_void,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemCopyContent(self, item_class, attr_list, length, out_data) }
    }

    /// Releases the memory used by the keychain attribute list and the keychain data retrieved in a previous call to SecKeychainItemCopyContent.
    ///
    /// Parameter `attrList`: A pointer to the attribute list to release. Pass NULL to ignore this parameter.
    ///
    /// Parameter `data`: A pointer to the data buffer to release. Pass NULL to ignore this parameter.
    ///
    /// # Safety
    ///
    /// - `attr_list` must be a valid pointer or null.
    /// - `data` must be a valid pointer or null.
    #[doc(alias = "SecKeychainItemFreeContent")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn free_content(
        attr_list: *mut SecKeychainAttributeList,
        data: *mut c_void,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemFreeContent(
                attr_list: *mut SecKeychainAttributeList,
                data: *mut c_void,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemFreeContent(attr_list, data) }
    }

    /// Copies the data and/or attributes stored in the given keychain item. You must call SecKeychainItemFreeAttributesAndData when you no longer need the attributes and data. If you want to modify the attributes returned here, use SecKeychainModifyAttributesAndData.
    ///
    /// Parameter `itemRef`: A reference to the keychain item to copy.
    ///
    /// Parameter `info`: A list of tags and formats of the attributes you wish to retrieve. Pass NULL if you don't need to retrieve any attributes. You can call SecKeychainAttributeInfoForItemID to obtain a list with all possible attribute tags and formats for the item's class.
    ///
    /// Parameter `itemClass`: On return, the item's class. Pass NULL if you don't require this information.
    ///
    /// Parameter `attrList`: On return, a pointer to the list of retrieved attributes. Pass NULL if you don't need to retrieve any attributes. You must call SecKeychainItemFreeAttributesAndData when you no longer need this list.
    ///
    /// Parameter `length`: On return, the length of the buffer pointed to by outData.
    ///
    /// Parameter `outData`: On return, a pointer to a buffer containing the data in this item. Pass NULL if you don't need to retrieve the data. You must call SecKeychainItemFreeAttributesAndData when you no longer need the data.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h). In addition, errSecParam (-50) may be returned if not enough valid parameters are supplied.
    ///
    /// # Safety
    ///
    /// - `info` must be a valid pointer or null.
    /// - `item_class` must be a valid pointer or null.
    /// - `attr_list` must be a valid pointer or null.
    /// - `length` must be a valid pointer or null.
    /// - `out_data` must be a valid pointer or null.
    #[doc(alias = "SecKeychainItemCopyAttributesAndData")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn copy_attributes_and_data(
        &self,
        info: *mut SecKeychainAttributeInfo,
        item_class: *mut SecItemClass,
        attr_list: *mut *mut SecKeychainAttributeList,
        length: *mut u32,
        out_data: *mut *mut c_void,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemCopyAttributesAndData(
                item_ref: &SecKeychainItem,
                info: *mut SecKeychainAttributeInfo,
                item_class: *mut SecItemClass,
                attr_list: *mut *mut SecKeychainAttributeList,
                length: *mut u32,
                out_data: *mut *mut c_void,
            ) -> OSStatus;
        }
        unsafe {
            SecKeychainItemCopyAttributesAndData(
                self, info, item_class, attr_list, length, out_data,
            )
        }
    }

    /// Releases the memory used by the keychain attribute list and the keychain data retrieved in a previous call to SecKeychainItemCopyAttributesAndData.
    ///
    /// Parameter `attrList`: A pointer to the attribute list to release. Pass NULL to ignore this parameter.
    ///
    /// Parameter `data`: A pointer to the data buffer to release. Pass NULL to ignore this parameter.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// # Safety
    ///
    /// - `attr_list` must be a valid pointer or null.
    /// - `data` must be a valid pointer or null.
    #[doc(alias = "SecKeychainItemFreeAttributesAndData")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn free_attributes_and_data(
        attr_list: *mut SecKeychainAttributeList,
        data: *mut c_void,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemFreeAttributesAndData(
                attr_list: *mut SecKeychainAttributeList,
                data: *mut c_void,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemFreeAttributesAndData(attr_list, data) }
    }

    /// Deletes a keychain item from the default keychain's permanent data store.
    ///
    /// Parameter `itemRef`: A keychain item reference of the item to delete.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// If itemRef has not previously been added to the keychain, SecKeychainItemDelete does nothing and returns errSecSuccess. IMPORTANT: SecKeychainItemDelete does not dispose the memory occupied by the item reference itself; use the CFRelease function when you are completely finished with an item.
    #[doc(alias = "SecKeychainItemDelete")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn delete(&self) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemDelete(item_ref: &SecKeychainItem) -> OSStatus;
        }
        unsafe { SecKeychainItemDelete(self) }
    }

    /// Copies an existing keychain reference from a keychain item.
    ///
    /// Parameter `itemRef`: A keychain item reference.
    ///
    /// Parameter `keychainRef`: On return, the keychain reference for the specified item. Release this reference by calling the CFRelease function.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// # Safety
    ///
    /// `keychain_ref` must be a valid pointer.
    #[doc(alias = "SecKeychainItemCopyKeychain")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn copy_keychain(&self, keychain_ref: NonNull<*mut SecKeychain>) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemCopyKeychain(
                item_ref: &SecKeychainItem,
                keychain_ref: NonNull<*mut SecKeychain>,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemCopyKeychain(self, keychain_ref) }
    }

    /// Copies a keychain item.
    ///
    /// Parameter `itemRef`: A reference to the keychain item to copy.
    ///
    /// Parameter `destKeychainRef`: A reference to the keychain in which to insert the copied keychain item.
    ///
    /// Parameter `initialAccess`: The initial access for the copied keychain item.
    ///
    /// Parameter `itemCopy`: On return, a reference to the copied keychain item.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// # Safety
    ///
    /// `item_copy` must be a valid pointer.
    #[doc(alias = "SecKeychainItemCreateCopy")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn create_copy(
        &self,
        dest_keychain_ref: Option<&SecKeychain>,
        initial_access: Option<&SecAccess>,
        item_copy: NonNull<*mut SecKeychainItem>,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemCreateCopy(
                item_ref: &SecKeychainItem,
                dest_keychain_ref: Option<&SecKeychain>,
                initial_access: Option<&SecAccess>,
                item_copy: NonNull<*mut SecKeychainItem>,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemCreateCopy(self, dest_keychain_ref, initial_access, item_copy) }
    }

    /// Returns a CFDataRef which can be used as a persistent reference to the given keychain item. The data obtained can be turned back into a SecKeychainItemRef later by calling SecKeychainItemCopyFromPersistentReference().
    ///
    /// Parameter `itemRef`: A reference to a keychain item.
    ///
    /// Parameter `persistentItemRef`: On return, a CFDataRef containing a persistent reference. You must release this data reference by calling the CFRelease function.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// # Safety
    ///
    /// `persistent_item_ref` must be a valid pointer.
    #[doc(alias = "SecKeychainItemCreatePersistentReference")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn create_persistent_reference(
        &self,
        persistent_item_ref: NonNull<*const CFData>,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemCreatePersistentReference(
                item_ref: &SecKeychainItem,
                persistent_item_ref: NonNull<*const CFData>,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemCreatePersistentReference(self, persistent_item_ref) }
    }

    /// Returns a SecKeychainItemRef, given a persistent reference previously obtained by calling SecKeychainItemCreatePersistentReference().
    ///
    /// Parameter `persistentItemRef`: A CFDataRef containing a persistent reference to a keychain item.
    ///
    /// Parameter `itemRef`: On return, a SecKeychainItemRef for the keychain item described by the persistent reference. You must release this item reference by calling the CFRelease function.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// # Safety
    ///
    /// `item_ref` must be a valid pointer.
    #[doc(alias = "SecKeychainItemCopyFromPersistentReference")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn copy_from_persistent_reference(
        persistent_item_ref: &CFData,
        item_ref: NonNull<*mut SecKeychainItem>,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemCopyFromPersistentReference(
                persistent_item_ref: &CFData,
                item_ref: NonNull<*mut SecKeychainItem>,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemCopyFromPersistentReference(persistent_item_ref, item_ref) }
    }

    /// Returns the CSSM_DL_DB_HANDLE for a given keychain item reference.
    ///
    /// Parameter `keyItemRef`: A keychain item reference.
    ///
    /// Parameter `dldbHandle`: On return, a CSSM_DL_DB_HANDLE for the keychain database containing the given item. The handle is valid until the keychain reference is released.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// This API is deprecated for 10.7. It should no longer be needed.
    ///
    /// # Safety
    ///
    /// `dldb_handle` must be a valid pointer.
    #[doc(alias = "SecKeychainItemGetDLDBHandle")]
    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
    #[deprecated = "CSSM is not supported"]
    #[inline]
    pub unsafe fn dldb_handle(&self, dldb_handle: NonNull<CSSM_DL_DB_HANDLE>) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemGetDLDBHandle(
                key_item_ref: &SecKeychainItem,
                dldb_handle: NonNull<CSSM_DL_DB_HANDLE>,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemGetDLDBHandle(self, dldb_handle) }
    }

    /// Returns a CSSM_DB_UNIQUE_RECORD for the given keychain item reference.
    ///
    /// Parameter `itemRef`: A keychain item reference.
    ///
    /// Parameter `uniqueRecordID`: On return, a pointer to a CSSM_DB_UNIQUE_RECORD structure for the given item. The unique record is valid until the item reference is released.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// This API is deprecated for 10.7. It should no longer be needed.
    ///
    /// # Safety
    ///
    /// `unique_record_id` must be a valid pointer.
    #[doc(alias = "SecKeychainItemGetUniqueRecordID")]
    #[cfg(all(
        feature = "SecAsn1Types",
        feature = "SecBase",
        feature = "cssmconfig",
        feature = "cssmtype"
    ))]
    #[deprecated = "CSSM is not supported"]
    #[inline]
    pub unsafe fn unique_record_id(
        &self,
        unique_record_id: NonNull<*const CSSM_DB_UNIQUE_RECORD>,
    ) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemGetUniqueRecordID(
                item_ref: &SecKeychainItem,
                unique_record_id: NonNull<*const CSSM_DB_UNIQUE_RECORD>,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemGetUniqueRecordID(self, unique_record_id) }
    }

    /// Copies the access of a given keychain item.
    ///
    /// Parameter `itemRef`: A reference to a keychain item.
    ///
    /// Parameter `access`: On return, a reference to the keychain item's access.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    ///
    /// # Safety
    ///
    /// `access` must be a valid pointer.
    #[doc(alias = "SecKeychainItemCopyAccess")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn copy_access(&self, access: NonNull<*mut SecAccess>) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemCopyAccess(
                item_ref: &SecKeychainItem,
                access: NonNull<*mut SecAccess>,
            ) -> OSStatus;
        }
        unsafe { SecKeychainItemCopyAccess(self, access) }
    }

    /// Sets the access of a given keychain item.
    ///
    /// Parameter `itemRef`: A reference to a keychain item.
    ///
    /// Parameter `access`: A reference to an access to replace the keychain item's current access.
    ///
    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
    #[doc(alias = "SecKeychainItemSetAccess")]
    #[cfg(feature = "SecBase")]
    #[deprecated = "SecKeychain is deprecated"]
    #[inline]
    pub unsafe fn set_access(&self, access: &SecAccess) -> OSStatus {
        extern "C-unwind" {
            fn SecKeychainItemSetAccess(item_ref: &SecKeychainItem, access: &SecAccess)
                -> OSStatus;
        }
        unsafe { SecKeychainItemSetAccess(self, access) }
    }
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::modify_attributes_and_data`"]
    pub fn SecKeychainItemModifyAttributesAndData(
        item_ref: &SecKeychainItem,
        attr_list: *const SecKeychainAttributeList,
        length: u32,
        data: *const c_void,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::create_from_content`"]
    pub fn SecKeychainItemCreateFromContent(
        item_class: SecItemClass,
        attr_list: NonNull<SecKeychainAttributeList>,
        length: u32,
        data: *const c_void,
        keychain_ref: Option<&SecKeychain>,
        initial_access: Option<&SecAccess>,
        item_ref: *mut *mut SecKeychainItem,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::modify_content`"]
    pub fn SecKeychainItemModifyContent(
        item_ref: &SecKeychainItem,
        attr_list: *const SecKeychainAttributeList,
        length: u32,
        data: *const c_void,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::copy_content`"]
    pub fn SecKeychainItemCopyContent(
        item_ref: &SecKeychainItem,
        item_class: *mut SecItemClass,
        attr_list: *mut SecKeychainAttributeList,
        length: *mut u32,
        out_data: *mut *mut c_void,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::free_content`"]
    pub fn SecKeychainItemFreeContent(
        attr_list: *mut SecKeychainAttributeList,
        data: *mut c_void,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::copy_attributes_and_data`"]
    pub fn SecKeychainItemCopyAttributesAndData(
        item_ref: &SecKeychainItem,
        info: *mut SecKeychainAttributeInfo,
        item_class: *mut SecItemClass,
        attr_list: *mut *mut SecKeychainAttributeList,
        length: *mut u32,
        out_data: *mut *mut c_void,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::free_attributes_and_data`"]
    pub fn SecKeychainItemFreeAttributesAndData(
        attr_list: *mut SecKeychainAttributeList,
        data: *mut c_void,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::delete`"]
    pub fn SecKeychainItemDelete(item_ref: &SecKeychainItem) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::copy_keychain`"]
    pub fn SecKeychainItemCopyKeychain(
        item_ref: &SecKeychainItem,
        keychain_ref: NonNull<*mut SecKeychain>,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::create_copy`"]
    pub fn SecKeychainItemCreateCopy(
        item_ref: &SecKeychainItem,
        dest_keychain_ref: Option<&SecKeychain>,
        initial_access: Option<&SecAccess>,
        item_copy: NonNull<*mut SecKeychainItem>,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::create_persistent_reference`"]
    pub fn SecKeychainItemCreatePersistentReference(
        item_ref: &SecKeychainItem,
        persistent_item_ref: NonNull<*const CFData>,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::copy_from_persistent_reference`"]
    pub fn SecKeychainItemCopyFromPersistentReference(
        persistent_item_ref: &CFData,
        item_ref: NonNull<*mut SecKeychainItem>,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
    #[deprecated = "renamed to `SecKeychainItem::dldb_handle`"]
    pub fn SecKeychainItemGetDLDBHandle(
        key_item_ref: &SecKeychainItem,
        dldb_handle: NonNull<CSSM_DL_DB_HANDLE>,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(all(
        feature = "SecAsn1Types",
        feature = "SecBase",
        feature = "cssmconfig",
        feature = "cssmtype"
    ))]
    #[deprecated = "renamed to `SecKeychainItem::unique_record_id`"]
    pub fn SecKeychainItemGetUniqueRecordID(
        item_ref: &SecKeychainItem,
        unique_record_id: NonNull<*const CSSM_DB_UNIQUE_RECORD>,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::copy_access`"]
    pub fn SecKeychainItemCopyAccess(
        item_ref: &SecKeychainItem,
        access: NonNull<*mut SecAccess>,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[cfg(feature = "SecBase")]
    #[deprecated = "renamed to `SecKeychainItem::set_access`"]
    pub fn SecKeychainItemSetAccess(item_ref: &SecKeychainItem, access: &SecAccess) -> OSStatus;
}