Debian Codegraph @

src/cert.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#;
6
7 use superrust-analyzer cargo sshkeys 0.3.4 crate/::errorrust-analyzer cargo sshkeys 0.3.4 error/::{Errorrust-analyzer cargo sshkeys 0.3.4 error/Error#, ErrorKindrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#, Resultrust-analyzer cargo sshkeys 0.3.4 error/Result#};
8 use superrust-analyzer cargo sshkeys 0.3.4 crate/::keytyperust-analyzer cargo sshkeys 0.3.4 keytype/::KeyTyperust-analyzer cargo sshkeys 0.3.4 keytype/KeyType#;
9 use superrust-analyzer cargo sshkeys 0.3.4 crate/::pubkeyrust-analyzer cargo sshkeys 0.3.4 pubkey/::PublicKeyrust-analyzer cargo sshkeys 0.3.4 pubkey/PublicKey#;
10 use superrust-analyzer cargo sshkeys 0.3.4 crate/::readerrust-analyzer cargo sshkeys 0.3.4 reader/::Readerrust-analyzer cargo sshkeys 0.3.4 reader/Reader#;
11
12 use base64rust-analyzer cargo base64 0.22.1 crate/;
13 use base64rust-analyzer cargo base64 0.22.1 crate/::Enginerust-analyzer cargo base64 0.22.1 engine/Engine#;
14
15 /// Represents the different types a certificate can be.
16 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
17 pub enum CertTyperust-analyzer cargo sshkeys 0.3.4 cert/CertType# {
18 /// Represents a user certificate.
19 Userrust-analyzer cargo sshkeys 0.3.4 cert/CertType#User#,
20
21 /// Represents a host certificate.
22 Hostrust-analyzer cargo sshkeys 0.3.4 cert/CertType#Host#,
23 }
24
25 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for CertTyperust-analyzer cargo sshkeys 0.3.4 cert/CertType# {
26 fn fmtrust-analyzer cargo sshkeys 0.3.4 cert/impl#[CertType][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
27 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self {
28 CertTyperust-analyzer cargo sshkeys 0.3.4 cert/CertType#::Userrust-analyzer cargo sshkeys 0.3.4 cert/CertType#User# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "user certificate"),
29 CertTyperust-analyzer cargo sshkeys 0.3.4 cert/CertType#::Hostrust-analyzer cargo sshkeys 0.3.4 cert/CertType#Host# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "host certificate"),
30 }
31 }
32 }
33
34 /// A type which represents an OpenSSH certificate key.
35 /// Please refer to [PROTOCOL.certkeys] for more details about OpenSSH certificates.
36 /// [PROTOCOL.certkeys]: https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?annotate=HEAD
37 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
38 pub struct Certificaterust-analyzer cargo sshkeys 0.3.4 cert/Certificate# {
39 /// Type of key.
40 pub key_typerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#key_type.: KeyTyperust-analyzer cargo sshkeys 0.3.4 keytype/KeyType#,
41
42 /// Cryptographic nonce.
43 pub noncerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#nonce.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
44
45 /// Public key part of the certificate.
46 pub keyrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#key.: PublicKeyrust-analyzer cargo sshkeys 0.3.4 pubkey/PublicKey#,
47
48 /// Serial number of certificate.
49 pub serialrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#serial.: u64,
50
51 /// Represents the type of the certificate.
52 pub cert_typerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#cert_type.: CertTyperust-analyzer cargo sshkeys 0.3.4 cert/CertType#,
53
54 /// Key identity.
55 pub key_idrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#key_id.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
56
57 /// The list of valid principals for the certificate.
58 pub valid_principalsrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#valid_principals.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
59
60 /// Time after which certificate is considered as valid.
61 pub valid_afterrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#valid_after.: u64,
62
63 /// Time before which certificate is considered as valid.
64 pub valid_beforerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#valid_before.: u64,
65
66 /// Critical options of the certificate. Generally used to
67 /// control features which restrict access.
68 pub critical_optionsrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#critical_options.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
69
70 /// Certificate extensions. Extensions are usually used to
71 /// enable features that grant access.
72 pub extensionsrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#extensions.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
73
74 /// The `reserved` field is currently unused and is ignored in this version of the protocol.
75 pub reservedrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#reserved.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
76
77 /// Signature key contains the CA public key used to sign the certificate.
78 pub signature_keyrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#signature_key.: PublicKeyrust-analyzer cargo sshkeys 0.3.4 pubkey/PublicKey#,
79
80 /// Signature of the certificate.
81 pub signaturerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#signature.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
82
83 /// Associated comment, if any.
84 pub commentrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#comment.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
85 }
86
87 impl Certificaterust-analyzer cargo sshkeys 0.3.4 cert/Certificate# {
88 /// Reads an OpenSSH certificate from a given path.
89 ///
90 /// # Example
91 ///
92 /// ```rust
93 /// # use sshkeys;
94 /// # fn example() -> sshkeys::Result<()> {
95 /// let cert = sshkeys::Certificate::from_path("/path/to/id_ed25519-cert.pub")?;
96 /// # Ok(())
97 /// # }
98 /// ```
99 pub fn from_pathrust-analyzer cargo sshkeys 0.3.4 cert/impl#[Certificate]from_path().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> Resultrust-analyzer cargo sshkeys 0.3.4 error/Result#<Certificaterust-analyzer cargo sshkeys 0.3.4 cert/Certificate#> {
100 let mut contents = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
101 Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Read]read_to_string().(&mut contents)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
102
103 Certificaterust-analyzer cargo sshkeys 0.3.4 cert/Certificate#::from_stringrust-analyzer cargo sshkeys 0.3.4 cert/impl#[Certificate]from_string().(&contents)
104 }
105
106 /// Reads an OpenSSH certificate from a given string.
107 ///
108 /// # Example
109 ///
110 /// ```rust
111 /// # use sshkeys;
112 /// # fn example() -> sshkeys::Result<()> {
113 /// let cert = sshkeys::Certificate::from_string("ssh-rsa AAAAB3NzaC1yc2EAAAA...")?;
114 /// # Ok(())
115 /// # }
116 /// ```
117 pub fn from_stringrust-analyzer cargo sshkeys 0.3.4 cert/impl#[Certificate]from_string().(s: &str) -> Resultrust-analyzer cargo sshkeys 0.3.4 error/Result#<Certificaterust-analyzer cargo sshkeys 0.3.4 cert/Certificate#> {
118 let mut iter = s.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().();
119
120 let kt_name = iter
121 .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().()
122 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo sshkeys 0.3.4 error/Error#::with_kindrust-analyzer cargo sshkeys 0.3.4 error/impl#[Error]with_kind().(ErrorKindrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#::InvalidFormatrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#InvalidFormat#))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
123
124 let kt = KeyTyperust-analyzer cargo sshkeys 0.3.4 keytype/KeyType#::from_namerust-analyzer cargo sshkeys 0.3.4 keytype/impl#[KeyType]from_name().(&kt_name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
125 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().kt.is_certrust-analyzer cargo sshkeys 0.3.4 keytype/KeyType#is_cert. {
126 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sshkeys 0.3.4 error/Error#::with_kindrust-analyzer cargo sshkeys 0.3.4 error/impl#[Error]with_kind().(ErrorKindrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#::NotCertificaterust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#NotCertificate#));
127 }
128
129 let data = iter
130 .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().()
131 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(Errorrust-analyzer cargo sshkeys 0.3.4 error/Error#::with_kindrust-analyzer cargo sshkeys 0.3.4 error/impl#[Error]with_kind().(ErrorKindrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#::InvalidFormatrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#InvalidFormat#))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
132
133 let comment = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(v));
134 let decoded = base64rust-analyzer cargo base64 0.22.1 crate/::enginerust-analyzer cargo base64 0.22.1 engine/::general_purposerust-analyzer cargo base64 0.22.1 engine/general_purpose/::STANDARDrust-analyzer cargo base64 0.22.1 engine/general_purpose/STANDARD..decoderust-analyzer cargo base64 0.22.1 engine/Engine#decode().(&data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
135 let mut reader = Readerrust-analyzer cargo sshkeys 0.3.4 reader/Reader#::newrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]new().(&decoded);
136
137 // Validate key types before reading the rest of the data
138 let kt_from_reader = reader.read_stringrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_string().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
139 if kt_name rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]ne().kt_from_reader {
140 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sshkeys 0.3.4 error/Error#::with_kindrust-analyzer cargo sshkeys 0.3.4 error/impl#[Error]with_kind().(ErrorKindrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#::KeyTypeMismatchrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#KeyTypeMismatch#));
141 }
142
143 let nonce = reader.read_bytesrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
144 let key = PublicKeyrust-analyzer cargo sshkeys 0.3.4 pubkey/PublicKey#::from_readerrust-analyzer cargo sshkeys 0.3.4 pubkey/impl#[PublicKey]from_reader().(&kt_name, &mut reader)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
145 let serial = reader.read_u64rust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
146
147 let cert_type = match reader.read_u32rust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_u32().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
148 1 => CertTyperust-analyzer cargo sshkeys 0.3.4 cert/CertType#::Userrust-analyzer cargo sshkeys 0.3.4 cert/CertType#User#,
149 2 => CertTyperust-analyzer cargo sshkeys 0.3.4 cert/CertType#::Hostrust-analyzer cargo sshkeys 0.3.4 cert/CertType#Host#,
150 n => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sshkeys 0.3.4 error/Error#::with_kindrust-analyzer cargo sshkeys 0.3.4 error/impl#[Error]with_kind().(ErrorKindrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#::InvalidCertTyperust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#InvalidCertType#(n))),
151 };
152
153 let key_id = reader.read_stringrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_string().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
154 let principals = reader.read_bytesrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_bytes().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|v| read_principalsrust-analyzer cargo sshkeys 0.3.4 cert/read_principals().(&v))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
155 let valid_after = reader.read_u64rust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
156 let valid_before = reader.read_u64rust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
157 let critical_options = reader.read_bytesrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_bytes().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|v| read_optionsrust-analyzer cargo sshkeys 0.3.4 cert/read_options().(&v))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
158 let extensions = reader.read_bytesrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_bytes().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|v| read_optionsrust-analyzer cargo sshkeys 0.3.4 cert/read_options().(&v))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
159 let reserved = reader.read_bytesrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
160 let signature_key = reader
161 .read_bytesrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_bytes().()
162 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|v| PublicKeyrust-analyzer cargo sshkeys 0.3.4 pubkey/PublicKey#::from_bytesrust-analyzer cargo sshkeys 0.3.4 pubkey/impl#[PublicKey]from_bytes().(&v))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
163 let signature = reader.read_bytesrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
164
165 let cert = Certificaterust-analyzer cargo sshkeys 0.3.4 cert/Certificate# {
166 key_typerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#key_type.: kt,
167 noncerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#nonce.: nonce,
168 keyrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#key.: key,
169 serialrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#serial.: serial,
170 cert_typerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#cert_type.: cert_type,
171 key_idrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#key_id.: key_id,
172 valid_principalsrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#valid_principals.: principals,
173 valid_afterrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#valid_after.: valid_after,
174 valid_beforerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#valid_before.: valid_before,
175 critical_optionsrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#critical_options.: critical_options,
176 extensionsrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#extensions.: extensions,
177 reservedrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#reserved.: reserved,
178 signature_keyrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#signature_key.: signature_key,
179 signaturerust-analyzer cargo sshkeys 0.3.4 cert/Certificate#signature.: signature,
180 commentrust-analyzer cargo sshkeys 0.3.4 cert/Certificate#comment.: comment,
181 };
182
183 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(cert)
184 }
185 }
186
187 // Reads `option` values from a byte sequence.
188 // The `option` values are used to represent the `critical options` and
189 // `extensions` in an OpenSSH certificate key, which are represented as tuples
190 // containing the `name` and `data` values of type `string`.
191 // Some `options` are `flags` only (e.g. the certificate extensions) and the
192 // associated value with them is the empty string (""), while others are `string`
193 // options and have an associated value, which is a `string`.
194 // The `critical options` of a certificate are always `string` options, since they
195 // have an associated `string` value, which is embedded in a separate buffer, so
196 // in order to extract the associated value we need to read the buffer first and then
197 // read the `string` value itself.
198 fn read_optionsrust-analyzer cargo sshkeys 0.3.4 cert/read_options().(buf: &[u8]) -> Resultrust-analyzer cargo sshkeys 0.3.4 error/Result#<HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
199 let mut reader = Readerrust-analyzer cargo sshkeys 0.3.4 reader/Reader#::newrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]new().(&buf);
200 let mut options = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
201
202 // Use a `Reader` and loop until EOF is reached, so that we can
203 // read all options from the provided byte slice.
204 loop {
205 let name = match reader.read_stringrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_string().() {
206 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) => v,
207 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => match e.kindrust-analyzer cargo sshkeys 0.3.4 error/Error#kind. {
208 ErrorKindrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#::UnexpectedEofrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#UnexpectedEof# => break,
209 _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e),
210 },
211 };
212
213 // If we have a `string` option extract the value from the buffer,
214 // otherwise we have a `flag` option which is the `empty` string.
215 let value_buf = reader.read_bytesrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
216 let value = if value_buf.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
217 Readerrust-analyzer cargo sshkeys 0.3.4 reader/Reader#::newrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]new().(&value_buf).read_stringrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_string().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
218 } else {
219 "".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
220 };
221
222 options.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name, value);
223 }
224
225 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(options)
226 }
227
228 // Reads the `valid principals` field of a certificate key.
229 // The `valid principals` are represented as a sequence of `string` values
230 // embedded in a buffer.
231 // This function reads the whole byte slice until EOF is reached in order to
232 // ensure all principals are read from the byte slice.
233 fn read_principalsrust-analyzer cargo sshkeys 0.3.4 cert/read_principals().(buf: &[u8]) -> Resultrust-analyzer cargo sshkeys 0.3.4 error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
234 let mut reader = Readerrust-analyzer cargo sshkeys 0.3.4 reader/Reader#::newrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]new().(&buf);
235 let mut items = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
236
237 loop {
238 let principal = match reader.read_stringrust-analyzer cargo sshkeys 0.3.4 reader/impl#[`Reader<'a>`]read_string().() {
239 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) => v,
240 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => match e.kindrust-analyzer cargo sshkeys 0.3.4 error/Error#kind. {
241 ErrorKindrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#::UnexpectedEofrust-analyzer cargo sshkeys 0.3.4 error/ErrorKind#UnexpectedEof# => break,
242 _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e),
243 },
244 };
245
246 items.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(principal);
247 }
248
249 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(items)
250 }