diff --git a/cidre/src/sec.rs b/cidre/src/sec.rs index 096c94ea..fbccda61 100644 --- a/cidre/src/sec.rs +++ b/cidre/src/sec.rs @@ -1,2 +1,4 @@ mod base; pub use base::*; + +pub mod certificate; diff --git a/cidre/src/sec/base.rs b/cidre/src/sec/base.rs index 526a68e6..a0cb576d 100644 --- a/cidre/src/sec/base.rs +++ b/cidre/src/sec/base.rs @@ -49,7 +49,7 @@ pub type KeychainAttrType = os::Type; #[doc(alias = "SecKeychainAttribute")] #[cfg(target_os = "macos")] #[repr(C)] -pub struct KeychainAttribute { +pub struct KeychainAttr { pub tag: KeychainAttrType, pub len: u32, pub data: *mut std::ffi::c_void, @@ -58,9 +58,9 @@ pub struct KeychainAttribute { #[doc(alias = "SecKeychainAttributeList")] #[cfg(target_os = "macos")] #[repr(C)] -pub struct KeychainAttributeList { +pub struct KeychainAttrList { pub count: u32, - pub attr: *mut KeychainAttribute, + pub attr: *mut KeychainAttr, } pub type KeychainStatus = u32; @@ -91,7 +91,7 @@ define_cf_type!( #[doc(alias = "SecKeychainAttributeInfo")] #[repr(C)] -pub struct KeychainAttributeInfo { +pub struct KeychainAttrInfo { pub count: u32, pub tag: *mut u32, pub format: *mut u32, diff --git a/cidre/src/sec/certificate.rs b/cidre/src/sec/certificate.rs new file mode 100644 index 00000000..300fdb82 --- /dev/null +++ b/cidre/src/sec/certificate.rs @@ -0,0 +1,90 @@ +use crate::{arc, cf, os, sec}; + +impl sec::Cert { + #[doc(alias = "SecCertificateGetTypeID")] + pub fn get_type_id() -> cf::TypeId { + unsafe { SecCertificateGetTypeID() } + } + + #[doc(alias = "SecCertificateCreateWithData")] + pub fn with_data_in( + data: &cf::Data, + allocator: Option<&cf::Allocator>, + ) -> Option> { + unsafe { SecCertificateCreateWithData(allocator, data) } + } + + #[doc(alias = "SecCertificateCreateWithData")] + pub fn with_data(data: &cf::Data) -> Option> { + unsafe { SecCertificateCreateWithData(None, data) } + } + + #[doc(alias = "SecCertificateCopyData")] + pub fn data(&self) -> arc::R { + unsafe { SecCertificateCopyData(self) } + } + + /// Return a simple string which hopefully represents a human + /// understandable summary. + #[doc(alias = "SecCertificateCopySubjectSummary")] + pub fn subject_summary(&self) -> Option> { + unsafe { SecCertificateCopySubjectSummary(self) } + } + + #[doc(alias = "SecCertificateCopyCommonName")] + pub fn common_name(&self) -> os::Result> { + let mut res = None; + unsafe { SecCertificateCopyCommonName(self, &mut res).to_result_unchecked(res) } + } + + #[doc(alias = "SecCertificateCopyEmailAddresses")] + pub fn emails(&self) -> os::Result>> { + let mut res = None; + unsafe { SecCertificateCopyEmailAddresses(self, &mut res).to_result_unchecked(res) } + } + + #[doc(alias = "SecCertificateCopyNormalizedIssuerSequence")] + pub fn normalized_issuer_sequence(&self) -> Option> { + unsafe { SecCertificateCopyNormalizedIssuerSequence(self) } + } + + #[doc(alias = "SecCertificateCopyNormalizedSubjectSequence")] + pub fn normalized_subject_sequence(&self) -> Option> { + unsafe { SecCertificateCopyNormalizedSubjectSequence(self) } + } + + #[doc(alias = "SecCertificateCopyKey")] + pub fn key(&self) -> Option> { + unsafe { SecCertificateCopyKey(self) } + } +} + +#[link(name = "Security", kind = "framework")] +extern "C-unwind" { + fn SecCertificateGetTypeID() -> cf::TypeId; + + fn SecCertificateCreateWithData( + allocator: Option<&cf::Allocator>, + data: &cf::Data, + ) -> Option>; + + fn SecCertificateCopyData(cert: &sec::Cert) -> arc::R; + + fn SecCertificateCopySubjectSummary(cert: &sec::Cert) -> Option>; + + fn SecCertificateCopyCommonName( + cert: &sec::Cert, + common_name: &mut Option>, + ) -> os::Status; + + fn SecCertificateCopyEmailAddresses( + cert: &sec::Cert, + email_addresses: &mut Option>>, + ) -> os::Status; + + fn SecCertificateCopyNormalizedIssuerSequence(cert: &sec::Cert) -> Option>; + + fn SecCertificateCopyNormalizedSubjectSequence(cert: &sec::Cert) -> Option>; + + fn SecCertificateCopyKey(cert: &sec::Cert) -> Option>; +}