aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_utils.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-04-30 09:07:27 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-04-30 09:07:27 -0500
commit3fc686ea06d4c2dcaf6b363ec1c54a72d995df88 (patch)
treec599bb3bbb31e38ca9074eebcabe55fbbf5cc7bb /tests/test_utils.py
parent26f2d5352911ff99c9c7650c926eaa73c432064e (diff)
downloadcryptography-3fc686ea06d4c2dcaf6b363ec1c54a72d995df88.tar.gz
cryptography-3fc686ea06d4c2dcaf6b363ec1c54a72d995df88.tar.bz2
cryptography-3fc686ea06d4c2dcaf6b363ec1c54a72d995df88.zip
dss_sig_value: Pure python conversion of (r, s) to byte stream
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 7a0b9e74..7b3ffbc3 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -27,11 +27,11 @@ from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
import cryptography_vectors
from .utils import (
- check_backend_support, check_for_iface, load_cryptrec_vectors,
- load_fips_dsa_key_pair_vectors, load_fips_dsa_sig_vectors,
- load_fips_ecdsa_key_pair_vectors, load_fips_ecdsa_signing_vectors,
- load_hash_vectors, load_nist_vectors, load_pkcs1_vectors,
- load_rsa_nist_vectors, load_vectors_from_file,
+ check_backend_support, check_for_iface, dss_sig_value,
+ load_cryptrec_vectors, load_fips_dsa_key_pair_vectors,
+ load_fips_dsa_sig_vectors, load_fips_ecdsa_key_pair_vectors,
+ load_fips_ecdsa_signing_vectors, load_hash_vectors, load_nist_vectors,
+ load_pkcs1_vectors, load_rsa_nist_vectors, load_vectors_from_file,
raises_unsupported_algorithm, select_backends
)
@@ -125,6 +125,32 @@ def test_check_backend_support_no_backend():
check_backend_support(item)
+def test_dss_sig_value():
+ sig = dss_sig_value(1, 1)
+ assert sig == b"0\x06\x02\x01\x01\x02\x01\x01"
+
+ sig2 = dss_sig_value(1037234182290683143945502320610861668562885151617,
+ 559776156650501990899426031439030258256861634312)
+ assert sig2 == (
+ b'0-\x02\x15\x00\xb5\xaf0xg\xfb\x8bT9\x00\x13\xccg\x02\r\xdf\x1f,\x0b'
+ b'\x81\x02\x14b\r;"\xabP1D\x0c>5\xea\xb6\xf4\x81)\x8f\x9e\x9f\x08'
+ )
+
+ sig3 = dss_sig_value(0, 0)
+ assert sig3 == b"0\x06\x02\x01\x00\x02\x01\x00"
+
+
+def test_dss_sig_value_negative():
+ with pytest.raises(ValueError):
+ dss_sig_value(-1, 1)
+
+ with pytest.raises(ValueError):
+ dss_sig_value(1, -1)
+
+ with pytest.raises(ValueError):
+ dss_sig_value(-1, -1)
+
+
def test_load_nist_vectors():
vector_data = textwrap.dedent("""
# CAVS 11.1