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