Skip to content

Commit

Permalink
Only impl IdentityCreate under #[cfg(test)]
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Oct 21, 2021
1 parent 1a5d645 commit 08ada09
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion identity-account/src/identity/identity_create.rs
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()
}
}

0 comments on commit 08ada09

Please sign in to comment.