objc2_security/generated/
SecImportExport.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "objc2")]
6use objc2::__framework_prelude::*;
7use objc2_core_foundation::*;
8
9use crate::*;
10
11/// [Apple's documentation](https://developer.apple.com/documentation/security/sec_key_import_export_params_version?language=objc)
12pub const SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION: c_uint = 0;
13/// [Apple's documentation](https://developer.apple.com/documentation/security/secexternalformat?language=objc)
14// NS_ENUM
15#[repr(transparent)]
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
17pub struct SecExternalFormat(pub u32);
18impl SecExternalFormat {
19    #[doc(alias = "kSecFormatUnknown")]
20    pub const FormatUnknown: Self = Self(0);
21    #[doc(alias = "kSecFormatOpenSSL")]
22    pub const FormatOpenSSL: Self = Self(1);
23    #[doc(alias = "kSecFormatSSH")]
24    pub const FormatSSH: Self = Self(2);
25    #[doc(alias = "kSecFormatBSAFE")]
26    pub const FormatBSAFE: Self = Self(3);
27    #[doc(alias = "kSecFormatRawKey")]
28    pub const FormatRawKey: Self = Self(4);
29    #[doc(alias = "kSecFormatWrappedPKCS8")]
30    pub const FormatWrappedPKCS8: Self = Self(5);
31    #[doc(alias = "kSecFormatWrappedOpenSSL")]
32    pub const FormatWrappedOpenSSL: Self = Self(6);
33    #[doc(alias = "kSecFormatWrappedSSH")]
34    pub const FormatWrappedSSH: Self = Self(7);
35    #[doc(alias = "kSecFormatWrappedLSH")]
36    pub const FormatWrappedLSH: Self = Self(8);
37    #[doc(alias = "kSecFormatX509Cert")]
38    pub const FormatX509Cert: Self = Self(9);
39    #[doc(alias = "kSecFormatPEMSequence")]
40    pub const FormatPEMSequence: Self = Self(10);
41    #[doc(alias = "kSecFormatPKCS7")]
42    pub const FormatPKCS7: Self = Self(11);
43    #[doc(alias = "kSecFormatPKCS12")]
44    pub const FormatPKCS12: Self = Self(12);
45    #[doc(alias = "kSecFormatNetscapeCertSequence")]
46    pub const FormatNetscapeCertSequence: Self = Self(13);
47    #[doc(alias = "kSecFormatSSHv2")]
48    pub const FormatSSHv2: Self = Self(14);
49}
50
51#[cfg(feature = "objc2")]
52unsafe impl Encode for SecExternalFormat {
53    const ENCODING: Encoding = u32::ENCODING;
54}
55
56#[cfg(feature = "objc2")]
57unsafe impl RefEncode for SecExternalFormat {
58    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
59}
60
61/// [Apple's documentation](https://developer.apple.com/documentation/security/secexternalitemtype?language=objc)
62// NS_ENUM
63#[repr(transparent)]
64#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
65pub struct SecExternalItemType(pub u32);
66impl SecExternalItemType {
67    #[doc(alias = "kSecItemTypeUnknown")]
68    pub const ItemTypeUnknown: Self = Self(0);
69    #[doc(alias = "kSecItemTypePrivateKey")]
70    pub const ItemTypePrivateKey: Self = Self(1);
71    #[doc(alias = "kSecItemTypePublicKey")]
72    pub const ItemTypePublicKey: Self = Self(2);
73    #[doc(alias = "kSecItemTypeSessionKey")]
74    pub const ItemTypeSessionKey: Self = Self(3);
75    #[doc(alias = "kSecItemTypeCertificate")]
76    pub const ItemTypeCertificate: Self = Self(4);
77    #[doc(alias = "kSecItemTypeAggregate")]
78    pub const ItemTypeAggregate: Self = Self(5);
79}
80
81#[cfg(feature = "objc2")]
82unsafe impl Encode for SecExternalItemType {
83    const ENCODING: Encoding = u32::ENCODING;
84}
85
86#[cfg(feature = "objc2")]
87unsafe impl RefEncode for SecExternalItemType {
88    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
89}
90
91/// [Apple's documentation](https://developer.apple.com/documentation/security/secitemimportexportflags?language=objc)
92// NS_OPTIONS
93#[repr(transparent)]
94#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
95pub struct SecItemImportExportFlags(pub u32);
96bitflags::bitflags! {
97    impl SecItemImportExportFlags: u32 {
98        #[doc(alias = "kSecItemPemArmour")]
99        const PemArmour = 0x00000001;
100    }
101}
102
103#[cfg(feature = "objc2")]
104unsafe impl Encode for SecItemImportExportFlags {
105    const ENCODING: Encoding = u32::ENCODING;
106}
107
108#[cfg(feature = "objc2")]
109unsafe impl RefEncode for SecItemImportExportFlags {
110    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
111}
112
113/// [Apple's documentation](https://developer.apple.com/documentation/security/seckeyimportexportflags?language=objc)
114// NS_OPTIONS
115#[repr(transparent)]
116#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
117pub struct SecKeyImportExportFlags(pub u32);
118bitflags::bitflags! {
119    impl SecKeyImportExportFlags: u32 {
120        #[doc(alias = "kSecKeyImportOnlyOne")]
121        const ImportOnlyOne = 0x00000001;
122        #[doc(alias = "kSecKeySecurePassphrase")]
123        const SecurePassphrase = 0x00000002;
124        #[doc(alias = "kSecKeyNoAccessControl")]
125        const NoAccessControl = 0x00000004;
126    }
127}
128
129#[cfg(feature = "objc2")]
130unsafe impl Encode for SecKeyImportExportFlags {
131    const ENCODING: Encoding = u32::ENCODING;
132}
133
134#[cfg(feature = "objc2")]
135unsafe impl RefEncode for SecKeyImportExportFlags {
136    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
137}
138
139/// [Apple's documentation](https://developer.apple.com/documentation/security/seckeyimportexportparameters?language=objc)
140#[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
141#[repr(C)]
142#[derive(Clone, Copy, Debug, PartialEq)]
143pub struct SecKeyImportExportParameters {
144    pub version: u32,
145    pub flags: SecKeyImportExportFlags,
146    pub passphrase: *const CFType,
147    pub alertTitle: NonNull<CFString>,
148    pub alertPrompt: NonNull<CFString>,
149    pub accessRef: *mut SecAccess,
150    pub keyUsage: CSSM_KEYUSE,
151    pub keyAttributes: CSSM_KEYATTR_FLAGS,
152}
153
154#[cfg(all(
155    feature = "SecBase",
156    feature = "cssmconfig",
157    feature = "cssmtype",
158    feature = "objc2"
159))]
160unsafe impl Encode for SecKeyImportExportParameters {
161    const ENCODING: Encoding = Encoding::Struct(
162        "?",
163        &[
164            <u32>::ENCODING,
165            <SecKeyImportExportFlags>::ENCODING,
166            <*const CFType>::ENCODING,
167            <NonNull<CFString>>::ENCODING,
168            <NonNull<CFString>>::ENCODING,
169            <*mut SecAccess>::ENCODING,
170            <CSSM_KEYUSE>::ENCODING,
171            <CSSM_KEYATTR_FLAGS>::ENCODING,
172        ],
173    );
174}
175
176#[cfg(all(
177    feature = "SecBase",
178    feature = "cssmconfig",
179    feature = "cssmtype",
180    feature = "objc2"
181))]
182unsafe impl RefEncode for SecKeyImportExportParameters {
183    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
184}
185
186/// [Apple's documentation](https://developer.apple.com/documentation/security/secitemimportexportkeyparameters?language=objc)
187#[cfg(feature = "SecBase")]
188#[repr(C)]
189#[derive(Clone, Copy, Debug, PartialEq)]
190pub struct SecItemImportExportKeyParameters {
191    pub version: u32,
192    pub flags: SecKeyImportExportFlags,
193    pub passphrase: *const CFType,
194    pub alertTitle: *const CFString,
195    pub alertPrompt: *const CFString,
196    pub accessRef: *mut SecAccess,
197    pub keyUsage: *const CFArray,
198    pub keyAttributes: *const CFArray,
199}
200
201#[cfg(all(feature = "SecBase", feature = "objc2"))]
202unsafe impl Encode for SecItemImportExportKeyParameters {
203    const ENCODING: Encoding = Encoding::Struct(
204        "?",
205        &[
206            <u32>::ENCODING,
207            <SecKeyImportExportFlags>::ENCODING,
208            <*const CFType>::ENCODING,
209            <*const CFString>::ENCODING,
210            <*const CFString>::ENCODING,
211            <*mut SecAccess>::ENCODING,
212            <*const CFArray>::ENCODING,
213            <*const CFArray>::ENCODING,
214        ],
215    );
216}
217
218#[cfg(all(feature = "SecBase", feature = "objc2"))]
219unsafe impl RefEncode for SecItemImportExportKeyParameters {
220    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
221}
222
223#[cfg(feature = "SecBase")]
224impl SecKeychainItem {
225    /// # Safety
226    ///
227    /// - `keychain_item_or_array` should be of the correct type.
228    /// - `key_params` must be a valid pointer or null.
229    /// - `exported_data` must be a valid pointer.
230    #[doc(alias = "SecKeychainItemExport")]
231    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
232    #[deprecated]
233    #[inline]
234    pub unsafe fn export(
235        keychain_item_or_array: &CFType,
236        output_format: SecExternalFormat,
237        flags: SecItemImportExportFlags,
238        key_params: *const SecKeyImportExportParameters,
239        exported_data: NonNull<*const CFData>,
240    ) -> OSStatus {
241        extern "C-unwind" {
242            fn SecKeychainItemExport(
243                keychain_item_or_array: &CFType,
244                output_format: SecExternalFormat,
245                flags: SecItemImportExportFlags,
246                key_params: *const SecKeyImportExportParameters,
247                exported_data: NonNull<*const CFData>,
248            ) -> OSStatus;
249        }
250        unsafe {
251            SecKeychainItemExport(
252                keychain_item_or_array,
253                output_format,
254                flags,
255                key_params,
256                exported_data,
257            )
258        }
259    }
260}
261
262extern "C-unwind" {
263    /// # Safety
264    ///
265    /// - `sec_item_or_array` should be of the correct type.
266    /// - `key_params` must be a valid pointer or null.
267    /// - `exported_data` must be a valid pointer.
268    #[cfg(feature = "SecBase")]
269    pub fn SecItemExport(
270        sec_item_or_array: &CFType,
271        output_format: SecExternalFormat,
272        flags: SecItemImportExportFlags,
273        key_params: *const SecItemImportExportKeyParameters,
274        exported_data: NonNull<*const CFData>,
275    ) -> OSStatus;
276}
277
278#[cfg(feature = "SecBase")]
279impl SecKeychainItem {
280    /// # Safety
281    ///
282    /// - `input_format` must be a valid pointer or null.
283    /// - `item_type` must be a valid pointer or null.
284    /// - `key_params` must be a valid pointer or null.
285    /// - `out_items` must be a valid pointer or null.
286    #[doc(alias = "SecKeychainItemImport")]
287    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
288    #[deprecated]
289    #[inline]
290    pub unsafe fn import(
291        imported_data: &CFData,
292        file_name_or_extension: Option<&CFString>,
293        input_format: *mut SecExternalFormat,
294        item_type: *mut SecExternalItemType,
295        flags: SecItemImportExportFlags,
296        key_params: *const SecKeyImportExportParameters,
297        import_keychain: Option<&SecKeychain>,
298        out_items: *mut *const CFArray,
299    ) -> OSStatus {
300        extern "C-unwind" {
301            fn SecKeychainItemImport(
302                imported_data: &CFData,
303                file_name_or_extension: Option<&CFString>,
304                input_format: *mut SecExternalFormat,
305                item_type: *mut SecExternalItemType,
306                flags: SecItemImportExportFlags,
307                key_params: *const SecKeyImportExportParameters,
308                import_keychain: Option<&SecKeychain>,
309                out_items: *mut *const CFArray,
310            ) -> OSStatus;
311        }
312        unsafe {
313            SecKeychainItemImport(
314                imported_data,
315                file_name_or_extension,
316                input_format,
317                item_type,
318                flags,
319                key_params,
320                import_keychain,
321                out_items,
322            )
323        }
324    }
325}
326
327extern "C-unwind" {
328    /// # Safety
329    ///
330    /// - `input_format` must be a valid pointer or null.
331    /// - `item_type` must be a valid pointer or null.
332    /// - `key_params` must be a valid pointer or null.
333    /// - `out_items` must be a valid pointer or null.
334    #[cfg(feature = "SecBase")]
335    pub fn SecItemImport(
336        imported_data: &CFData,
337        file_name_or_extension: Option<&CFString>,
338        input_format: *mut SecExternalFormat,
339        item_type: *mut SecExternalItemType,
340        flags: SecItemImportExportFlags,
341        key_params: *const SecItemImportExportKeyParameters,
342        import_keychain: Option<&SecKeychain>,
343        out_items: *mut *const CFArray,
344    ) -> OSStatus;
345}
346
347extern "C" {
348    /// Predefined key constants used when passing dictionary-based arguments to import/export functions.
349    ///
350    /// See also [Apple's documentation](https://developer.apple.com/documentation/security/ksecimportexportpassphrase?language=objc)
351    pub static kSecImportExportPassphrase: &'static CFString;
352}
353
354extern "C" {
355    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecimportexportkeychain?language=objc)
356    pub static kSecImportExportKeychain: &'static CFString;
357}
358
359extern "C" {
360    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecimportexportaccess?language=objc)
361    pub static kSecImportExportAccess: &'static CFString;
362}
363
364extern "C" {
365    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecimporttomemoryonly?language=objc)
366    pub static kSecImportToMemoryOnly: &'static CFString;
367}
368
369extern "C" {
370    /// Predefined key constants used to pass back a CFArray with a
371    /// CFDictionary per item.
372    ///
373    ///
374    /// This implementation specific identifier cannot be expected to have
375    /// any format.
376    ///
377    /// the SHA-1 digest of the public key.
378    ///
379    ///
380    /// certificates.  Not guaranteed to successfully evaluate.
381    ///
382    /// certificates for this item's identity
383    ///
384    /// See also [Apple's documentation](https://developer.apple.com/documentation/security/ksecimportitemlabel?language=objc)
385    pub static kSecImportItemLabel: &'static CFString;
386}
387
388extern "C" {
389    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecimportitemkeyid?language=objc)
390    pub static kSecImportItemKeyID: &'static CFString;
391}
392
393extern "C" {
394    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecimportitemtrust?language=objc)
395    pub static kSecImportItemTrust: &'static CFString;
396}
397
398extern "C" {
399    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecimportitemcertchain?language=objc)
400    pub static kSecImportItemCertChain: &'static CFString;
401}
402
403extern "C" {
404    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecimportitemidentity?language=objc)
405    pub static kSecImportItemIdentity: &'static CFString;
406}
407
408extern "C-unwind" {
409    /// Imports the contents of a PKCS12 formatted blob.
410    ///
411    /// Parameter `pkcs12_data`: The PKCS#12 formatted data to be imported.
412    ///
413    /// Parameter `options`: A dictionary containing import options. A
414    /// kSecImportExportPassphrase entry is required at minimum. Only password-based
415    /// PKCS12 blobs are currently supported.
416    ///
417    /// Parameter `items`: On return, an array containing a dictionary for every item
418    /// extracted. Use kSecImportItem constants to access specific elements of
419    /// these dictionaries. Your code must CFRelease the array when it is no longer
420    /// needed.
421    ///
422    /// Returns: errSecSuccess in case of success. errSecDecode means either the
423    /// blob can't be read or it is malformed. errSecAuthFailed means an
424    /// incorrect password was supplied, or data in the container is damaged.
425    ///
426    /// The normal behavior of this function is to import items into process
427    /// memory on iOS, and into the default keychain on macOS. You can modify this behavior
428    /// with entries in the options dictionary. To specify a file-based keychain and
429    /// legacy access control on macOS, provide kSecImportExportKeychain with a SecKeychainRef
430    /// value, and/or kSecImportExportAccess with a SecAccessRef value. In macOS 14 and later,
431    /// it is possible to specify the data protection keychain instead of a file-based keychain
432    /// by including kSecUseDataProtectionKeychain with a value of kCFBooleanTrue. Starting with
433    /// macOS 15 and iOS 18, kSecImportToMemoryOnly (with a value of kCFBooleanTrue) allows you
434    /// to skip importing to the keychain on macOS and explicitly specify iOS behavior.
435    ///
436    /// # Safety
437    ///
438    /// - `options` generics must be of the correct type.
439    /// - `items` must be a valid pointer.
440    pub fn SecPKCS12Import(
441        pkcs12_data: &CFData,
442        options: &CFDictionary,
443        items: NonNull<*const CFArray>,
444    ) -> OSStatus;
445}
446
447extern "C-unwind" {
448    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
449    #[deprecated = "renamed to `SecKeychainItem::export`"]
450    pub fn SecKeychainItemExport(
451        keychain_item_or_array: &CFType,
452        output_format: SecExternalFormat,
453        flags: SecItemImportExportFlags,
454        key_params: *const SecKeyImportExportParameters,
455        exported_data: NonNull<*const CFData>,
456    ) -> OSStatus;
457}
458
459extern "C-unwind" {
460    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
461    #[deprecated = "renamed to `SecKeychainItem::import`"]
462    pub fn SecKeychainItemImport(
463        imported_data: &CFData,
464        file_name_or_extension: Option<&CFString>,
465        input_format: *mut SecExternalFormat,
466        item_type: *mut SecExternalItemType,
467        flags: SecItemImportExportFlags,
468        key_params: *const SecKeyImportExportParameters,
469        import_keychain: Option<&SecKeychain>,
470        out_items: *mut *const CFArray,
471    ) -> OSStatus;
472}