Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leading zeroes #4

Closed
orion78fr opened this issue Jan 27, 2022 · 6 comments
Closed

Leading zeroes #4

orion78fr opened this issue Jan 27, 2022 · 6 comments

Comments

@orion78fr
Copy link
Contributor

I use the crate for a keepass TOTP app and I have a little issue with leading zeroes.

otp_gen

When you have the result of the get_otp, you don't really know how to format the string to have the correct number of leading 0.

I suggest that get_otp returns a struct that contains the otp, the number of digits and the duration before next refresh and has methods like get_as_integer and get_as_string in particular that return a string with the correct number of leading zeroes.

@orion78fr
Copy link
Contributor Author

By the way, I can do a PR for this too if you want.

@tmthecoder
Copy link
Owner

Definitely a good idea, I can take care of this. I'll probably make an OTPResult struct that provides an as_str or as_u32 getter where the as_str will default to returning a formatted string. I don't think the time duration would fit into the result as there's already a getter for duration in the TOTP and HOTP structs, but it would have a getter for digits

@orion78fr
Copy link
Contributor Author

I'll probably make an OTPResult struct that provides an as_str or as_u32 getter where the as_str will default to returning a formatted string.

Yeah, that's exactly what I was thinking.

I don't think the time duration would fit into the result as there's already a getter for duration

Yeah, what I suggested is adding a field that tells "next refresh in 12 seconds" for example, not duplicating the duration. That could be useful to apps to know when to refresh next.

@tmthecoder
Copy link
Owner

Yeah, what I suggested is adding a field that tells "next refresh in 12 seconds" for example, not duplicating the duration. That could be useful to apps to know when to refresh next.

Ah okay, that makes sense. Though I was thinking of making the OTPResult shared between both HOTP and TOTP classes for simplicity.

What may make more sense is adding in a time_until_refresh method in the TOTP struct since that (in my thoughts, at least) fits better with the TOTP class

@orion78fr
Copy link
Contributor Author

Yeah I see, makes sense to have the same result for both OTP types and put the time_until_refresh in TOTP.

Looking forward to this when I fix my problems with Android export on my project.

@tmthecoder
Copy link
Owner

Both features are added as of v0.4.0

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

No branches or pull requests

2 participants