apple_security/
lib.rs

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]
7extern crate core_foundation;
8
9use core_foundation_sys::base::OSStatus;
10use apple_security_sys::base::errSecSuccess;
11
12use crate::base::{Error, Result};
13#[cfg(target_os = "macos")]
14use crate::os::macos::access::SecAccess;
15#[cfg(target_os = "macos")]
16use crate::os::macos::keychain::SecKeychain;
17
18#[cfg(test)]
19macro_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]
30mod dlsym;
31
32pub mod access_control;
33#[cfg(target_os = "macos")]
34pub mod authorization;
35pub mod base;
36#[cfg(any(target_os = "macos", target_os = "ios"))]
37pub mod certificate;
38pub mod cipher_suite;
39#[cfg(any(target_os = "macos", target_os = "ios"))]
40pub mod identity;
41#[cfg(any(target_os = "macos", target_os = "ios"))]
42pub mod import_export;
43#[cfg(any(target_os = "macos", target_os = "ios"))]
44pub mod item;
45#[cfg(any(target_os = "macos", target_os = "ios"))]
46pub mod key;
47pub mod os;
48pub mod passwords;
49pub mod passwords_options;
50#[cfg(any(target_os = "macos", target_os = "ios"))]
51pub mod policy;
52pub mod random;
53#[cfg(any(target_os = "macos", target_os = "ios"))]
54pub mod secure_transport;
55#[cfg(any(target_os = "macos", target_os = "ios"))]
56pub mod trust;
57#[cfg(target_os = "macos")]
58pub mod trust_settings;
59
60#[cfg(target_os = "macos")]
61trait Pkcs12ImportOptionsInternals {
62    fn keychain(&mut self, keychain: SecKeychain) -> &mut Self;
63    fn access(&mut self, access: SecAccess) -> &mut Self;
64}
65
66#[cfg(target_os = "macos")]
67trait ItemSearchOptionsInternals {
68    fn keychains(&mut self, keychains: &[SecKeychain]) -> &mut Self;
69}
70
71trait AsInner {
72    type Inner;
73    fn as_inner(&self) -> Self::Inner;
74}
75
76#[inline(always)]
77fn cvt(err: OSStatus) -> Result<()> {
78    match err {
79        errSecSuccess => Ok(()),
80        err => Err(Error::from_code(err)),
81    }
82}
83
84#[cfg(test)]
85mod test {
86    use crate::certificate::SecCertificate;
87
88    pub fn certificate() -> SecCertificate {
89        let certificate = include_bytes!("../test/server.der");
90        p!(SecCertificate::from_der(certificate))
91    }
92}