pve: add_totp anda dd_yubico cannot error, drop Result type

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-11-10 09:50:46 +01:00
parent 951bc726a2
commit 3e5228dd73
2 changed files with 16 additions and 24 deletions

View File

@ -388,9 +388,11 @@ fn add_totp(
{ {
bail!("failed to verify TOTP challenge"); bail!("failed to verify TOTP challenge");
} }
config Ok(TfaUpdateInfo::id(config.add_totp(
.add_totp(userid, description, totp) userid,
.map(TfaUpdateInfo::id) description,
totp,
)))
} }
fn add_yubico( fn add_yubico(
@ -400,9 +402,11 @@ fn add_yubico(
value: Option<String>, value: Option<String>,
) -> Result<TfaUpdateInfo, Error> { ) -> Result<TfaUpdateInfo, Error> {
let key = value.ok_or_else(|| format_err!("missing 'value' parameter for 'yubico' entry"))?; let key = value.ok_or_else(|| format_err!("missing 'value' parameter for 'yubico' entry"))?;
config Ok(TfaUpdateInfo::id(config.add_yubico(
.add_yubico(userid, description, key) userid,
.map(TfaUpdateInfo::id) description,
key,
)))
} }
fn add_u2f<A: OpenUserChallengeData>( fn add_u2f<A: OpenUserChallengeData>(

View File

@ -167,34 +167,22 @@ impl TfaConfig {
/// ///
/// Unlike U2F/WA, this does not require a challenge/response. The user can choose their secret /// Unlike U2F/WA, this does not require a challenge/response. The user can choose their secret
/// themselves. /// themselves.
pub fn add_totp( pub fn add_totp(&mut self, userid: &str, description: String, value: Totp) -> String {
&mut self, self.users
userid: &str,
description: String,
value: Totp,
) -> Result<String, Error> {
Ok(self
.users
.entry(userid.to_owned()) .entry(userid.to_owned())
.or_default() .or_default()
.add_totp(description, value)) .add_totp(description, value)
} }
/// Add a Yubico key to a user. /// Add a Yubico key to a user.
/// ///
/// Unlike U2F/WA, this does not require a challenge/response. The user can choose their secret /// Unlike U2F/WA, this does not require a challenge/response. The user can choose their secret
/// themselves. /// themselves.
pub fn add_yubico( pub fn add_yubico(&mut self, userid: &str, description: String, key: String) -> String {
&mut self, self.users
userid: &str,
description: String,
key: String,
) -> Result<String, Error> {
Ok(self
.users
.entry(userid.to_owned()) .entry(userid.to_owned())
.or_default() .or_default()
.add_yubico(description, key)) .add_yubico(description, key)
} }
/// Add a new set of recovery keys. There can only be 1 set of keys at a time. /// Add a new set of recovery keys. There can only be 1 set of keys at a time.