totp icon indicating copy to clipboard operation
totp copied to clipboard

support -b for base32 input

Open avih opened this issue 1 year ago • 4 comments

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).

avih avatar Oct 21 '23 17:10 avih

Made base32_decode static.

avih avatar Oct 21 '23 18:10 avih

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);
    ~~~~~~         ^~~

avih avatar Oct 22 '23 07:10 avih

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!

avih avatar Oct 22 '23 15:10 avih

ping?

avih avatar Dec 05 '23 18:12 avih