1use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13#[doc(alias = "CMSEncoderRef")]
15#[repr(C)]
16pub struct CMSEncoder {
17 inner: [u8; 0],
18 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
19}
20
21cf_type!(
22 unsafe impl CMSEncoder {}
23);
24#[cfg(feature = "objc2")]
25cf_objc2_type!(
26 unsafe impl RefEncode<"_CMSEncoder"> for CMSEncoder {}
27);
28
29unsafe impl ConcreteType for CMSEncoder {
30 #[doc(alias = "CMSEncoderGetTypeID")]
31 #[inline]
32 fn type_id() -> CFTypeID {
33 extern "C-unwind" {
34 fn CMSEncoderGetTypeID() -> CFTypeID;
35 }
36 unsafe { CMSEncoderGetTypeID() }
37 }
38}
39
40impl CMSEncoder {
41 #[doc(alias = "CMSEncoderCreate")]
45 #[inline]
46 pub unsafe fn create(cms_encoder_out: NonNull<*mut CMSEncoder>) -> OSStatus {
47 extern "C-unwind" {
48 fn CMSEncoderCreate(cms_encoder_out: NonNull<*mut CMSEncoder>) -> OSStatus;
49 }
50 unsafe { CMSEncoderCreate(cms_encoder_out) }
51 }
52}
53
54extern "C" {
55 pub static kCMSEncoderDigestAlgorithmSHA1: &'static CFString;
57}
58
59extern "C" {
60 pub static kCMSEncoderDigestAlgorithmSHA256: &'static CFString;
62}
63
64impl CMSEncoder {
65 #[doc(alias = "CMSEncoderSetSignerAlgorithm")]
66 #[inline]
67 pub unsafe fn set_signer_algorithm(&self, digest_algorithm: &CFString) -> OSStatus {
68 extern "C-unwind" {
69 fn CMSEncoderSetSignerAlgorithm(
70 cms_encoder: &CMSEncoder,
71 digest_algorithm: &CFString,
72 ) -> OSStatus;
73 }
74 unsafe { CMSEncoderSetSignerAlgorithm(self, digest_algorithm) }
75 }
76
77 #[doc(alias = "CMSEncoderAddSigners")]
81 #[inline]
82 pub unsafe fn add_signers(&self, signer_or_array: &CFType) -> OSStatus {
83 extern "C-unwind" {
84 fn CMSEncoderAddSigners(cms_encoder: &CMSEncoder, signer_or_array: &CFType)
85 -> OSStatus;
86 }
87 unsafe { CMSEncoderAddSigners(self, signer_or_array) }
88 }
89
90 #[doc(alias = "CMSEncoderCopySigners")]
94 #[inline]
95 pub unsafe fn copy_signers(&self, signers_out: NonNull<*const CFArray>) -> OSStatus {
96 extern "C-unwind" {
97 fn CMSEncoderCopySigners(
98 cms_encoder: &CMSEncoder,
99 signers_out: NonNull<*const CFArray>,
100 ) -> OSStatus;
101 }
102 unsafe { CMSEncoderCopySigners(self, signers_out) }
103 }
104
105 #[doc(alias = "CMSEncoderAddRecipients")]
109 #[inline]
110 pub unsafe fn add_recipients(&self, recipient_or_array: &CFType) -> OSStatus {
111 extern "C-unwind" {
112 fn CMSEncoderAddRecipients(
113 cms_encoder: &CMSEncoder,
114 recipient_or_array: &CFType,
115 ) -> OSStatus;
116 }
117 unsafe { CMSEncoderAddRecipients(self, recipient_or_array) }
118 }
119
120 #[doc(alias = "CMSEncoderCopyRecipients")]
124 #[inline]
125 pub unsafe fn copy_recipients(&self, recipients_out: NonNull<*const CFArray>) -> OSStatus {
126 extern "C-unwind" {
127 fn CMSEncoderCopyRecipients(
128 cms_encoder: &CMSEncoder,
129 recipients_out: NonNull<*const CFArray>,
130 ) -> OSStatus;
131 }
132 unsafe { CMSEncoderCopyRecipients(self, recipients_out) }
133 }
134
135 #[doc(alias = "CMSEncoderSetHasDetachedContent")]
136 #[inline]
137 pub unsafe fn set_has_detached_content(&self, detached_content: bool) -> OSStatus {
138 extern "C-unwind" {
139 fn CMSEncoderSetHasDetachedContent(
140 cms_encoder: &CMSEncoder,
141 detached_content: Boolean,
142 ) -> OSStatus;
143 }
144 unsafe { CMSEncoderSetHasDetachedContent(self, detached_content as _) }
145 }
146
147 #[doc(alias = "CMSEncoderGetHasDetachedContent")]
151 #[inline]
152 pub unsafe fn has_detached_content(&self, detached_content_out: NonNull<Boolean>) -> OSStatus {
153 extern "C-unwind" {
154 fn CMSEncoderGetHasDetachedContent(
155 cms_encoder: &CMSEncoder,
156 detached_content_out: NonNull<Boolean>,
157 ) -> OSStatus;
158 }
159 unsafe { CMSEncoderGetHasDetachedContent(self, detached_content_out) }
160 }
161
162 #[doc(alias = "CMSEncoderSetEncapsulatedContentType")]
166 #[cfg(feature = "SecAsn1Types")]
167 #[deprecated]
168 #[inline]
169 pub unsafe fn set_encapsulated_content_type(
170 &self,
171 e_content_type: NonNull<SecAsn1Oid>,
172 ) -> OSStatus {
173 extern "C-unwind" {
174 fn CMSEncoderSetEncapsulatedContentType(
175 cms_encoder: &CMSEncoder,
176 e_content_type: NonNull<SecAsn1Oid>,
177 ) -> OSStatus;
178 }
179 unsafe { CMSEncoderSetEncapsulatedContentType(self, e_content_type) }
180 }
181
182 #[doc(alias = "CMSEncoderSetEncapsulatedContentTypeOID")]
186 #[inline]
187 pub unsafe fn set_encapsulated_content_type_oid(
188 &self,
189 e_content_type_oid: &CFType,
190 ) -> OSStatus {
191 extern "C-unwind" {
192 fn CMSEncoderSetEncapsulatedContentTypeOID(
193 cms_encoder: &CMSEncoder,
194 e_content_type_oid: &CFType,
195 ) -> OSStatus;
196 }
197 unsafe { CMSEncoderSetEncapsulatedContentTypeOID(self, e_content_type_oid) }
198 }
199
200 #[doc(alias = "CMSEncoderCopyEncapsulatedContentType")]
204 #[inline]
205 pub unsafe fn copy_encapsulated_content_type(
206 &self,
207 e_content_type_out: NonNull<*const CFData>,
208 ) -> OSStatus {
209 extern "C-unwind" {
210 fn CMSEncoderCopyEncapsulatedContentType(
211 cms_encoder: &CMSEncoder,
212 e_content_type_out: NonNull<*const CFData>,
213 ) -> OSStatus;
214 }
215 unsafe { CMSEncoderCopyEncapsulatedContentType(self, e_content_type_out) }
216 }
217
218 #[doc(alias = "CMSEncoderAddSupportingCerts")]
222 #[inline]
223 pub unsafe fn add_supporting_certs(&self, cert_or_array: &CFType) -> OSStatus {
224 extern "C-unwind" {
225 fn CMSEncoderAddSupportingCerts(
226 cms_encoder: &CMSEncoder,
227 cert_or_array: &CFType,
228 ) -> OSStatus;
229 }
230 unsafe { CMSEncoderAddSupportingCerts(self, cert_or_array) }
231 }
232
233 #[doc(alias = "CMSEncoderCopySupportingCerts")]
237 #[inline]
238 pub unsafe fn copy_supporting_certs(&self, certs_out: NonNull<*const CFArray>) -> OSStatus {
239 extern "C-unwind" {
240 fn CMSEncoderCopySupportingCerts(
241 cms_encoder: &CMSEncoder,
242 certs_out: NonNull<*const CFArray>,
243 ) -> OSStatus;
244 }
245 unsafe { CMSEncoderCopySupportingCerts(self, certs_out) }
246 }
247}
248
249#[repr(transparent)]
252#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
253pub struct CMSSignedAttributes(pub u32);
254bitflags::bitflags! {
255 impl CMSSignedAttributes: u32 {
256 #[doc(alias = "kCMSAttrNone")]
257 const AttrNone = 0x0000;
258 #[doc(alias = "kCMSAttrSmimeCapabilities")]
259 const AttrSmimeCapabilities = 0x0001;
260 #[doc(alias = "kCMSAttrSmimeEncryptionKeyPrefs")]
261 const AttrSmimeEncryptionKeyPrefs = 0x0002;
262 #[doc(alias = "kCMSAttrSmimeMSEncryptionKeyPrefs")]
263 const AttrSmimeMSEncryptionKeyPrefs = 0x0004;
264 #[doc(alias = "kCMSAttrSigningTime")]
265 const AttrSigningTime = 0x0008;
266 #[doc(alias = "kCMSAttrAppleCodesigningHashAgility")]
267 const AttrAppleCodesigningHashAgility = 0x0010;
268 #[doc(alias = "kCMSAttrAppleCodesigningHashAgilityV2")]
269 const AttrAppleCodesigningHashAgilityV2 = 0x0020;
270 #[doc(alias = "kCMSAttrAppleExpirationTime")]
271 const AttrAppleExpirationTime = 0x0040;
272 }
273}
274
275#[cfg(feature = "objc2")]
276unsafe impl Encode for CMSSignedAttributes {
277 const ENCODING: Encoding = u32::ENCODING;
278}
279
280#[cfg(feature = "objc2")]
281unsafe impl RefEncode for CMSSignedAttributes {
282 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
283}
284
285impl CMSEncoder {
286 #[doc(alias = "CMSEncoderAddSignedAttributes")]
287 #[inline]
288 pub unsafe fn add_signed_attributes(&self, signed_attributes: CMSSignedAttributes) -> OSStatus {
289 extern "C-unwind" {
290 fn CMSEncoderAddSignedAttributes(
291 cms_encoder: &CMSEncoder,
292 signed_attributes: CMSSignedAttributes,
293 ) -> OSStatus;
294 }
295 unsafe { CMSEncoderAddSignedAttributes(self, signed_attributes) }
296 }
297}
298
299#[repr(transparent)]
302#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
303pub struct CMSCertificateChainMode(pub u32);
304impl CMSCertificateChainMode {
305 #[doc(alias = "kCMSCertificateNone")]
306 pub const None: Self = Self(0);
307 #[doc(alias = "kCMSCertificateSignerOnly")]
308 pub const SignerOnly: Self = Self(1);
309 #[doc(alias = "kCMSCertificateChain")]
310 pub const Chain: Self = Self(2);
311 #[doc(alias = "kCMSCertificateChainWithRoot")]
312 pub const ChainWithRoot: Self = Self(3);
313 #[doc(alias = "kCMSCertificateChainWithRootOrFail")]
314 pub const ChainWithRootOrFail: Self = Self(4);
315}
316
317#[cfg(feature = "objc2")]
318unsafe impl Encode for CMSCertificateChainMode {
319 const ENCODING: Encoding = u32::ENCODING;
320}
321
322#[cfg(feature = "objc2")]
323unsafe impl RefEncode for CMSCertificateChainMode {
324 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
325}
326
327impl CMSEncoder {
328 #[doc(alias = "CMSEncoderSetCertificateChainMode")]
329 #[inline]
330 pub unsafe fn set_certificate_chain_mode(
331 &self,
332 chain_mode: CMSCertificateChainMode,
333 ) -> OSStatus {
334 extern "C-unwind" {
335 fn CMSEncoderSetCertificateChainMode(
336 cms_encoder: &CMSEncoder,
337 chain_mode: CMSCertificateChainMode,
338 ) -> OSStatus;
339 }
340 unsafe { CMSEncoderSetCertificateChainMode(self, chain_mode) }
341 }
342
343 #[doc(alias = "CMSEncoderGetCertificateChainMode")]
347 #[inline]
348 pub unsafe fn certificate_chain_mode(
349 &self,
350 chain_mode_out: NonNull<CMSCertificateChainMode>,
351 ) -> OSStatus {
352 extern "C-unwind" {
353 fn CMSEncoderGetCertificateChainMode(
354 cms_encoder: &CMSEncoder,
355 chain_mode_out: NonNull<CMSCertificateChainMode>,
356 ) -> OSStatus;
357 }
358 unsafe { CMSEncoderGetCertificateChainMode(self, chain_mode_out) }
359 }
360
361 #[doc(alias = "CMSEncoderUpdateContent")]
365 #[inline]
366 pub unsafe fn update_content(&self, content: NonNull<c_void>, content_len: usize) -> OSStatus {
367 extern "C-unwind" {
368 fn CMSEncoderUpdateContent(
369 cms_encoder: &CMSEncoder,
370 content: NonNull<c_void>,
371 content_len: usize,
372 ) -> OSStatus;
373 }
374 unsafe { CMSEncoderUpdateContent(self, content, content_len) }
375 }
376
377 #[doc(alias = "CMSEncoderCopyEncodedContent")]
381 #[inline]
382 pub unsafe fn copy_encoded_content(
383 &self,
384 encoded_content_out: NonNull<*const CFData>,
385 ) -> OSStatus {
386 extern "C-unwind" {
387 fn CMSEncoderCopyEncodedContent(
388 cms_encoder: &CMSEncoder,
389 encoded_content_out: NonNull<*const CFData>,
390 ) -> OSStatus;
391 }
392 unsafe { CMSEncoderCopyEncodedContent(self, encoded_content_out) }
393 }
394}
395
396#[cfg(feature = "SecAsn1Types")]
404#[deprecated]
405#[inline]
406pub unsafe extern "C-unwind" fn CMSEncode(
407 signers: Option<&CFType>,
408 recipients: Option<&CFType>,
409 e_content_type: *const SecAsn1Oid,
410 detached_content: bool,
411 signed_attributes: CMSSignedAttributes,
412 content: NonNull<c_void>,
413 content_len: usize,
414 encoded_content_out: NonNull<*const CFData>,
415) -> OSStatus {
416 extern "C-unwind" {
417 fn CMSEncode(
418 signers: Option<&CFType>,
419 recipients: Option<&CFType>,
420 e_content_type: *const SecAsn1Oid,
421 detached_content: Boolean,
422 signed_attributes: CMSSignedAttributes,
423 content: NonNull<c_void>,
424 content_len: usize,
425 encoded_content_out: NonNull<*const CFData>,
426 ) -> OSStatus;
427 }
428 unsafe {
429 CMSEncode(
430 signers,
431 recipients,
432 e_content_type,
433 detached_content as _,
434 signed_attributes,
435 content,
436 content_len,
437 encoded_content_out,
438 )
439 }
440}
441
442#[inline]
450pub unsafe extern "C-unwind" fn CMSEncodeContent(
451 signers: Option<&CFType>,
452 recipients: Option<&CFType>,
453 e_content_type_oid: Option<&CFType>,
454 detached_content: bool,
455 signed_attributes: CMSSignedAttributes,
456 content: NonNull<c_void>,
457 content_len: usize,
458 encoded_content_out: *mut *const CFData,
459) -> OSStatus {
460 extern "C-unwind" {
461 fn CMSEncodeContent(
462 signers: Option<&CFType>,
463 recipients: Option<&CFType>,
464 e_content_type_oid: Option<&CFType>,
465 detached_content: Boolean,
466 signed_attributes: CMSSignedAttributes,
467 content: NonNull<c_void>,
468 content_len: usize,
469 encoded_content_out: *mut *const CFData,
470 ) -> OSStatus;
471 }
472 unsafe {
473 CMSEncodeContent(
474 signers,
475 recipients,
476 e_content_type_oid,
477 detached_content as _,
478 signed_attributes,
479 content,
480 content_len,
481 encoded_content_out,
482 )
483 }
484}
485
486impl CMSEncoder {
487 #[doc(alias = "CMSEncoderCopySignerTimestamp")]
491 #[inline]
492 pub unsafe fn copy_signer_timestamp(
493 &self,
494 signer_index: usize,
495 timestamp: NonNull<CFAbsoluteTime>,
496 ) -> OSStatus {
497 extern "C-unwind" {
498 fn CMSEncoderCopySignerTimestamp(
499 cms_encoder: &CMSEncoder,
500 signer_index: usize,
501 timestamp: NonNull<CFAbsoluteTime>,
502 ) -> OSStatus;
503 }
504 unsafe { CMSEncoderCopySignerTimestamp(self, signer_index, timestamp) }
505 }
506
507 #[doc(alias = "CMSEncoderCopySignerTimestampWithPolicy")]
512 #[inline]
513 pub unsafe fn copy_signer_timestamp_with_policy(
514 &self,
515 time_stamp_policy: Option<&CFType>,
516 signer_index: usize,
517 timestamp: NonNull<CFAbsoluteTime>,
518 ) -> OSStatus {
519 extern "C-unwind" {
520 fn CMSEncoderCopySignerTimestampWithPolicy(
521 cms_encoder: &CMSEncoder,
522 time_stamp_policy: Option<&CFType>,
523 signer_index: usize,
524 timestamp: NonNull<CFAbsoluteTime>,
525 ) -> OSStatus;
526 }
527 unsafe {
528 CMSEncoderCopySignerTimestampWithPolicy(
529 self,
530 time_stamp_policy,
531 signer_index,
532 timestamp,
533 )
534 }
535 }
536}
537
538extern "C-unwind" {
539 #[deprecated = "renamed to `CMSEncoder::create`"]
540 pub fn CMSEncoderCreate(cms_encoder_out: NonNull<*mut CMSEncoder>) -> OSStatus;
541}
542
543extern "C-unwind" {
544 #[deprecated = "renamed to `CMSEncoder::set_signer_algorithm`"]
545 pub fn CMSEncoderSetSignerAlgorithm(
546 cms_encoder: &CMSEncoder,
547 digest_algorithm: &CFString,
548 ) -> OSStatus;
549}
550
551extern "C-unwind" {
552 #[deprecated = "renamed to `CMSEncoder::add_signers`"]
553 pub fn CMSEncoderAddSigners(cms_encoder: &CMSEncoder, signer_or_array: &CFType) -> OSStatus;
554}
555
556extern "C-unwind" {
557 #[deprecated = "renamed to `CMSEncoder::copy_signers`"]
558 pub fn CMSEncoderCopySigners(
559 cms_encoder: &CMSEncoder,
560 signers_out: NonNull<*const CFArray>,
561 ) -> OSStatus;
562}
563
564extern "C-unwind" {
565 #[deprecated = "renamed to `CMSEncoder::add_recipients`"]
566 pub fn CMSEncoderAddRecipients(
567 cms_encoder: &CMSEncoder,
568 recipient_or_array: &CFType,
569 ) -> OSStatus;
570}
571
572extern "C-unwind" {
573 #[deprecated = "renamed to `CMSEncoder::copy_recipients`"]
574 pub fn CMSEncoderCopyRecipients(
575 cms_encoder: &CMSEncoder,
576 recipients_out: NonNull<*const CFArray>,
577 ) -> OSStatus;
578}
579
580#[deprecated = "renamed to `CMSEncoder::set_has_detached_content`"]
581#[inline]
582pub unsafe extern "C-unwind" fn CMSEncoderSetHasDetachedContent(
583 cms_encoder: &CMSEncoder,
584 detached_content: bool,
585) -> OSStatus {
586 extern "C-unwind" {
587 fn CMSEncoderSetHasDetachedContent(
588 cms_encoder: &CMSEncoder,
589 detached_content: Boolean,
590 ) -> OSStatus;
591 }
592 unsafe { CMSEncoderSetHasDetachedContent(cms_encoder, detached_content as _) }
593}
594
595extern "C-unwind" {
596 #[deprecated = "renamed to `CMSEncoder::has_detached_content`"]
597 pub fn CMSEncoderGetHasDetachedContent(
598 cms_encoder: &CMSEncoder,
599 detached_content_out: NonNull<Boolean>,
600 ) -> OSStatus;
601}
602
603extern "C-unwind" {
604 #[cfg(feature = "SecAsn1Types")]
605 #[deprecated = "renamed to `CMSEncoder::set_encapsulated_content_type`"]
606 pub fn CMSEncoderSetEncapsulatedContentType(
607 cms_encoder: &CMSEncoder,
608 e_content_type: NonNull<SecAsn1Oid>,
609 ) -> OSStatus;
610}
611
612extern "C-unwind" {
613 #[deprecated = "renamed to `CMSEncoder::set_encapsulated_content_type_oid`"]
614 pub fn CMSEncoderSetEncapsulatedContentTypeOID(
615 cms_encoder: &CMSEncoder,
616 e_content_type_oid: &CFType,
617 ) -> OSStatus;
618}
619
620extern "C-unwind" {
621 #[deprecated = "renamed to `CMSEncoder::copy_encapsulated_content_type`"]
622 pub fn CMSEncoderCopyEncapsulatedContentType(
623 cms_encoder: &CMSEncoder,
624 e_content_type_out: NonNull<*const CFData>,
625 ) -> OSStatus;
626}
627
628extern "C-unwind" {
629 #[deprecated = "renamed to `CMSEncoder::add_supporting_certs`"]
630 pub fn CMSEncoderAddSupportingCerts(
631 cms_encoder: &CMSEncoder,
632 cert_or_array: &CFType,
633 ) -> OSStatus;
634}
635
636extern "C-unwind" {
637 #[deprecated = "renamed to `CMSEncoder::copy_supporting_certs`"]
638 pub fn CMSEncoderCopySupportingCerts(
639 cms_encoder: &CMSEncoder,
640 certs_out: NonNull<*const CFArray>,
641 ) -> OSStatus;
642}
643
644extern "C-unwind" {
645 #[deprecated = "renamed to `CMSEncoder::add_signed_attributes`"]
646 pub fn CMSEncoderAddSignedAttributes(
647 cms_encoder: &CMSEncoder,
648 signed_attributes: CMSSignedAttributes,
649 ) -> OSStatus;
650}
651
652extern "C-unwind" {
653 #[deprecated = "renamed to `CMSEncoder::set_certificate_chain_mode`"]
654 pub fn CMSEncoderSetCertificateChainMode(
655 cms_encoder: &CMSEncoder,
656 chain_mode: CMSCertificateChainMode,
657 ) -> OSStatus;
658}
659
660extern "C-unwind" {
661 #[deprecated = "renamed to `CMSEncoder::certificate_chain_mode`"]
662 pub fn CMSEncoderGetCertificateChainMode(
663 cms_encoder: &CMSEncoder,
664 chain_mode_out: NonNull<CMSCertificateChainMode>,
665 ) -> OSStatus;
666}
667
668extern "C-unwind" {
669 #[deprecated = "renamed to `CMSEncoder::update_content`"]
670 pub fn CMSEncoderUpdateContent(
671 cms_encoder: &CMSEncoder,
672 content: NonNull<c_void>,
673 content_len: usize,
674 ) -> OSStatus;
675}
676
677extern "C-unwind" {
678 #[deprecated = "renamed to `CMSEncoder::copy_encoded_content`"]
679 pub fn CMSEncoderCopyEncodedContent(
680 cms_encoder: &CMSEncoder,
681 encoded_content_out: NonNull<*const CFData>,
682 ) -> OSStatus;
683}
684
685extern "C-unwind" {
686 #[deprecated = "renamed to `CMSEncoder::copy_signer_timestamp`"]
687 pub fn CMSEncoderCopySignerTimestamp(
688 cms_encoder: &CMSEncoder,
689 signer_index: usize,
690 timestamp: NonNull<CFAbsoluteTime>,
691 ) -> OSStatus;
692}
693
694extern "C-unwind" {
695 #[deprecated = "renamed to `CMSEncoder::copy_signer_timestamp_with_policy`"]
696 pub fn CMSEncoderCopySignerTimestampWithPolicy(
697 cms_encoder: &CMSEncoder,
698 time_stamp_policy: Option<&CFType>,
699 signer_index: usize,
700 timestamp: NonNull<CFAbsoluteTime>,
701 ) -> OSStatus;
702}