Scan all identity directories and try to find one matching the ID.
(identities_dir: &Path, id_base32: &str)
| 308 | |
| 309 | /// Scan all identity directories and try to find one matching the ID. |
| 310 | fn load_identity_by_scanning(identities_dir: &Path, id_base32: &str) -> Option<UserIdentityInfo> { |
| 311 | // Already tried by ID match; try loading the first User identity as fallback |
| 312 | let entries = std::fs::read_dir(identities_dir).ok()?; |
| 313 | |
| 314 | for entry in entries.flatten() { |
| 315 | if !entry.path().is_dir() { |
| 316 | continue; |
| 317 | } |
| 318 | |
| 319 | let identity_path = entry.path().join("identity.toml"); |
| 320 | if let Ok(content) = std::fs::read_to_string(&identity_path) { |
| 321 | // Check if it contains the right ID, or if it's a User type identity |
| 322 | if content.contains(id_base32) |
| 323 | || (content.contains("type = \"user\"") |
| 324 | || content.contains("identity_type = \"user\"")) |
| 325 | { |
| 326 | return parse_identity_toml(&content); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | None |
| 331 | } |
| 332 | |
| 333 | /// Parse minimal identity info from an identity.toml file. |
| 334 | fn parse_identity_toml(content: &str) -> Option<UserIdentityInfo> { |
no test coverage detected