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