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