aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/test_dsa.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2016-01-10 15:23:40 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2016-01-10 15:23:40 -0600
commited2d4b184a9acb5de1fa25aaacf4a71d7e23f82e (patch)
treeb7db119e1276a32f9336baade3d19368144f4cc4 /tests/hazmat/primitives/test_dsa.py
parent3f6f8f593e0bd9910d406ec56bfeceba5a2badbf (diff)
parent41777171d35c2935e5d690cd51edf3ad89803bad (diff)
downloadcryptography-ed2d4b184a9acb5de1fa25aaacf4a71d7e23f82e.tar.gz
cryptography-ed2d4b184a9acb5de1fa25aaacf4a71d7e23f82e.tar.bz2
cryptography-ed2d4b184a9acb5de1fa25aaacf4a71d7e23f82e.zip
Merge pull request #2661 from alex/coverage
Write some tests for skip conditions in tests.
Diffstat (limited to 'tests/hazmat/primitives/test_dsa.py')
-rw-r--r--tests/hazmat/primitives/test_dsa.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/tests/hazmat/primitives/test_dsa.py b/tests/hazmat/primitives/test_dsa.py
index d1f8f341..fcfda614 100644
--- a/tests/hazmat/primitives/test_dsa.py
+++ b/tests/hazmat/primitives/test_dsa.py
@@ -35,6 +35,29 @@ class DummyKeyEncryption(object):
pass
+@utils.register_interface(hashes.HashAlgorithm)
+class DummyHashAlgorithm(object):
+ name = "dummy"
+ digest_size = 32
+ block_size = 64
+
+
+def _skip_if_dsa_not_supported(backend, algorithm, p, q, g):
+ if (
+ not backend.dsa_parameters_supported(p, q, g) or
+ not backend.dsa_hash_supported(algorithm)
+ ):
+ pytest.skip(
+ "{0} does not support the provided parameters".format(backend)
+ )
+
+
+@pytest.mark.requires_backend_interface(interface=DSABackend)
+def test_skip_if_dsa_not_supported(backend):
+ with pytest.raises(pytest.skip.Exception):
+ _skip_if_dsa_not_supported(backend, DummyHashAlgorithm(), 1, 1, 1)
+
+
@pytest.mark.requires_backend_interface(interface=DSABackend)
class TestDSA(object):
def test_generate_dsa_parameters(self, backend):
@@ -552,14 +575,10 @@ class TestDSAVerification(object):
def test_dsa_verification(self, vector, backend):
digest_algorithm = vector['digest_algorithm'].replace("-", "")
algorithm = self._algorithms_dict[digest_algorithm]
- if (
- not backend.dsa_parameters_supported(
- vector['p'], vector['q'], vector['g']
- ) or not backend.dsa_hash_supported(algorithm)
- ):
- pytest.skip(
- "{0} does not support the provided parameters".format(backend)
- )
+
+ _skip_if_dsa_not_supported(
+ backend, algorithm, vector['p'], vector['q'], vector['g']
+ )
public_key = dsa.DSAPublicNumbers(
parameter_numbers=dsa.DSAParameterNumbers(
@@ -620,14 +639,10 @@ class TestDSASignature(object):
def test_dsa_signing(self, vector, backend):
digest_algorithm = vector['digest_algorithm'].replace("-", "")
algorithm = self._algorithms_dict[digest_algorithm]
- if (
- not backend.dsa_parameters_supported(
- vector['p'], vector['q'], vector['g']
- ) or not backend.dsa_hash_supported(algorithm)
- ):
- pytest.skip(
- "{0} does not support the provided parameters".format(backend)
- )
+
+ _skip_if_dsa_not_supported(
+ backend, algorithm, vector['p'], vector['q'], vector['g']
+ )
private_key = dsa.DSAPrivateNumbers(
public_numbers=dsa.DSAPublicNumbers(