logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

pass-otp-69-otp-insert_require_only_one_issuer_or_account.patch (1660B)


  1. From 1ea820305d131a69eeac0e08ebce4b971c10e8f1 Mon Sep 17 00:00:00 2001
  2. From: Benjamin Denhartog <ben@denhartog.io>
  3. Date: Thu, 15 Mar 2018 14:03:50 -0700
  4. Subject: [PATCH] otp-insert: require only one of `--issuer` or `--account`
  5. closes #68
  6. ---
  7. otp.bash | 16 +++++++++++-----
  8. 1 file changed, 11 insertions(+), 5 deletions(-)
  9. diff --git a/otp.bash b/otp.bash
  10. index 33aca78..25ac459 100755
  11. --- a/otp.bash
  12. +++ b/otp.bash
  13. @@ -105,9 +105,10 @@ otp_read_uri() {
  14. }
  15. otp_read_secret() {
  16. - local uri prompt="$1" echo="$2" issuer accountname
  17. - issuer="$(urlencode "$3")"
  18. - accountname="$(urlencode "$4")"
  19. + local uri prompt="$1" echo="$2" issuer accountname separator
  20. + [ ! "$3" = false ] && issuer="$(urlencode "$3")"
  21. + [ ! "$4" = false ] && accountname="$(urlencode "$4")"
  22. + [ -n "$issuer" ] && [ -n "$accountname" ] && separator=":"
  23. if [[ -t 0 ]]; then
  24. if [[ $echo -eq 0 ]]; then
  25. @@ -123,7 +124,8 @@ otp_read_secret() {
  26. read -r secret
  27. fi
  28. - uri="otpauth://totp/$issuer:$accountname?secret=$secret&issuer=$issuer"
  29. + uri="otpauth://totp/${issuer}${separator}${accountname}?secret=${secret}"
  30. + [ -n "$issuer" ] && uri="${uri}&issuer=${issuer}"
  31. otp_parse_uri "$uri"
  32. }
  33. @@ -216,7 +218,11 @@ cmd_otp_insert() {
  34. fi
  35. if [[ $from_secret -eq 1 ]]; then
  36. - ([[ -z "$issuer" ]] || [[ -z "$account" ]]) && die "Missing issuer or account"
  37. + [ -z "$issuer" ] && issuer=false
  38. + [ -z "$account" ] && account=false
  39. +
  40. + [ "$issuer" = false ] && [ "$account" = false ] && die "Missing one of either '--issuer' or '--account'"
  41. +
  42. otp_read_secret "$prompt" $echo "$issuer" "$account"
  43. else
  44. otp_read_uri "$prompt" $echo