Scan all identity directories and try to find one matching the ID.
(identities_dir: &Path, id_base32: &str)
| 491 | |
| 492 | /// Scan all identity directories and try to find one matching the ID. |
| 493 | fn load_identity_by_scanning(identities_dir: &Path, id_base32: &str) -> Option<UserIdentityInfo> { |
| 494 | // Already tried by ID match; try loading the first User identity as fallback |
| 495 | let entries = std::fs::read_dir(identities_dir).ok()?; |
| 496 | |
| 497 | for entry in entries.flatten() { |
| 498 | if !entry.path().is_dir() { |
| 499 | continue; |
| 500 | } |
| 501 | |
| 502 | let identity_path = entry.path().join("identity.toml"); |
| 503 | if let Ok(content) = std::fs::read_to_string(&identity_path) { |
| 504 | // Check if it contains the right ID, or if it's a User type identity |
| 505 | if content.contains(id_base32) |
| 506 | || (content.contains("type = \"user\"") |
| 507 | || content.contains("identity_type = \"user\"")) |
| 508 | { |
| 509 | return parse_identity_toml(&content); |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | None |
| 514 | } |
| 515 | |
| 516 | /// Parse minimal identity info from an identity.toml file. |
| 517 | fn parse_identity_toml(content: &str) -> Option<UserIdentityInfo> { |
no test coverage detected