summaryrefslogtreecommitdiff
path: root/tests/test_algorithms.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_algorithms.py')
-rw-r--r--tests/test_algorithms.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_algorithms.py b/tests/test_algorithms.py
index 538078a..894ce28 100644
--- a/tests/test_algorithms.py
+++ b/tests/test_algorithms.py
@@ -45,6 +45,12 @@ class TestAlgorithms:
with pytest.raises(NotImplementedError):
algo.to_jwk("value")
+ def test_algorithm_should_throw_exception_if_compute_hash_digest_not_impl(self):
+ algo = Algorithm()
+
+ with pytest.raises(NotImplementedError):
+ algo.compute_hash_digest(b"value")
+
def test_none_algorithm_should_throw_exception_if_key_is_not_none(self):
algo = NoneAlgorithm()
@@ -1054,3 +1060,20 @@ class TestOKPAlgorithms:
signature_2 = algo.sign(b"Hello World!", priv_key_2)
assert algo.verify(b"Hello World!", pub_key_2, signature_1)
assert algo.verify(b"Hello World!", pub_key_2, signature_2)
+
+ @crypto_required
+ def test_rsa_can_compute_digest(self):
+ # this is the well-known sha256 hash of "foo"
+ foo_hash = base64.b64decode(b"LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=")
+
+ algo = RSAAlgorithm(RSAAlgorithm.SHA256)
+ computed_hash = algo.compute_hash_digest(b"foo")
+ assert computed_hash == foo_hash
+
+ def test_hmac_can_compute_digest(self):
+ # this is the well-known sha256 hash of "foo"
+ foo_hash = base64.b64decode(b"LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=")
+
+ algo = HMACAlgorithm(HMACAlgorithm.SHA256)
+ computed_hash = algo.compute_hash_digest(b"foo")
+ assert computed_hash == foo_hash