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 5from __future__ import absolute_import, division, print_function 6 7import pytest 8 9from cryptography.hazmat.primitives import constant_time 10 11 12class TestConstantTimeBytesEq(object): 13 def test_reject_unicode(self): 14 with pytest.raises(TypeError): 15 constant_time.bytes_eq(b"foo", u"foo") 16 17 with pytest.raises(TypeError): 18 constant_time.bytes_eq(u"foo", b"foo") 19 20 with pytest.raises(TypeError): 21 constant_time.bytes_eq(u"foo", u"foo") 22 23 def test_compares(self): 24 assert constant_time.bytes_eq(b"foo", b"foo") is True 25 26 assert constant_time.bytes_eq(b"foo", b"bar") is False 27 28 assert constant_time.bytes_eq(b"foobar", b"foo") is False 29 30 assert constant_time.bytes_eq(b"foo", b"foobar") is False 31