pyauth / pyotp

Python One-Time Password Library
https://pyauth.github.io/pyotp/
Other
2.97k stars 323 forks source link

Expected type 'str', got 'bytes' instead #129

Closed tiholic closed 2 years ago

tiholic commented 2 years ago

This snippet is errored by linter

pyotp.TOTP(base64.b32encode(bytes(f'my-key', 'utf-8')), interval=15 * 60)

https://github.com/pyauth/pyotp/blob/6568c1a83af8e0229f3c4b28d03552d601e2b7fe/src/pyotp/otp.py#L11-L12

this should be changed to def __init__(self, s: bytes, digi... to fix the problem

kislyuk commented 2 years ago

Thanks for your interest in PyOTP. Your expectation here is incorrect; the first parameter expects a string representing the base32 encoding of the secret, not bytes. Having the first parameter be bytes would be confusing as it would make it less clear whether the base32 encoded secret or the raw secret bytes are expected.