Skip to content

Commit 50ed298

Browse files
SergejJureckokornelski
authored andcommitted
additional exports and wrappers (#73)
* missing kSecAttrKeySizeInBits and kSecAttrKeyTypeRSA is in ios * SecKeyCopyExternalRepresentation is available on ios as well
1 parent 3a65603 commit 50ed298

File tree

7 files changed

+28
-5
lines changed

7 files changed

+28
-5
lines changed

security-framework-sys/src/item.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ extern "C" {
2222
pub static kSecAttrKeyType: CFStringRef;
2323
pub static kSecAttrLabel: CFStringRef;
2424

25-
#[cfg(target_os = "macos")]
25+
pub static kSecAttrKeySizeInBits: CFStringRef;
26+
27+
pub static kSecAttrKeyTypeECSECPrimeRandom: CFStringRef;
2628
pub static kSecAttrKeyTypeRSA: CFStringRef;
2729
#[cfg(target_os = "macos")]
2830
pub static kSecAttrKeyTypeDSA: CFStringRef;

security-framework-sys/src/key.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use core_foundation_sys::base::CFTypeID;
22
#[cfg(target_os = "macos")]
33
use core_foundation_sys::data::CFDataRef;
4-
#[cfg(target_os = "macos")]
54
use core_foundation_sys::dictionary::CFDictionaryRef;
65
#[cfg(target_os = "macos")]
76
use core_foundation_sys::error::CFErrorRef;
@@ -18,6 +17,8 @@ extern "C" {
1817
error: *mut CFErrorRef,
1918
) -> SecKeyRef;
2019

21-
#[cfg(feature = "OSX_10_12")]
20+
#[cfg(any(feature = "OSX_10_12", target_os = "ios"))]
2221
pub fn SecKeyCopyExternalRepresentation(key: SecKeyRef, error: *mut CFErrorRef) -> CFDataRef;
22+
#[cfg(any(feature = "OSX_10_12", target_os = "ios"))]
23+
pub fn SecKeyCopyAttributes(key: SecKeyRef) -> CFDictionaryRef;
2324
}

security-framework-sys/src/policy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ use base::SecPolicyRef;
66
extern "C" {
77
pub fn SecPolicyCreateSSL(server: Boolean, hostname: CFStringRef) -> SecPolicyRef;
88
pub fn SecPolicyGetTypeID() -> CFTypeID;
9+
pub fn SecPolicyCreateBasicX509() -> SecPolicyRef;
910
}

security-framework-sys/src/trust.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use base::SecCertificateRef;
2+
use base::SecKeyRef;
23
use core_foundation_sys::array::CFArrayRef;
34
use core_foundation_sys::base::{Boolean, CFIndex, CFTypeID, CFTypeRef, OSStatus};
4-
55
pub type SecTrustResultType = u32;
66

77
pub const kSecTrustResultInvalid: SecTrustResultType = 0;
@@ -35,4 +35,5 @@ extern "C" {
3535
trust: *mut SecTrustRef,
3636
) -> OSStatus;
3737
pub fn SecTrustSetPolicies(trust: SecTrustRef, policies: CFTypeRef) -> OSStatus;
38+
pub fn SecTrustCopyPublicKey(trust: SecTrustRef) -> SecKeyRef;
3839
}

security-framework/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ unsafe fn get_item(item: CFTypeRef) -> SearchResult {
226226
return SearchResult::Data(buf);
227227
}
228228

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

security-framework/src/policy.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ impl SecPolicy {
4040
SecPolicy::wrap_under_create_rule(policy)
4141
}
4242
}
43+
44+
/// Returns a policy object for the default X.509 policy.
45+
pub fn create_x509() -> SecPolicy {
46+
unsafe {
47+
let policy = SecPolicyCreateBasicX509();
48+
SecPolicy::wrap_under_create_rule(policy)
49+
}
50+
}
4351
}
4452

4553
#[cfg(test)]

security-framework/src/trust.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::ptr;
1010
use base::Result;
1111
use certificate::SecCertificate;
1212
use cvt;
13+
use key::SecKey;
1314
use policy::SecPolicy;
1415

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

107+
/// Returns the public key for a leaf certificate after it has been evaluated.
108+
pub fn copy_public_key(&mut self) -> Result<SecKey> {
109+
unsafe {
110+
Ok(SecKey::wrap_under_create_rule(SecTrustCopyPublicKey(
111+
self.0,
112+
)))
113+
}
114+
}
115+
106116
/// Evaluates trust.
107117
// FIXME should return &mut self
108118
pub fn evaluate(&self) -> Result<TrustResult> {

0 commit comments

Comments
 (0)