procfs/
keyring.rs

1use super::{Current, ProcResult};
2use procfs_core::keyring::*;
3use std::collections::HashMap;
4
5impl Current for Keys {
6    const PATH: &'static str = "/proc/keys";
7}
8
9/// Returns a list of the keys for which the reading thread has **view** permission, providing
10/// various information about each key.
11pub fn keys() -> ProcResult<Vec<Key>> {
12    Keys::current().map(|k| k.0)
13}
14
15impl Current for KeyUsers {
16    const PATH: &'static str = "/proc/key-users";
17}
18
19/// Get various information for each user ID that has at least one key on the system.
20pub fn key_users() -> ProcResult<HashMap<u32, KeyUser>> {
21    KeyUsers::current().map(|k| k.0)
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn test_keys() {
30        for key in keys().unwrap() {
31            println!("{:#?}", key);
32        }
33    }
34
35    #[test]
36    fn test_key_users() {
37        for (_user, data) in key_users().unwrap() {
38            println!("{:#?}", data);
39        }
40    }
41}