1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#[doc(inline)]
pub use super::constants::KeyType;
use std::iter::FromIterator;
pub type KeyOption = (String, Option<String>);
pub type KeyOptions = Vec<KeyOption>;
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct PublicKey {
pub key_type: KeyType,
pub encoded_key: String,
}
impl PublicKey {
pub fn new(key_type: KeyType, encoded_key: String) -> Self {
Self {
key_type,
encoded_key,
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct KeyAuthorization {
pub options: KeyOptions,
pub key: PublicKey,
pub comments: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum KeysFileLine {
Comment(String),
Key(KeyAuthorization),
}
#[derive(Debug, Default, Clone)]
pub struct KeysFile {
pub lines: Vec<KeysFileLine>,
}
impl FromIterator<KeysFileLine> for KeysFile {
fn from_iter<I: IntoIterator<Item = KeysFileLine>>(i: I) -> Self {
Self {
lines: i.into_iter().collect::<Vec<_>>(),
}
}
}
impl IntoIterator for KeysFile {
type Item = KeysFileLine;
type IntoIter = ::std::vec::IntoIter<KeysFileLine>;
fn into_iter(self) -> Self::IntoIter {
self.lines.into_iter()
}
}