Build the identity, generating a keypair if needed.
(self)
| 467 | |
| 468 | /// Build the identity, generating a keypair if needed. |
| 469 | pub fn build(self) -> Result<Identity, IdentityError> { |
| 470 | let public_key = match (self.keypair, self.public_key) { |
| 471 | (Some(kp), _) => kp.public, |
| 472 | (None, Some(pk)) => pk, |
| 473 | (None, None) => KeyPair::generate().public, |
| 474 | }; |
| 475 | |
| 476 | let id = IdentityId::from_public_key(&public_key); |
| 477 | |
| 478 | let mut metadata = IdentityMetadata::new(); |
| 479 | if let Some(desc) = self.description { |
| 480 | metadata.description = Some(desc); |
| 481 | } |
| 482 | if let Some(exp) = self.expires_at { |
| 483 | metadata.expires_at = Some(exp); |
| 484 | } |
| 485 | |
| 486 | Ok(Identity { |
| 487 | id, |
| 488 | name: self.name, |
| 489 | email: self.email, |
| 490 | public_key, |
| 491 | identity_type: self.identity_type, |
| 492 | usage: self.usage, |
| 493 | metadata, |
| 494 | delegated_by: self.delegated_by, |
| 495 | }) |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | /// Author information compatible with atomic-core's change headers. |
no outgoing calls