totp
totp copied to clipboard
support -b for base32 input
The title says it all...
(cool project!)
(unrelated, it might be better to replace echo -n
with printf %s
, because echo -n
is non portable, or just remove the -n
bcause newlines are typically ignored anyway by base32 -d
).
Made base32_decode
static.
Simplified the code a bit, and added casts to avoid (strict) compiler warning on sign-ness and value truncation.
None of the casts were required as the sign was ensured prior in all cases, and the truncation was as intended (assign to uint8_t
intentionally truncated the value, now it's explicit).
There's one warning remaining, which also existed previously, and I didn't touch:
totp.c:145:20: error: implicit conversion changes signedness: 'ssize_t' (aka 'int') to 'unsigned int'
[-Werror,-Wsign-conversion]
memcpy(ko, ki, len);
~~~~~~ ^~~
Made base32_decode
a lot smaller (I enjoiy this...).
It behaves identically, probably slightly slower (this context is not performance critical) but now it's also easier to change alphabet (which we don't need), and it works with any charset and not only ASCII (e.g. even if B
is not immediately after A
, though it's unlikely to fix any real world usecase).
But most importantly, it's more cute!
ping?