aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJeff Yang <jeffjieyang@gmail.com>2019-07-08 16:44:11 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2019-07-08 15:44:11 -0500
commitcd59bd275ecc484b1662c86ae9ef0a64eb17d00f (patch)
tree0f2bc2ad0f5f7eb2df94038cd2cc6d56c435ce7c /tests
parent9a09f9690890c4b6fa6d4d1625e78dcbaffbf734 (diff)
downloadcryptography-cd59bd275ecc484b1662c86ae9ef0a64eb17d00f.tar.gz
cryptography-cd59bd275ecc484b1662c86ae9ef0a64eb17d00f.tar.bz2
cryptography-cd59bd275ecc484b1662c86ae9ef0a64eb17d00f.zip
add class methods for poly1305 sign verify operations (#4932)
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/test_poly1305.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_poly1305.py b/tests/hazmat/primitives/test_poly1305.py
index 71495ff7..edca4623 100644
--- a/tests/hazmat/primitives/test_poly1305.py
+++ b/tests/hazmat/primitives/test_poly1305.py
@@ -47,6 +47,9 @@ class TestPoly1305(object):
poly.update(msg)
assert poly.finalize() == tag
+ assert Poly1305.generate_tag(key, msg) == tag
+ Poly1305.verify_tag(key, msg, tag)
+
def test_key_with_no_additional_references(self, backend):
poly = Poly1305(os.urandom(32))
assert len(poly.finalize()) == 16
@@ -66,6 +69,9 @@ class TestPoly1305(object):
with pytest.raises(TypeError):
poly.update(u'')
+ with pytest.raises(TypeError):
+ Poly1305.generate_tag(b"0" * 32, u'')
+
def test_verify(self, backend):
poly = Poly1305(b"0" * 32)
poly.update(b"msg")
@@ -78,6 +84,8 @@ class TestPoly1305(object):
poly2.update(b"msg")
poly2.verify(tag)
+ Poly1305.verify_tag(b"0" * 32, b"msg", tag)
+
def test_invalid_verify(self, backend):
poly = Poly1305(b"0" * 32)
poly.update(b"msg")
@@ -89,22 +97,37 @@ class TestPoly1305(object):
with pytest.raises(InvalidSignature):
p2.verify(b"\x00" * 16)
+ with pytest.raises(InvalidSignature):
+ Poly1305.verify_tag(b"0" * 32, b"msg", b"\x00" * 16)
+
def test_verify_reject_unicode(self, backend):
poly = Poly1305(b"0" * 32)
with pytest.raises(TypeError):
poly.verify(u'')
+ with pytest.raises(TypeError):
+ Poly1305.verify_tag(b"0" * 32, b"msg", u'')
+
def test_invalid_key_type(self, backend):
with pytest.raises(TypeError):
Poly1305(object())
+ with pytest.raises(TypeError):
+ Poly1305.generate_tag(object(), b"msg")
+
def test_invalid_key_length(self, backend):
with pytest.raises(ValueError):
Poly1305(b"0" * 31)
with pytest.raises(ValueError):
+ Poly1305.generate_tag(b"0" * 31, b"msg")
+
+ with pytest.raises(ValueError):
Poly1305(b"0" * 33)
+ with pytest.raises(ValueError):
+ Poly1305.generate_tag(b"0" * 33, b"msg")
+
def test_buffer_protocol(self, backend):
key = binascii.unhexlify(
b"1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cb"
@@ -123,3 +146,7 @@ class TestPoly1305(object):
assert poly.finalize() == binascii.unhexlify(
b"4541669a7eaaee61e708dc7cbcc5eb62"
)
+
+ assert Poly1305.generate_tag(key, msg) == binascii.unhexlify(
+ b"4541669a7eaaee61e708dc7cbcc5eb62"
+ )