-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only impl
IdentityCreate
under #[cfg(test)]
- Loading branch information
1 parent
1a5d645
commit 08ada09
Showing
1 changed file
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,61 @@ | ||
// Copyright 2020-2021 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[cfg(test)] | ||
use std::convert::TryInto; | ||
|
||
use identity_core::crypto::KeyType; | ||
use identity_iota::tangle::NetworkName; | ||
|
||
use crate::types::MethodSecret; | ||
|
||
/// Configuration used to create a new Identity. | ||
#[derive(Debug)] | ||
#[derive(Debug, Clone)] | ||
pub(crate) struct IdentityCreate { | ||
pub(crate) key_type: KeyType, | ||
pub(crate) name: Option<String>, | ||
pub(crate) network: Option<NetworkName>, | ||
pub(crate) method_secret: Option<MethodSecret>, | ||
} | ||
|
||
impl IdentityCreate { | ||
pub(crate) fn new() -> Self { | ||
Self { | ||
key_type: KeyType::Ed25519, | ||
name: None, | ||
network: None, | ||
method_secret: None, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
impl IdentityCreate { | ||
#[must_use] | ||
pub(crate) fn key_type(mut self, value: KeyType) -> Self { | ||
self.key_type = value; | ||
self | ||
} | ||
|
||
#[allow(clippy::double_must_use)] | ||
#[must_use] | ||
pub(crate) fn network<T>(mut self, value: T) -> crate::Result<Self> | ||
where | ||
T: TryInto<NetworkName>, | ||
{ | ||
self.network = Some(value.try_into().map_err(|_| identity_iota::Error::InvalidNetworkName)?); | ||
Ok(self) | ||
} | ||
|
||
#[must_use] | ||
pub(crate) fn method_secret(mut self, value: MethodSecret) -> Self { | ||
self.method_secret = Some(value); | ||
self | ||
} | ||
} | ||
|
||
impl Default for IdentityCreate { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |