1 //! Wrappers around the OSX Security Framework.
2 
3 #![warn(missing_docs)]
4 #![allow(non_upper_case_globals)]
5 
6 extern crate security_framework_sys;
7 #[macro_use]
8 extern crate core_foundation;
9 extern crate core_foundation_sys;
10 extern crate libc;
11 
12 #[cfg(test)]
13 extern crate hex;
14 #[cfg(test)]
15 extern crate tempdir;
16 
17 use core_foundation_sys::base::OSStatus;
18 use security_framework_sys::base::errSecSuccess;
19 
20 use crate::base::{Error, Result};
21 #[cfg(target_os = "macos")]
22 use crate::os::macos::access::SecAccess;
23 #[cfg(target_os = "macos")]
24 use crate::os::macos::keychain::SecKeychain;
25 
26 #[cfg(test)]
27 macro_rules! p {
28     ($e:expr) => {
29         match $e {
30             Ok(s) => s,
31             Err(e) => panic!("{:?}", e),
32         }
33     };
34 }
35 
36 #[cfg(all(not(feature = "OSX_10_13"), feature = "alpn"))]
37 #[macro_use]
38 mod dlsym;
39 
40 pub mod base;
41 pub mod certificate;
42 pub mod cipher_suite;
43 pub mod identity;
44 pub mod import_export;
45 pub mod item;
46 pub mod key;
47 pub mod os;
48 pub mod policy;
49 pub mod random;
50 pub mod secure_transport;
51 pub mod trust;
52 #[cfg(target_os = "macos")]
53 pub mod trust_settings;
54 
55 #[cfg(target_os = "macos")]
56 trait Pkcs12ImportOptionsInternals {
keychain(&mut self, keychain: SecKeychain) -> &mut Self57     fn keychain(&mut self, keychain: SecKeychain) -> &mut Self;
access(&mut self, access: SecAccess) -> &mut Self58     fn access(&mut self, access: SecAccess) -> &mut Self;
59 }
60 
61 #[cfg(target_os = "macos")]
62 trait ItemSearchOptionsInternals {
keychains(&mut self, keychains: &[SecKeychain]) -> &mut Self63     fn keychains(&mut self, keychains: &[SecKeychain]) -> &mut Self;
64 }
65 
66 trait AsInner {
67     type Inner;
as_inner(&self) -> Self::Inner68     fn as_inner(&self) -> Self::Inner;
69 }
70 
cvt(err: OSStatus) -> Result<()>71 fn cvt(err: OSStatus) -> Result<()> {
72     match err {
73         errSecSuccess => Ok(()),
74         err => Err(Error::from_code(err)),
75     }
76 }
77 
78 #[cfg(test)]
79 mod test {
80     use crate::certificate::SecCertificate;
81 
certificate() -> SecCertificate82     pub fn certificate() -> SecCertificate {
83         let certificate = include_bytes!("../test/server.der");
84         p!(SecCertificate::from_der(certificate))
85     }
86 }
87