1 //! OSX specific extensions.
2 
3 pub mod access;
4 pub mod certificate;
5 pub mod certificate_oids;
6 pub mod code_signing;
7 pub mod digest_transform;
8 pub mod encrypt_transform;
9 pub mod identity;
10 pub mod import_export;
11 pub mod item;
12 pub mod key;
13 pub mod keychain;
14 pub mod keychain_item;
15 pub mod passwords;
16 pub mod secure_transport;
17 pub mod transform;
18 
19 #[cfg(test)]
20 pub mod test {
21     use crate::identity::SecIdentity;
22     use crate::item::{ItemClass, ItemSearchOptions, Reference, SearchResult};
23     use crate::os::macos::item::ItemSearchOptionsExt;
24     use crate::os::macos::keychain::SecKeychain;
25     use std::fs::File;
26     use std::io::prelude::*;
27     use std::path::Path;
28 
identity(dir: &Path) -> SecIdentity29     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 
keychain(dir: &Path) -> SecKeychain42     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 }
53