Skip to main content

security_framework/
lib.rs

1#![cfg(target_vendor = "apple")]
2
3//! Wrappers around the macOS Security Framework.
4#![warn(missing_docs)]
5#![allow(non_upper_case_globals)]
6#![allow(clippy::manual_non_exhaustive)] // MSRV
7#![allow(clippy::bad_bit_mask)] // bitflags
8#![allow(clippy::struct_excessive_bools)]
9#![allow(clippy::unreadable_literal)]
10#![allow(clippy::ignore_without_reason)]
11
12use core_foundation_sys::base::OSStatus;
13use security_framework_sys::base::errSecSuccess;
14
15use crate::base::{Error, Result};
16
17#[cfg(test)]
18macro_rules! p {
19    ($e:expr) => {
20        match $e {
21            Ok(s) => s,
22            Err(e) => panic!("{:?}", e),
23        }
24    };
25}
26
27pub mod access_control;
28#[cfg(target_os = "macos")]
29pub mod authorization;
30pub mod base;
31pub mod certificate;
32pub mod cipher_suite;
33#[cfg(target_os = "macos")]
34pub mod cms;
35pub mod identity;
36pub mod import_export;
37pub mod item;
38pub mod key;
39pub mod os;
40pub mod passwords;
41#[doc(hidden)]
42pub mod passwords_options;
43pub mod policy;
44pub mod random;
45pub mod secure_transport;
46pub mod trust;
47#[cfg(target_os = "macos")]
48pub mod trust_settings;
49
50#[inline(always)]
51fn cvt(err: OSStatus) -> Result<()> {
52    match err {
53        errSecSuccess => Ok(()),
54        err => Err(Error::from_code(err)),
55    }
56}
57
58#[cfg(test)]
59mod test {
60    use crate::certificate::SecCertificate;
61
62    /// Returns the server certificate (for certificate parsing/identity tests)
63    pub fn certificate() -> SecCertificate {
64        let certificate = include_bytes!("../test/server.der");
65        p!(SecCertificate::from_der(certificate))
66    }
67
68    /// Returns the CA certificate (trust anchor for TLS verification)
69    pub fn ca_certificate() -> SecCertificate {
70        let certificate = include_bytes!("../test/ca.der");
71        p!(SecCertificate::from_der(certificate))
72    }
73}