Scan all identity directories and try to find one matching the ID.
(identities_dir: &Path, id_base32: &str)
| 419 | |
| 420 | /// Scan all identity directories and try to find one matching the ID. |
| 421 | fn load_identity_by_scanning(identities_dir: &Path, id_base32: &str) -> Option<UserIdentityInfo> { |
| 422 | // Already tried by ID match; try loading the first User identity as fallback |
| 423 | let entries = std::fs::read_dir(identities_dir).ok()?; |
| 424 | |
| 425 | for entry in entries.flatten() { |
| 426 | if !entry.path().is_dir() { |
| 427 | continue; |
| 428 | } |
| 429 | |
| 430 | let identity_path = entry.path().join("identity.toml"); |
| 431 | if let Ok(content) = std::fs::read_to_string(&identity_path) { |
| 432 | // Check if it contains the right ID, or if it's a User type identity |
| 433 | if content.contains(id_base32) |
| 434 | || (content.contains("type = \"user\"") |
| 435 | || content.contains("identity_type = \"user\"")) |
| 436 | { |
| 437 | return parse_identity_toml(&content); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | None |
| 442 | } |
| 443 | |
| 444 | /// Parse minimal identity info from an identity.toml file. |
| 445 | fn parse_identity_toml(content: &str) -> Option<UserIdentityInfo> { |
no test coverage detected