Follow-on from #13. #13 added strict-mode rejection of non-zero trailing bits
(RFC 4648 section 3.5) and of data characters appearing after padding. It
intentionally deferred full padding count/length validation because that
requires a policy decision this ticket must resolve.
Deferred scope:
- In strict mode, validate that the number of
= pad characters is correct for
the data length: numDataChars mod 8 must be in {0,2,4,5,7} (1,3,6 are
impossible for valid Base32), and, when padding is present, the pad-run length
must equal the expected value (0/6/4/3/1 respectively) so that
dataChars + padChars is a multiple of 8.
- Reject an invalid data-length remainder (1,3,6) in strict mode regardless of
padding.
- Decide the padded-vs-unpadded policy. Real-world TOTP secrets (e.g. Google
Authenticator) are frequently stored UNPADDED, so requiring canonical padding
would reject them even in strict mode. Options: (a) accept unpadded input but,
if any = is present, require the exact correct count/position; (b) require
full canonical padding; (c) expose it as a separate option. Pick one and
document it.
Implementation notes:
Acceptance criteria:
Follow-on from #13. #13 added strict-mode rejection of non-zero trailing bits
(RFC 4648 section 3.5) and of data characters appearing after padding. It
intentionally deferred full padding count/length validation because that
requires a policy decision this ticket must resolve.
Deferred scope:
=pad characters is correct forthe data length:
numDataChars mod 8must be in {0,2,4,5,7} (1,3,6 areimpossible for valid Base32), and, when padding is present, the pad-run length
must equal the expected value (0/6/4/3/1 respectively) so that
dataChars + padCharsis a multiple of 8.padding.
Authenticator) are frequently stored UNPADDED, so requiring canonical padding
would reject them even in strict mode. Options: (a) accept unpadded input but,
if any
=is present, require the exact correct count/position; (b) requirefull canonical padding; (c) expose it as a separate option. Pick one and
document it.
Implementation notes:
pStrict,EBase32DecodeError, thevPaddingSeenflag). Count data chars and pad charsduring the decode loop and validate after it.
Acceptance criteria:
=count for the data length.