Load an identity by name.
(&self, name: &str)
| 524 | |
| 525 | /// Load an identity by name. |
| 526 | pub fn load_by_name(&self, name: &str) -> Result<Identity, IdentityError> { |
| 527 | // Try to find an identity directory with a matching name |
| 528 | for entry in fs::read_dir(&self.root)? { |
| 529 | let entry = entry?; |
| 530 | let path = entry.path(); |
| 531 | |
| 532 | if path.is_dir() { |
| 533 | let identity_path = path.join(Self::IDENTITY_FILE); |
| 534 | if identity_path.exists() { |
| 535 | let content = fs::read_to_string(&identity_path)?; |
| 536 | let stored: StoredIdentity = toml::from_str(&content)?; |
| 537 | |
| 538 | if stored.name == name { |
| 539 | return stored.to_identity(); |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | Err(IdentityError::NotFound { |
| 546 | name: name.to_string(), |
| 547 | }) |
| 548 | } |
| 549 | |
| 550 | /// Load the secret key for an identity. |
| 551 | pub fn load_secret_key( |