Build the identity, generating a keypair if needed.
(self)
| 499 | |
| 500 | /// Build the identity, generating a keypair if needed. |
| 501 | pub fn build(self) -> Result<Identity, IdentityError> { |
| 502 | let public_key = match (self.keypair, self.public_key) { |
| 503 | (Some(kp), _) => kp.public, |
| 504 | (None, Some(pk)) => pk, |
| 505 | (None, None) => KeyPair::generate().public, |
| 506 | }; |
| 507 | |
| 508 | let id = IdentityId::from_public_key(&public_key); |
| 509 | |
| 510 | let mut metadata = IdentityMetadata::new(); |
| 511 | if let Some(desc) = self.description { |
| 512 | metadata.description = Some(desc); |
| 513 | } |
| 514 | if let Some(exp) = self.expires_at { |
| 515 | metadata.expires_at = Some(exp); |
| 516 | } |
| 517 | |
| 518 | Ok(Identity { |
| 519 | id, |
| 520 | name: self.name, |
| 521 | email: self.email, |
| 522 | public_key, |
| 523 | identity_type: self.identity_type, |
| 524 | usage: self.usage, |
| 525 | metadata, |
| 526 | delegated_by: self.delegated_by, |
| 527 | }) |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /// Author information compatible with atomic-core's change headers. |
no outgoing calls