aboutsummaryrefslogtreecommitdiff
path: root/otp.bash
diff options
context:
space:
mode:
authorBenjamin Denhartog <ben@denhartog.io>2018-03-15 14:03:50 -0700
committerTad Fisher <tadfisher@gmail.com>2018-03-17 13:51:36 -0700
commit02bdc4a06fb2a2419b7cd29f19912052248d1c01 (patch)
treead65fd8a55e1cd399f0df80f01079ed989a630b7 /otp.bash
parent778400313da4533a5fb9e5940df79249ebcbe140 (diff)
otp-insert: require only one of `--issuer` or `--account`
closes #68
Diffstat (limited to 'otp.bash')
-rwxr-xr-xotp.bash16
1 files 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