diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-10-27 12:29:58 +0900 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-10-27 12:30:29 +0900 |
commit | e4150bcc07fb2c68e3c860c31766b4282bba8740 (patch) | |
tree | b688eae7a07be540e0cb2fd5ae44836afc8bf5d4 | |
parent | 3568563e0ecdec07606c8b5f3fed6eaea1fa95fd (diff) | |
download | cryptography-e4150bcc07fb2c68e3c860c31766b4282bba8740.tar.gz cryptography-e4150bcc07fb2c68e3c860c31766b4282bba8740.tar.bz2 cryptography-e4150bcc07fb2c68e3c860c31766b4282bba8740.zip |
remove support for null points, improve docs
-rw-r--r-- | docs/hazmat/primitives/asymmetric/utils.rst | 11 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/utils.py | 8 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_asym_utils.py | 6 |
3 files changed, 13 insertions, 12 deletions
diff --git a/docs/hazmat/primitives/asymmetric/utils.rst b/docs/hazmat/primitives/asymmetric/utils.rst index 829edb99..79d14dae 100644 --- a/docs/hazmat/primitives/asymmetric/utils.rst +++ b/docs/hazmat/primitives/asymmetric/utils.rst @@ -37,12 +37,11 @@ Asymmetric Utilities `SEC 1 v2.0`_ section 2.3.3. This function only supports uncompressed points. - :param curve: A + :param curve: An :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` - provider. + instance. - :param x: The x value of the point. - :type x: int or `None` + :param int x: The x value of the point. :param int y: The y value of the point. @@ -59,9 +58,9 @@ Asymmetric Utilities ``x`` and ``y`` integer values. This function only supports uncompressed points. - :param curve: A + :param curve: An :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` - provider. + instance. :param bytes data: The serialized point byte string. diff --git a/src/cryptography/hazmat/primitives/asymmetric/utils.py b/src/cryptography/hazmat/primitives/asymmetric/utils.py index b62eadf0..57dea41a 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/utils.py +++ b/src/cryptography/hazmat/primitives/asymmetric/utils.py @@ -79,9 +79,9 @@ def encode_ec_point(curve, x, y): raise TypeError("curve must be an EllipticCurve instance") if x is None: - return b'\x00' + raise ValueError("null points are not supported") else: - # Get the ceiling of curve.key_size / 8 + # key_size is in bits. Convert to bytes and round up byte_length = (curve.key_size + 7) // 8 return ( b'\x04' + utils.int_to_bytes(x, byte_length) + @@ -94,9 +94,9 @@ def decode_ec_point(curve, data): raise TypeError("curve must be an EllipticCurve instance") if data == b'\x00': - return None, None + raise ValueError("null points are not supported") elif data.startswith(b'\x04'): - # Get the ceiling of curve.key_size / 8 + # key_size is in bits. Convert to bytes and round up byte_length = (curve.key_size + 7) // 8 if len(data) == 2 * byte_length + 1: return (utils.int_from_bytes(data[1:byte_length + 1], 'big'), diff --git a/tests/hazmat/primitives/test_asym_utils.py b/tests/hazmat/primitives/test_asym_utils.py index c713e9c6..22551bc4 100644 --- a/tests/hazmat/primitives/test_asym_utils.py +++ b/tests/hazmat/primitives/test_asym_utils.py @@ -82,7 +82,8 @@ def test_decode_dss_invalid_asn1(): def test_encode_ec_point_none(): - assert encode_ec_point(ec.SECP384R1(), None, 100) == b"\x00" + with pytest.raises(ValueError): + encode_ec_point(ec.SECP384R1(), None, 100) def test_encode_wrong_curve_type(): @@ -106,7 +107,8 @@ def test_encode_ec_point(): def test_decode_ec_point_none(): - assert decode_ec_point(ec.SECP384R1(), b"\x00") == (None, None) + with pytest.raises(ValueError): + decode_ec_point(ec.SECP384R1(), b"\x00") def test_decode_ec_point(): |