Simplify
This commit is contained in:
parent
a6e33aafea
commit
4a228a3ce7
1 changed files with 10 additions and 18 deletions
|
@ -182,25 +182,17 @@ impl CryptoKeys {
|
||||||
let password_sortkey = format!("password:{}", hex::encode(&ident));
|
let password_sortkey = format!("password:{}", hex::encode(&ident));
|
||||||
|
|
||||||
let password_blob = {
|
let password_blob = {
|
||||||
let mut params = k2v
|
let mut val = match k2v.read_item("keys", &password_sortkey).await {
|
||||||
.read_batch(&[k2v_read_single_key("keys", &password_sortkey)])
|
Err(k2v_client::Error::NotFound) => {
|
||||||
.await
|
bail!("given password does not exist in storage")
|
||||||
.context("ReadBatch to read password")?;
|
}
|
||||||
if params.len() != 1 {
|
x => x?,
|
||||||
bail!(
|
};
|
||||||
"Invalid response from k2v storage: {:?} (expected one item)",
|
if val.value.len() != 1 {
|
||||||
params
|
bail!("multiple values for password in storage");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if params[0].items.len() != 1 {
|
match val.value.pop().unwrap() {
|
||||||
bail!("given password does not exist in storage.");
|
K2vValue::Value(v) => v,
|
||||||
}
|
|
||||||
let vals = &mut params[0].items.iter_mut().next().unwrap().1.value;
|
|
||||||
if vals.len() != 1 {
|
|
||||||
bail!("Multiple values for password in storage");
|
|
||||||
}
|
|
||||||
match &mut vals[0] {
|
|
||||||
K2vValue::Value(v) => std::mem::take(v),
|
|
||||||
K2vValue::Tombstone => bail!("password is a tombstone"),
|
K2vValue::Tombstone => bail!("password is a tombstone"),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue