aboutsummaryrefslogtreecommitdiff
path: root/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/commands.rs b/src/commands.rs
index ebb28ca..64da866 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -306,7 +306,7 @@ where
if let Some(pin) = pin {
let pin = pin
.to_str()
- .ok_or_else(|| anyhow::anyhow!("Failed to read PIN: Invalid Unicode data found"))?;
+ .context("Failed to read PIN: Invalid Unicode data found")?;
op(ctx, data, &pin).map_err(|(_, err)| err)
} else {
try_with_pin_and_data_with_pinentry(ctx, pin_entry, data, op)
@@ -552,7 +552,7 @@ pub fn hidden_create(ctx: &mut Context<'_>, slot: u8, start: u8, end: u8) -> any
let pwd = if let Some(pwd) = &ctx.password {
pwd
.to_str()
- .ok_or_else(|| anyhow::anyhow!("Failed to read password: invalid unicode data found"))
+ .context("Failed to read password: Invalid Unicode data found")
.map(ToOwned::to_owned)
} else {
pinentry::choose(ctx, &pwd_entry).context("Failed to select new PIN")
@@ -571,7 +571,7 @@ pub fn hidden_open(ctx: &mut Context<'_>) -> anyhow::Result<()> {
let pwd = if let Some(pwd) = &ctx.password {
pwd
.to_str()
- .ok_or_else(|| anyhow::anyhow!("Failed to read password: Invalid Unicode data found"))
+ .context("Failed to read password: Invalid Unicode data found")
.map(ToOwned::to_owned)
} else {
pinentry::inquire(ctx, &pwd_entry, pinentry::Mode::Query, None)
@@ -744,7 +744,7 @@ fn prepare_ascii_secret(secret: &str) -> anyhow::Result<String> {
fn prepare_base32_secret(secret: &str) -> anyhow::Result<String> {
base32::decode(base32::Alphabet::RFC4648 { padding: false }, secret)
.map(|vec| format_bytes(&vec))
- .ok_or_else(|| anyhow::anyhow!("Failed to parse base32 secret"))
+ .context("Failed to parse base32 secret")
}
/// Configure a one-time password slot on the Nitrokey device.
@@ -817,7 +817,7 @@ fn print_otp_status(
};
slot = slot
.checked_add(1)
- .ok_or_else(|| anyhow::anyhow!("Encountered integer overflow when iterating OTP slots"))?;
+ .context("Encountered integer overflow when iterating OTP slots")?;
let name = match result {
Ok(name) => name,
Err(nitrokey::Error::LibraryError(nitrokey::LibraryError::InvalidSlot)) => return Ok(()),
@@ -884,7 +884,7 @@ fn choose_pin(
if let Some(new_pin) = new_pin {
new_pin
.to_str()
- .ok_or_else(|| anyhow::anyhow!("Failed to read PIN: Invalid Unicode data found"))
+ .context("Failed to read PIN: Invalid Unicode data found")
.map(ToOwned::to_owned)
} else {
pinentry::choose(ctx, pin_entry).context("Failed to select PIN")