apple_security_framework/os/macos/
mod.rs

1//! OSX specific extensions.
2
3pub mod access;
4pub mod certificate;
5pub mod certificate_oids;
6pub mod code_signing;
7pub mod digest_transform;
8pub mod encrypt_transform;
9pub mod identity;
10pub mod import_export;
11pub mod item;
12pub mod key;
13pub mod keychain;
14pub mod keychain_item;
15pub mod passwords;
16pub mod secure_transport;
17pub mod transform;
18
19#[cfg(test)]
20pub mod test {
21    use std::{fs::File, io::prelude::*, path::Path};
22
23    use crate::{
24        identity::SecIdentity,
25        item::{ItemClass, ItemSearchOptions, Reference, SearchResult},
26        os::macos::{item::ItemSearchOptionsExt, keychain::SecKeychain},
27    };
28
29    pub fn identity(dir: &Path) -> SecIdentity {
30        // FIXME https://github.com/rust-lang/rust/issues/30018
31        let keychain = keychain(dir);
32        let mut items = p!(ItemSearchOptions::new()
33            .class(ItemClass::identity())
34            .keychains(&[keychain])
35            .search());
36        match items.pop().unwrap() {
37            SearchResult::Ref(Reference::Identity(identity)) => identity,
38            _ => panic!("expected identity"),
39        }
40    }
41
42    pub fn keychain(dir: &Path) -> SecKeychain {
43        let path = dir.join("server.keychain");
44        let mut file = p!(File::create(&path));
45        p!(file.write_all(include_bytes!("../../../test/server.keychain")));
46        drop(file);
47
48        let mut keychain = p!(SecKeychain::open(&path));
49        p!(keychain.unlock(Some("password123")));
50        keychain
51    }
52}