apple_security_framework/
lib.rs

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