Load an identity by name.
(&self, name: &str)
| 545 | |
| 546 | /// Load an identity by name. |
| 547 | pub fn load_by_name(&self, name: &str) -> Result<Identity, IdentityError> { |
| 548 | // Try to find an identity directory with a matching name |
| 549 | for entry in fs::read_dir(&self.root)? { |
| 550 | let entry = entry?; |
| 551 | let path = entry.path(); |
| 552 | |
| 553 | if path.is_dir() { |
| 554 | let identity_path = path.join(Self::IDENTITY_FILE); |
| 555 | if identity_path.exists() { |
| 556 | let content = fs::read_to_string(&identity_path)?; |
| 557 | let stored: StoredIdentity = toml::from_str(&content)?; |
| 558 | |
| 559 | if stored.name == name { |
| 560 | return stored.to_identity(); |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | Err(IdentityError::NotFound { |
| 567 | name: name.to_string(), |
| 568 | }) |
| 569 | } |
| 570 | |
| 571 | /// Load the secret key for an identity. |
| 572 | pub fn load_secret_key( |