constantoine/totp-rs

PartialEq support

Closed this issue · 8 comments

For my task, I need support for the PartialEq trait. Is it possible to implement the PartialEq trait for TOTP?

Hi! How would you implement it? Do you need to check for same secret? Or just same configuration (digits, period-length, period skew, algo)

I mean you can make changes to the totp-rs code.

#[derive(Debug, Clone, PartialEq)]
struct TOTP {
   ...
}

Seing issue #13 I should probably make sure the token comparison be done in constant time

Since you're just thinking of deriving PartialEq, which is basically checking for every fields equality, I'll implement it but with constant time token comparison

This feature request is irrelevant to issue #13. I need the PartialEq trait in order to use TOTP in an API that requires it. PartialEq has no effect on checking the token.

It as an effect on comparing the secret* sorry this was a typo. I'm working on it

Thanks!

The eq method is not used to validate user input, so constant time comparison is not required in my humble opinion.

I'm not sure how other people want to use this, so I preferred to err on the side of caution if there's use cases I haven't thought of. But yes, it should normally not be used to validate user input