totp

Simple cli tool for storing TOTP secrets and generating tokens
git clone https://git.inz.fi/totp/
Log | Files | Refs | Submodules

commit 42f2adb484033fcc76f6c0aaf986ca3b38282a54
parent cde8057f11a99cdf39a244754d7f189f455011b8
Author: Santtu Lakkala <inz@inz.fi>
Date:   Tue,  2 Jan 2024 18:37:12 +0200

Fix token parsing, simplify

Diffstat:
Mtoken.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/token.c b/token.c @@ -90,11 +90,11 @@ struct token token_parse_uri(char *data) { if (!i) return rv; - rv.desc = uridecode(bytesnc(str, i - str), false); + rv.desc = uridecode(bytesec(str, i), false); if ((v = memchr(rv.desc.data, ':', bytes_len(rv.desc)))) { rv.issuer = bytesec(rv.desc.data, v++); - rv.desc = bytesnc(v, i - v); + rv.desc = bytesec(v, rv.desc.end); } while (*i++) { @@ -102,7 +102,7 @@ struct token token_parse_uri(char *data) { if (bytes_len(rv.key)) croak("Multiple secrets in URI"); i = v + strcspn(v, "&"); - rv.key = debase32(bytesnc(v, i - v)); + rv.key = debase32(bytesec(v, i)); } else if ((v = if_prefix(i, "digits="))) { if (!(rv.digits = strtou8(v, &i))) return rv; @@ -111,7 +111,7 @@ struct token token_parse_uri(char *data) { return rv; } else if ((v = if_prefix(i, "issuer="))) { i = v + strcspn(v, "&"); - struct bytes newiss = uridecode(bytesnc(v, i - v), true); + struct bytes newiss = uridecode(bytesec(v, i), true); if (bytes_len(rv.issuer) && !bytesequal(rv.issuer, newiss)) { errno = EINVAL; return rv;