pass-otp-69-otp-insert_require_only_one_issuer_or_account.patch (1660B)
- From 1ea820305d131a69eeac0e08ebce4b971c10e8f1 Mon Sep 17 00:00:00 2001
- From: Benjamin Denhartog <ben@denhartog.io>
- Date: Thu, 15 Mar 2018 14:03:50 -0700
- Subject: [PATCH] otp-insert: require only one of `--issuer` or `--account`
- closes #68
- ---
- otp.bash | 16 +++++++++++-----
- 1 file changed, 11 insertions(+), 5 deletions(-)
- diff --git a/otp.bash b/otp.bash
- index 33aca78..25ac459 100755
- --- a/otp.bash
- +++ b/otp.bash
- @@ -105,9 +105,10 @@ otp_read_uri() {
- }
- otp_read_secret() {
- - local uri prompt="$1" echo="$2" issuer accountname
- - issuer="$(urlencode "$3")"
- - accountname="$(urlencode "$4")"
- + local uri prompt="$1" echo="$2" issuer accountname separator
- + [ ! "$3" = false ] && issuer="$(urlencode "$3")"
- + [ ! "$4" = false ] && accountname="$(urlencode "$4")"
- + [ -n "$issuer" ] && [ -n "$accountname" ] && separator=":"
- if [[ -t 0 ]]; then
- if [[ $echo -eq 0 ]]; then
- @@ -123,7 +124,8 @@ otp_read_secret() {
- read -r secret
- fi
- - uri="otpauth://totp/$issuer:$accountname?secret=$secret&issuer=$issuer"
- + uri="otpauth://totp/${issuer}${separator}${accountname}?secret=${secret}"
- + [ -n "$issuer" ] && uri="${uri}&issuer=${issuer}"
- otp_parse_uri "$uri"
- }
- @@ -216,7 +218,11 @@ cmd_otp_insert() {
- fi
- if [[ $from_secret -eq 1 ]]; then
- - ([[ -z "$issuer" ]] || [[ -z "$account" ]]) && die "Missing issuer or account"
- + [ -z "$issuer" ] && issuer=false
- + [ -z "$account" ] && account=false
- +
- + [ "$issuer" = false ] && [ "$account" = false ] && die "Missing one of either '--issuer' or '--account'"
- +
- otp_read_secret "$prompt" $echo "$issuer" "$account"
- else
- otp_read_uri "$prompt" $echo