Skip to content

Commit 98a3e40

Browse files
authored
Require storage_credentials and storage_config wallet parameters to be Strings (#285)
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
1 parent 7e0d4c4 commit 98a3e40

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

libvcx/src/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub fn open_main_pool(config: &PoolConfig) -> VcxResult<()> {
6868

6969
pub fn open_as_main_wallet(wallet_config: &WalletConfig) -> VcxResult<WalletHandle> {
7070
trace!("open_as_main_wallet >>> {}", &wallet_config.wallet_name);
71-
let config = build_wallet_config(&wallet_config.wallet_name, wallet_config.wallet_type.as_ref().map(String::as_str), wallet_config.storage_config.as_ref().map(String::as_str));
72-
let credentials = build_wallet_credentials(&wallet_config.wallet_key, wallet_config.storage_credentials.as_ref().map(|s| s.to_string()).as_deref(), &wallet_config.wallet_key_derivation, wallet_config.rekey.as_deref(), wallet_config.rekey_derivation_method.as_deref())?;
71+
let config = build_wallet_config(&wallet_config.wallet_name, wallet_config.wallet_type.as_deref(), wallet_config.storage_config.as_deref());
72+
let credentials = build_wallet_credentials(&wallet_config.wallet_key, wallet_config.storage_credentials.as_deref(), &wallet_config.wallet_key_derivation, wallet_config.rekey.as_deref(), wallet_config.rekey_derivation_method.as_deref())?;
7373

7474
let handle = indy::wallet::open_wallet(&config, &credentials)
7575
.wait()

libvcx/src/libindy/utils/wallet.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct WalletConfig {
1818
#[serde(skip_serializing_if = "Option::is_none")]
1919
pub storage_config: Option<String>,
2020
#[serde(skip_serializing_if = "Option::is_none")]
21-
pub storage_credentials: Option<serde_json::Value>,
21+
pub storage_credentials: Option<String>,
2222
#[serde(skip_serializing_if = "Option::is_none")]
2323
pub rekey: Option<String>,
2424
#[serde(skip_serializing_if = "Option::is_none")]
@@ -114,21 +114,30 @@ pub fn build_wallet_config(wallet_name: &str, wallet_type: Option<&str>, storage
114114
config.to_string()
115115
}
116116

117-
//todo: refactor args.
117+
118118
pub fn build_wallet_credentials(key: &str, storage_credentials: Option<&str>, key_derivation_method: &str, rekey: Option<&str>, rekey_derivation_method: Option<&str>) -> VcxResult<String> {
119119
serde_json::to_string(&WalletCredentials {
120-
key: String::from(key),
120+
key: key.into(),
121121
rekey: rekey.map(|s| s.into()),
122-
storage_credentials: storage_credentials.map(|s| serde_json::from_str(s).unwrap()),
123-
key_derivation_method: String::from(key_derivation_method),
122+
storage_credentials: storage_credentials.map(|val| serde_json::from_str(val).unwrap()),
123+
key_derivation_method: key_derivation_method.into(),
124124
rekey_derivation_method: rekey_derivation_method.map(|s| s.into())
125125
}).map_err(|err| VcxError::from_msg(VcxErrorKind::SerializationError, format!("Failed to serialize WalletCredentials, err: {:?}", err)))
126126
}
127127

128128
pub fn create_indy_wallet(wallet_config: &WalletConfig) -> VcxResult<()> {
129129
trace!("create_wallet >>> {}", &wallet_config.wallet_name);
130-
let config = build_wallet_config(&wallet_config.wallet_name, wallet_config.wallet_type.as_ref().map(String::as_str), wallet_config.storage_config.as_ref().map(String::as_str));
131-
let credentials = build_wallet_credentials(&wallet_config.wallet_key, wallet_config.storage_credentials.as_ref().map(|s| s.to_string()).as_deref(), &wallet_config.wallet_key_derivation, None, None)?;
130+
let config = build_wallet_config(
131+
&wallet_config.wallet_name,
132+
wallet_config.wallet_type.as_deref(),
133+
wallet_config.storage_config.as_deref());
134+
let credentials = build_wallet_credentials(
135+
&wallet_config.wallet_key,
136+
wallet_config.storage_credentials.as_deref(),
137+
&wallet_config.wallet_key_derivation,
138+
None,
139+
None
140+
)?;
132141

133142
trace!("Credentials: {:?}", credentials);
134143

@@ -178,8 +187,8 @@ pub fn close_main_wallet() -> VcxResult<()> {
178187
pub fn delete_wallet(wallet_config: &WalletConfig) -> VcxResult<()> {
179188
trace!("delete_wallet >>> wallet_name: {}", &wallet_config.wallet_name);
180189

181-
let config = build_wallet_config(&wallet_config.wallet_name, wallet_config.wallet_type.as_ref().map(String::as_str), wallet_config.storage_config.as_ref().map(String::as_str));
182-
let credentials = build_wallet_credentials(&wallet_config.wallet_key, wallet_config.storage_credentials.as_ref().map(|s| s.to_string()).as_deref(), &wallet_config.wallet_key_derivation, None, None)?;
190+
let config = build_wallet_config(&wallet_config.wallet_name, wallet_config.wallet_type.as_ref().map(String::as_str), wallet_config.storage_config.as_deref());
191+
let credentials = build_wallet_credentials(&wallet_config.wallet_key, wallet_config.storage_credentials.as_deref(), &wallet_config.wallet_key_derivation, None, None)?;
183192

184193
wallet::delete_wallet(&config, &credentials)
185194
.wait()

0 commit comments

Comments
 (0)