constant_time.py 387 B

12345678910111213
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. import hmac
  5. def bytes_eq(a: bytes, b: bytes) -> bool:
  6. if not isinstance(a, bytes) or not isinstance(b, bytes):
  7. raise TypeError("a and b must be bytes.")
  8. return hmac.compare_digest(a, b)