Skip to content

Conversation

nikicat
Copy link
Contributor

@nikicat nikicat commented Oct 27, 2024

This PR adds support for Steam TOTP encoding. totp:// URL should have encoder=steam param

Copy link

@AnomalRoil AnomalRoil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was simpler than I thought it'd be! Thanks a lot

Comment on lines +137 to +139
digit := value % radix
value /= radix
c := alphabet[digit]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: the name "Digit" has somewhat of another meaning in that library, maybe pick or pos would be clearer.

mod := int32(value % int64(math.Pow10(l)))
switch opts.Encoder {
case otp.EncoderDefault:
mod := int32(value % int64(math.Pow10(l)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing of note here, is that previously Digits.Lengths() could only be 6 or 8, whereas now it'll accept arbitrary values, meaning that if a user sets Digits to a negative value, that will cause a runtime panic because of the cast to int64 returning 0, since as per the spec:

When converting a floating-point number to an integer, the fraction is discarded (truncation towards zero).

This currently cannot happen because the Length function uses strconv.ParseUint which disallows sign prefixes, but it might warrant a set of comment here and there.

@nikicat
Copy link
Contributor Author

nikicat commented Nov 1, 2024

@AnomalRoil I appreciate your gratitude. If you don't mind, add patches to this PR please.

@pquerna pquerna merged commit c95b697 into pquerna:master Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants