Simplify error checking in get-otp.

Using an authenticated encryption scheme means we can check if we had
the proper password and not print anything to standard out, instead of
having jq verify if its input is valid JSON.
This commit is contained in:
Érico Rolim 2020-10-09 00:55:06 -03:00
parent 0f1ccd703c
commit 4fe7044f17
1 changed files with 4 additions and 6 deletions

View File

@ -1,14 +1,12 @@
#!/bin/sh
file="${OTP_ACCOUNTS:-$HOME/.local/share/otp_accounts}"
json="$(@PREFIX@/libexec/cbc-file unlock "$file")"
[ -z "$json" ] && exit 1
pre_label="$(printf %s "$json" |
jq '.[].label' 2>/dev/null)"
[ -z "$pre_label" ] && exit 1
label="$(printf %s "$pre_label" |
label="$(printf %s "$json" |
jq '.[].label' 2>/dev/null |
fzf --cycle -1 ${1:+--query "$1"}
)"
)"
[ -z "$label" ] && exit 1
secret="$(printf %s "$json" |