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