Delete an identity from the store.
(&mut self, id: &IdentityId)
| 600 | |
| 601 | /// Delete an identity from the store. |
| 602 | pub fn delete(&mut self, id: &IdentityId) -> Result<(), IdentityError> { |
| 603 | let identity_dir = self.find_identity_dir(id)?; |
| 604 | |
| 605 | // Remove from defaults if set |
| 606 | if self.config.default_identity.as_ref() == Some(&id.to_base32()) { |
| 607 | self.config.default_identity = None; |
| 608 | } |
| 609 | |
| 610 | self.config |
| 611 | .default_by_usage |
| 612 | .retain(|_, v| v != &id.to_base32()); |
| 613 | |
| 614 | // Save updated config |
| 615 | self.save_config()?; |
| 616 | |
| 617 | // Remove the identity directory |
| 618 | fs::remove_dir_all(identity_dir)?; |
| 619 | |
| 620 | Ok(()) |
| 621 | } |
| 622 | |
| 623 | /// List all identities in the store. |
| 624 | pub fn list(&self) -> Result<Vec<Identity>, IdentityError> { |