~martijnbraam/public-inbox

numberstation: Gracefully handle doubles in URLs v1 APPLIED

Andrey Skvortsov: 2
 Gracefully handle doubles in URLs
 Use GtkSpinbox instead of GtkAdjustment to get integer value

 2 files changed, 8 insertions(+), 8 deletions(-)
Hi Martijn,

Do you have any feedback on these patches sent a month ago?
 - Use GtkSpinbox instead of GtkAdjustment to get integer value
 - Gracefully handle doubles in URLs

They fix usage of custom period for TOTP in numberstation, otherwise
it's not possible to add TOTP with custom period through UI or URL.
Hi Andrey,

Sorry for the delay, I've applied your patches.
I had not encountered otp urls with decimals in them before, they don't 
really make sense for things like length but better to handle it than 
not I guess.

Greetings,
Martijn Braam
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~martijnbraam/public-inbox/patches/37328/mbox | git am -3
Learn more about email & git

[PATCH numberstation] Gracefully handle doubles in URLs Export this patch

Otherwise following error happens:
```
  File "numberstation/window.py", line 302, in on_save_clicked
    url = OTPUrl.create(name=name, type=type, secret=secret, duration=duration, length=length, counter=counter)
  File "numberstation/otpurl.py", line 44, in create
    return cls(otp.provisioning_uri(name=name))
  File "numberstation/otpurl.py", line 26, in __init__
    self.period = int((qs['period'][0])) if 'period' in qs else 30
ValueError: invalid literal for int() with base 10: '60.0'
```

Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
---
 numberstation/otpurl.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/numberstation/otpurl.py b/numberstation/otpurl.py
index f64f53f..628e3f0 100644
--- a/numberstation/otpurl.py
+++ b/numberstation/otpurl.py
@@ -23,11 +23,11 @@ class OTPUrl:
        qs = parse_qs(parts.query)
        self.secret = qs['secret'][0]
        self.issuer = qs['issuer'][0] if 'issuer' in qs else None
        self.period = int(qs['period'][0]) if 'period' in qs else 30
        self.digits = int(qs['digits'][0]) if 'digits' in qs else 6
        self.initial_count = int(qs['counter'][0]) if 'counter' in qs else 0
        self.period = int(float(qs['period'][0])) if 'period' in qs else 30
        self.digits = int(float(qs['digits'][0])) if 'digits' in qs else 6
        self.initial_count = int(float(qs['counter'][0])) if 'counter' in qs else 0
        if 'initial_count' in qs:
            self.initial_count = int(qs['initial_count'][0])
            self.initial_count = int(float(qs['initial_count'][0]))

        self.digest = hashlib.sha1
        if 'digest' in qs:
-- 
2.35.1

[PATCH numberstation] Use GtkSpinbox instead of GtkAdjustment to get integer value Export this patch

Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
---
 numberstation/window.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/numberstation/window.py b/numberstation/window.py
index bdcf2bd..59fc9e7 100644
--- a/numberstation/window.py
+++ b/numberstation/window.py
@@ -42,8 +42,8 @@ class NumberstationWindow:
        self.add_secret = builder.get_object("add_secret")
        self.add_totp = builder.get_object("add_totp")
        self.add_counter = builder.get_object("add_counter")
        self.add_length_adj = builder.get_object("add_length_adj")
        self.add_timer_adj = builder.get_object("add_timer_adj")
        self.add_length = builder.get_object("add_length")
        self.add_timer = builder.get_object("add_timer")
        self.add_save = builder.get_object("add_save")

        self.hamburgermenu = builder.get_object("hamburgermenu")
@@ -291,8 +291,8 @@ class NumberstationWindow:
        name = self.add_name.get_text().strip()
        type = 'totp' if self.add_totp.get_active() else 'hotp'
        secret = self.add_secret.get_text().strip()
        duration = self.add_timer_adj.get_value()
        length = self.add_length_adj.get_value()
        duration = self.add_timer.get_value_as_int()
        length = self.add_length.get_value_as_int()
        counter = self.add_counter.get_text().strip()
        if counter == '':
            counter = None
-- 
2.35.1
Hi Martijn,

Do you have any feedback on these patches sent a month ago?
 - Use GtkSpinbox instead of GtkAdjustment to get integer value
 - Gracefully handle doubles in URLs

They fix usage of custom period for TOTP in numberstation, otherwise
it's not possible to add TOTP with custom period through UI or URL.