diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-20 21:02:53 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-20 21:02:53 +0200 |
commit | 4a228a3ce7c843a8e6e7254f858201d0ba1c8b6f (patch) | |
tree | cffad13769fbd44689ee6a112b8cdbd1a8515f6a | |
parent | a6e33aafea89ba86ac94bbc33a503f1ef5644828 (diff) | |
download | aerogramme-4a228a3ce7c843a8e6e7254f858201d0ba1c8b6f.tar.gz aerogramme-4a228a3ce7c843a8e6e7254f858201d0ba1c8b6f.zip |
Simplify
-rw-r--r-- | src/login/mod.rs | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/src/login/mod.rs b/src/login/mod.rs index de04126..7464cbb 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -182,25 +182,17 @@ impl CryptoKeys { let password_sortkey = format!("password:{}", hex::encode(&ident)); let password_blob = { - let mut params = k2v - .read_batch(&[k2v_read_single_key("keys", &password_sortkey)]) - .await - .context("ReadBatch to read password")?; - if params.len() != 1 { - bail!( - "Invalid response from k2v storage: {:?} (expected one item)", - params - ); - } - if params[0].items.len() != 1 { - bail!("given password does not exist in storage."); - } - let vals = &mut params[0].items.iter_mut().next().unwrap().1.value; - if vals.len() != 1 { - bail!("Multiple values for password in storage"); + let mut val = match k2v.read_item("keys", &password_sortkey).await { + Err(k2v_client::Error::NotFound) => { + bail!("given password does not exist in storage") + } + x => x?, + }; + if val.value.len() != 1 { + bail!("multiple values for password in storage"); } - match &mut vals[0] { - K2vValue::Value(v) => std::mem::take(v), + match val.value.pop().unwrap() { + K2vValue::Value(v) => v, K2vValue::Tombstone => bail!("password is a tombstone"), } }; |