diff options
author | Benjamin Denhartog <ben@denhartog.io> | 2018-03-15 14:03:50 -0700 |
---|---|---|
committer | Tad Fisher <tadfisher@gmail.com> | 2018-03-17 13:51:36 -0700 |
commit | 02bdc4a06fb2a2419b7cd29f19912052248d1c01 (patch) | |
tree | ad65fd8a55e1cd399f0df80f01079ed989a630b7 | |
parent | 778400313da4533a5fb9e5940df79249ebcbe140 (diff) | |
download | pass-otp-02bdc4a06fb2a2419b7cd29f19912052248d1c01.tar.gz pass-otp-02bdc4a06fb2a2419b7cd29f19912052248d1c01.zip |
otp-insert: require only one of `--issuer` or `--account`
closes #68
-rwxr-xr-x | otp.bash | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -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 |