Skip to content

Commit

Permalink
sec::Cert
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 20, 2024
1 parent 782dbb6 commit 25cd53a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cidre/src/sec.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
mod base;
pub use base::*;

pub mod certificate;
8 changes: 4 additions & 4 deletions cidre/src/sec/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
90 changes: 90 additions & 0 deletions cidre/src/sec/certificate.rs
Original file line number Diff line number Diff line change
@@ -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<arc::R<Self>> {
unsafe { SecCertificateCreateWithData(allocator, data) }
}

#[doc(alias = "SecCertificateCreateWithData")]
pub fn with_data(data: &cf::Data) -> Option<arc::R<Self>> {
unsafe { SecCertificateCreateWithData(None, data) }
}

#[doc(alias = "SecCertificateCopyData")]
pub fn data(&self) -> arc::R<cf::Data> {
unsafe { SecCertificateCopyData(self) }
}

/// Return a simple string which hopefully represents a human
/// understandable summary.
#[doc(alias = "SecCertificateCopySubjectSummary")]
pub fn subject_summary(&self) -> Option<arc::R<cf::String>> {
unsafe { SecCertificateCopySubjectSummary(self) }
}

#[doc(alias = "SecCertificateCopyCommonName")]
pub fn common_name(&self) -> os::Result<arc::R<cf::String>> {
let mut res = None;
unsafe { SecCertificateCopyCommonName(self, &mut res).to_result_unchecked(res) }
}

#[doc(alias = "SecCertificateCopyEmailAddresses")]
pub fn emails(&self) -> os::Result<arc::R<cf::ArrayOf<cf::String>>> {
let mut res = None;
unsafe { SecCertificateCopyEmailAddresses(self, &mut res).to_result_unchecked(res) }
}

#[doc(alias = "SecCertificateCopyNormalizedIssuerSequence")]
pub fn normalized_issuer_sequence(&self) -> Option<arc::R<cf::Data>> {
unsafe { SecCertificateCopyNormalizedIssuerSequence(self) }
}

#[doc(alias = "SecCertificateCopyNormalizedSubjectSequence")]
pub fn normalized_subject_sequence(&self) -> Option<arc::R<cf::Data>> {
unsafe { SecCertificateCopyNormalizedSubjectSequence(self) }
}

#[doc(alias = "SecCertificateCopyKey")]
pub fn key(&self) -> Option<arc::R<sec::Key>> {
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<arc::R<sec::Cert>>;

fn SecCertificateCopyData(cert: &sec::Cert) -> arc::R<cf::Data>;

fn SecCertificateCopySubjectSummary(cert: &sec::Cert) -> Option<arc::R<cf::String>>;

fn SecCertificateCopyCommonName(
cert: &sec::Cert,
common_name: &mut Option<arc::R<cf::String>>,
) -> os::Status;

fn SecCertificateCopyEmailAddresses(
cert: &sec::Cert,
email_addresses: &mut Option<arc::R<cf::ArrayOf<cf::String>>>,
) -> os::Status;

fn SecCertificateCopyNormalizedIssuerSequence(cert: &sec::Cert) -> Option<arc::R<cf::Data>>;

fn SecCertificateCopyNormalizedSubjectSequence(cert: &sec::Cert) -> Option<arc::R<cf::Data>>;

fn SecCertificateCopyKey(cert: &sec::Cert) -> Option<arc::R<sec::Key>>;
}

0 comments on commit 25cd53a

Please # to comment.