Skip to content

additional exports and wrappers #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion security-framework-sys/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ extern "C" {
pub static kSecAttrKeyType: CFStringRef;
pub static kSecAttrLabel: CFStringRef;

#[cfg(target_os = "macos")]
pub static kSecAttrKeySizeInBits: CFStringRef;

pub static kSecAttrKeyTypeECSECPrimeRandom: CFStringRef;
pub static kSecAttrKeyTypeRSA: CFStringRef;
#[cfg(target_os = "macos")]
pub static kSecAttrKeyTypeDSA: CFStringRef;
Expand Down
5 changes: 3 additions & 2 deletions security-framework-sys/src/key.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core_foundation_sys::base::CFTypeID;
#[cfg(target_os = "macos")]
use core_foundation_sys::data::CFDataRef;
#[cfg(target_os = "macos")]
use core_foundation_sys::dictionary::CFDictionaryRef;
#[cfg(target_os = "macos")]
use core_foundation_sys::error::CFErrorRef;
Expand All @@ -18,6 +17,8 @@ extern "C" {
error: *mut CFErrorRef,
) -> SecKeyRef;

#[cfg(feature = "OSX_10_12")]
#[cfg(any(feature = "OSX_10_12", target_os = "ios"))]
pub fn SecKeyCopyExternalRepresentation(key: SecKeyRef, error: *mut CFErrorRef) -> CFDataRef;
#[cfg(any(feature = "OSX_10_12", target_os = "ios"))]
pub fn SecKeyCopyAttributes(key: SecKeyRef) -> CFDictionaryRef;
}
1 change: 1 addition & 0 deletions security-framework-sys/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ use base::SecPolicyRef;
extern "C" {
pub fn SecPolicyCreateSSL(server: Boolean, hostname: CFStringRef) -> SecPolicyRef;
pub fn SecPolicyGetTypeID() -> CFTypeID;
pub fn SecPolicyCreateBasicX509() -> SecPolicyRef;
}
3 changes: 2 additions & 1 deletion security-framework-sys/src/trust.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use base::SecCertificateRef;
use base::SecKeyRef;
use core_foundation_sys::array::CFArrayRef;
use core_foundation_sys::base::{Boolean, CFIndex, CFTypeID, CFTypeRef, OSStatus};

pub type SecTrustResultType = u32;

pub const kSecTrustResultInvalid: SecTrustResultType = 0;
Expand Down Expand Up @@ -35,4 +35,5 @@ extern "C" {
trust: *mut SecTrustRef,
) -> OSStatus;
pub fn SecTrustSetPolicies(trust: SecTrustRef, policies: CFTypeRef) -> OSStatus;
pub fn SecTrustCopyPublicKey(trust: SecTrustRef) -> SecKeyRef;
}
2 changes: 1 addition & 1 deletion security-framework/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ unsafe fn get_item(item: CFTypeRef) -> SearchResult {
return SearchResult::Data(buf);
}

if type_id == CFDictionary::type_id() {
if type_id == CFDictionary::<*const u8, *const u8>::type_id() {
return SearchResult::Dict(CFDictionary::wrap_under_get_rule(item as *mut _));
}

Expand Down
8 changes: 8 additions & 0 deletions security-framework/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ impl SecPolicy {
SecPolicy::wrap_under_create_rule(policy)
}
}

/// Returns a policy object for the default X.509 policy.
pub fn create_x509() -> SecPolicy {
unsafe {
let policy = SecPolicyCreateBasicX509();
SecPolicy::wrap_under_create_rule(policy)
}
}
}

#[cfg(test)]
Expand Down
10 changes: 10 additions & 0 deletions security-framework/src/trust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::ptr;
use base::Result;
use certificate::SecCertificate;
use cvt;
use key::SecKey;
use policy::SecPolicy;

/// The result of trust evaluation.
Expand Down Expand Up @@ -103,6 +104,15 @@ impl SecTrust {
unsafe { cvt(SecTrustSetPolicies(self.0, policy.as_CFTypeRef())) }
}

/// Returns the public key for a leaf certificate after it has been evaluated.
pub fn copy_public_key(&mut self) -> Result<SecKey> {
unsafe {
Ok(SecKey::wrap_under_create_rule(SecTrustCopyPublicKey(
self.0,
)))
}
}

/// Evaluates trust.
// FIXME should return &mut self
pub fn evaluate(&self) -> Result<TrustResult> {
Expand Down