Note for the js devs: The most efficient way of checking for canonicity is probably to count the number of padding =
s and check against a list of allowed last characters. Less efficient but simpler to implement: If there is one padding =
, decode and reencode the last two nonpadding characters and check for equality, if there are two padding ==
s, decode and reencode the last three nonpadding characters. That is at least more efficient than reencoding the full string.
The rust implementation will perform the check as part of the decoding process, but js doesn't get that luxury.