We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Documentation of DSA signature references incorrect RFC
Documentation of DSA signatures (https://cryptography.io/en/latest/hazmat/primitives/asymmetric/dsa/#signing) references RFC 6979 which sounds strange. Same for the naming of de/encoding functions at https://cryptography.io/en/latest/hazmat/primitives/asymmetric/utils/#cryptography.hazmat.primitives.asymmetric.utils.decode_rfc6979_signature

But that RFC doesn't actually define the {r,s} encoding. The actual asn1 module can be found in RFC 3279 which defines both dsa-with-sha1 signature and Dss-Sig-Value which is the {r,s} sequence.

The references to RFC 6979 are actually unfortunate, because it defines deterministic DSA signatures, while cryptography.io exposes the randomised version using openssl's `DSA_sign`.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cryptography/utils.py`
Content:
```
1 # This file is dual licensed under the terms of the Apache License, Version
2 # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3 # for complete details.
4 
5 from __future__ import absolute_import, division, print_function
6 
7 import abc
8 import binascii
9 import inspect
10 import struct
11 import sys
12 import warnings
13 
14 
15 DeprecatedIn09 = DeprecationWarning
16 
17 
18 def read_only_property(name):
19     return property(lambda self: getattr(self, name))
20 
21 
22 def register_interface(iface):
23     def register_decorator(klass):
24         verify_interface(iface, klass)
25         iface.register(klass)
26         return klass
27     return register_decorator
28 
29 
30 if hasattr(int, "from_bytes"):
31     int_from_bytes = int.from_bytes
32 else:
33     def int_from_bytes(data, byteorder, signed=False):
34         assert byteorder == 'big'
35         assert not signed
36 
37         if len(data) % 4 != 0:
38             data = (b'\x00' * (4 - (len(data) % 4))) + data
39 
40         result = 0
41 
42         while len(data) > 0:
43             digit, = struct.unpack('>I', data[:4])
44             result = (result << 32) + digit
45             data = data[4:]
46 
47         return result
48 
49 
50 def int_to_bytes(integer):
51     hex_string = '%x' % integer
52     n = len(hex_string)
53     return binascii.unhexlify(hex_string.zfill(n + (n & 1)))
54 
55 
56 class InterfaceNotImplemented(Exception):
57     pass
58 
59 
60 def verify_interface(iface, klass):
61     for method in iface.__abstractmethods__:
62         if not hasattr(klass, method):
63             raise InterfaceNotImplemented(
64                 "{0} is missing a {1!r} method".format(klass, method)
65             )
66         if isinstance(getattr(iface, method), abc.abstractproperty):
67             # Can't properly verify these yet.
68             continue
69         spec = inspect.getargspec(getattr(iface, method))
70         actual = inspect.getargspec(getattr(klass, method))
71         if spec != actual:
72             raise InterfaceNotImplemented(
73                 "{0}.{1}'s signature differs from the expected. Expected: "
74                 "{2!r}. Received: {3!r}".format(
75                     klass, method, spec, actual
76                 )
77             )
78 
79 
80 if sys.version_info >= (2, 7):
81     def bit_length(x):
82         return x.bit_length()
83 else:
84     def bit_length(x):
85         return len(bin(x)) - (2 + (x <= 0))
86 
87 
88 class _DeprecatedValue(object):
89     def __init__(self, value, message, warning_class):
90         self.value = value
91         self.message = message
92         self.warning_class = warning_class
93 
94 
95 class _ModuleWithDeprecations(object):
96     def __init__(self, module):
97         self.__dict__["_module"] = module
98 
99     def __getattr__(self, attr):
100         obj = getattr(self._module, attr)
101         if isinstance(obj, _DeprecatedValue):
102             warnings.warn(obj.message, obj.warning_class, stacklevel=2)
103             obj = obj.value
104         return obj
105 
106     def __setattr__(self, attr, value):
107         setattr(self._module, attr, value)
108 
109     def __dir__(self):
110         return ["_module"] + dir(self._module)
111 
112 
113 def deprecated(value, module_name, message, warning_class):
114     module = sys.modules[module_name]
115     if not isinstance(module, _ModuleWithDeprecations):
116         sys.modules[module_name] = module = _ModuleWithDeprecations(module)
117     return _DeprecatedValue(value, message, warning_class)
118
```

Path: `src/cryptography/hazmat/primitives/asymmetric/utils.py`
Content:
```
1 # This file is dual licensed under the terms of the Apache License, Version
2 # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3 # for complete details.
4 
5 from __future__ import absolute_import, division, print_function
6 
7 from pyasn1.codec.der import decoder, encoder
8 from pyasn1.error import PyAsn1Error
9 from pyasn1.type import namedtype, univ
10 
11 import six
12 
13 
14 class _DSSSigValue(univ.Sequence):
15     componentType = namedtype.NamedTypes(
16         namedtype.NamedType('r', univ.Integer()),
17         namedtype.NamedType('s', univ.Integer())
18     )
19 
20 
21 def decode_rfc6979_signature(signature):
22     try:
23         data, remaining = decoder.decode(signature, asn1Spec=_DSSSigValue())
24     except PyAsn1Error:
25         raise ValueError("Invalid signature data. Unable to decode ASN.1")
26 
27     if remaining:
28         raise ValueError(
29             "The signature contains bytes after the end of the ASN.1 sequence."
30         )
31 
32     r = int(data.getComponentByName('r'))
33     s = int(data.getComponentByName('s'))
34     return (r, s)
35 
36 
37 def encode_rfc6979_signature(r, s):
38     if (
39         not isinstance(r, six.integer_types) or
40         not isinstance(s, six.integer_types)
41     ):
42         raise ValueError("Both r and s must be integers")
43 
44     sig = _DSSSigValue()
45     sig.setComponentByName('r', r)
46     sig.setComponentByName('s', s)
47     return encoder.encode(sig)
48
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cryptography/hazmat/primitives/asymmetric/utils.py b/src/cryptography/hazmat/primitives/asymmetric/utils.py
--- a/src/cryptography/hazmat/primitives/asymmetric/utils.py
+++ b/src/cryptography/hazmat/primitives/asymmetric/utils.py
@@ -4,12 +4,16 @@
 
 from __future__ import absolute_import, division, print_function
 
+import warnings
+
 from pyasn1.codec.der import decoder, encoder
 from pyasn1.error import PyAsn1Error
 from pyasn1.type import namedtype, univ
 
 import six
 
+from cryptography import utils
+
 
 class _DSSSigValue(univ.Sequence):
     componentType = namedtype.NamedTypes(
@@ -19,6 +23,17 @@
 
 
 def decode_rfc6979_signature(signature):
+    warnings.warn(
+        "decode_rfc6979_signature is deprecated and will "
+        "be removed in a future version, use decode_dss_signature instead "
+        "instead.",
+        utils.DeprecatedIn10,
+        stacklevel=2
+    )
+    return decode_dss_signature(signature)
+
+
+def decode_dss_signature(signature):
     try:
         data, remaining = decoder.decode(signature, asn1Spec=_DSSSigValue())
     except PyAsn1Error:
@@ -35,6 +50,17 @@
 
 
 def encode_rfc6979_signature(r, s):
+    warnings.warn(
+        "encode_rfc6979_signature is deprecated and will "
+        "be removed in a future version, use encode_dss_signature instead "
+        "instead.",
+        utils.DeprecatedIn10,
+        stacklevel=2
+    )
+    return encode_dss_signature(r, s)
+
+
+def encode_dss_signature(r, s):
     if (
         not isinstance(r, six.integer_types) or
         not isinstance(s, six.integer_types)
diff --git a/src/cryptography/utils.py b/src/cryptography/utils.py
--- a/src/cryptography/utils.py
+++ b/src/cryptography/utils.py
@@ -13,6 +13,7 @@
 
 
 DeprecatedIn09 = DeprecationWarning
+DeprecatedIn10 = PendingDeprecationWarning
 
 
 def read_only_property(name):

{"golden_diff": "diff --git a/src/cryptography/hazmat/primitives/asymmetric/utils.py b/src/cryptography/hazmat/primitives/asymmetric/utils.py\n--- a/src/cryptography/hazmat/primitives/asymmetric/utils.py\n+++ b/src/cryptography/hazmat/primitives/asymmetric/utils.py\n@@ -4,12 +4,16 @@\n \n from __future__ import absolute_import, division, print_function\n \n+import warnings\n+\n from pyasn1.codec.der import decoder, encoder\n from pyasn1.error import PyAsn1Error\n from pyasn1.type import namedtype, univ\n \n import six\n \n+from cryptography import utils\n+\n \n class _DSSSigValue(univ.Sequence):\n     componentType = namedtype.NamedTypes(\n@@ -19,6 +23,17 @@\n \n \n def decode_rfc6979_signature(signature):\n+    warnings.warn(\n+        \"decode_rfc6979_signature is deprecated and will \"\n+        \"be removed in a future version, use decode_dss_signature instead \"\n+        \"instead.\",\n+        utils.DeprecatedIn10,\n+        stacklevel=2\n+    )\n+    return decode_dss_signature(signature)\n+\n+\n+def decode_dss_signature(signature):\n     try:\n         data, remaining = decoder.decode(signature, asn1Spec=_DSSSigValue())\n     except PyAsn1Error:\n@@ -35,6 +50,17 @@\n \n \n def encode_rfc6979_signature(r, s):\n+    warnings.warn(\n+        \"encode_rfc6979_signature is deprecated and will \"\n+        \"be removed in a future version, use encode_dss_signature instead \"\n+        \"instead.\",\n+        utils.DeprecatedIn10,\n+        stacklevel=2\n+    )\n+    return encode_dss_signature(r, s)\n+\n+\n+def encode_dss_signature(r, s):\n     if (\n         not isinstance(r, six.integer_types) or\n         not isinstance(s, six.integer_types)\ndiff --git a/src/cryptography/utils.py b/src/cryptography/utils.py\n--- a/src/cryptography/utils.py\n+++ b/src/cryptography/utils.py\n@@ -13,6 +13,7 @@\n \n \n DeprecatedIn09 = DeprecationWarning\n+DeprecatedIn10 = PendingDeprecationWarning\n \n \n def read_only_property(name):\n", "issue": "Documentation of DSA signature references incorrect RFC\nDocumentation of DSA signatures (https://cryptography.io/en/latest/hazmat/primitives/asymmetric/dsa/#signing) references RFC 6979 which sounds strange. Same for the naming of de/encoding functions at https://cryptography.io/en/latest/hazmat/primitives/asymmetric/utils/#cryptography.hazmat.primitives.asymmetric.utils.decode_rfc6979_signature\n\nBut that RFC doesn't actually define the {r,s} encoding. The actual asn1 module can be found in RFC 3279 which defines both dsa-with-sha1 signature and Dss-Sig-Value which is the {r,s} sequence.\n\nThe references to RFC 6979 are actually unfortunate, because it defines deterministic DSA signatures, while cryptography.io exposes the randomised version using openssl's `DSA_sign`.\n\n", "before_files": [{"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport abc\nimport binascii\nimport inspect\nimport struct\nimport sys\nimport warnings\n\n\nDeprecatedIn09 = DeprecationWarning\n\n\ndef read_only_property(name):\n    return property(lambda self: getattr(self, name))\n\n\ndef register_interface(iface):\n    def register_decorator(klass):\n        verify_interface(iface, klass)\n        iface.register(klass)\n        return klass\n    return register_decorator\n\n\nif hasattr(int, \"from_bytes\"):\n    int_from_bytes = int.from_bytes\nelse:\n    def int_from_bytes(data, byteorder, signed=False):\n        assert byteorder == 'big'\n        assert not signed\n\n        if len(data) % 4 != 0:\n            data = (b'\\x00' * (4 - (len(data) % 4))) + data\n\n        result = 0\n\n        while len(data) > 0:\n            digit, = struct.unpack('>I', data[:4])\n            result = (result << 32) + digit\n            data = data[4:]\n\n        return result\n\n\ndef int_to_bytes(integer):\n    hex_string = '%x' % integer\n    n = len(hex_string)\n    return binascii.unhexlify(hex_string.zfill(n + (n & 1)))\n\n\nclass InterfaceNotImplemented(Exception):\n    pass\n\n\ndef verify_interface(iface, klass):\n    for method in iface.__abstractmethods__:\n        if not hasattr(klass, method):\n            raise InterfaceNotImplemented(\n                \"{0} is missing a {1!r} method\".format(klass, method)\n            )\n        if isinstance(getattr(iface, method), abc.abstractproperty):\n            # Can't properly verify these yet.\n            continue\n        spec = inspect.getargspec(getattr(iface, method))\n        actual = inspect.getargspec(getattr(klass, method))\n        if spec != actual:\n            raise InterfaceNotImplemented(\n                \"{0}.{1}'s signature differs from the expected. Expected: \"\n                \"{2!r}. Received: {3!r}\".format(\n                    klass, method, spec, actual\n                )\n            )\n\n\nif sys.version_info >= (2, 7):\n    def bit_length(x):\n        return x.bit_length()\nelse:\n    def bit_length(x):\n        return len(bin(x)) - (2 + (x <= 0))\n\n\nclass _DeprecatedValue(object):\n    def __init__(self, value, message, warning_class):\n        self.value = value\n        self.message = message\n        self.warning_class = warning_class\n\n\nclass _ModuleWithDeprecations(object):\n    def __init__(self, module):\n        self.__dict__[\"_module\"] = module\n\n    def __getattr__(self, attr):\n        obj = getattr(self._module, attr)\n        if isinstance(obj, _DeprecatedValue):\n            warnings.warn(obj.message, obj.warning_class, stacklevel=2)\n            obj = obj.value\n        return obj\n\n    def __setattr__(self, attr, value):\n        setattr(self._module, attr, value)\n\n    def __dir__(self):\n        return [\"_module\"] + dir(self._module)\n\n\ndef deprecated(value, module_name, message, warning_class):\n    module = sys.modules[module_name]\n    if not isinstance(module, _ModuleWithDeprecations):\n        sys.modules[module_name] = module = _ModuleWithDeprecations(module)\n    return _DeprecatedValue(value, message, warning_class)\n", "path": "src/cryptography/utils.py"}, {"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\nfrom pyasn1.codec.der import decoder, encoder\nfrom pyasn1.error import PyAsn1Error\nfrom pyasn1.type import namedtype, univ\n\nimport six\n\n\nclass _DSSSigValue(univ.Sequence):\n    componentType = namedtype.NamedTypes(\n        namedtype.NamedType('r', univ.Integer()),\n        namedtype.NamedType('s', univ.Integer())\n    )\n\n\ndef decode_rfc6979_signature(signature):\n    try:\n        data, remaining = decoder.decode(signature, asn1Spec=_DSSSigValue())\n    except PyAsn1Error:\n        raise ValueError(\"Invalid signature data. Unable to decode ASN.1\")\n\n    if remaining:\n        raise ValueError(\n            \"The signature contains bytes after the end of the ASN.1 sequence.\"\n        )\n\n    r = int(data.getComponentByName('r'))\n    s = int(data.getComponentByName('s'))\n    return (r, s)\n\n\ndef encode_rfc6979_signature(r, s):\n    if (\n        not isinstance(r, six.integer_types) or\n        not isinstance(s, six.integer_types)\n    ):\n        raise ValueError(\"Both r and s must be integers\")\n\n    sig = _DSSSigValue()\n    sig.setComponentByName('r', r)\n    sig.setComponentByName('s', s)\n    return encoder.encode(sig)\n", "path": "src/cryptography/hazmat/primitives/asymmetric/utils.py"}], "after_files": [{"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport abc\nimport binascii\nimport inspect\nimport struct\nimport sys\nimport warnings\n\n\nDeprecatedIn09 = DeprecationWarning\nDeprecatedIn10 = PendingDeprecationWarning\n\n\ndef read_only_property(name):\n    return property(lambda self: getattr(self, name))\n\n\ndef register_interface(iface):\n    def register_decorator(klass):\n        verify_interface(iface, klass)\n        iface.register(klass)\n        return klass\n    return register_decorator\n\n\nif hasattr(int, \"from_bytes\"):\n    int_from_bytes = int.from_bytes\nelse:\n    def int_from_bytes(data, byteorder, signed=False):\n        assert byteorder == 'big'\n        assert not signed\n\n        if len(data) % 4 != 0:\n            data = (b'\\x00' * (4 - (len(data) % 4))) + data\n\n        result = 0\n\n        while len(data) > 0:\n            digit, = struct.unpack('>I', data[:4])\n            result = (result << 32) + digit\n            data = data[4:]\n\n        return result\n\n\ndef int_to_bytes(integer):\n    hex_string = '%x' % integer\n    n = len(hex_string)\n    return binascii.unhexlify(hex_string.zfill(n + (n & 1)))\n\n\nclass InterfaceNotImplemented(Exception):\n    pass\n\n\ndef verify_interface(iface, klass):\n    for method in iface.__abstractmethods__:\n        if not hasattr(klass, method):\n            raise InterfaceNotImplemented(\n                \"{0} is missing a {1!r} method\".format(klass, method)\n            )\n        if isinstance(getattr(iface, method), abc.abstractproperty):\n            # Can't properly verify these yet.\n            continue\n        spec = inspect.getargspec(getattr(iface, method))\n        actual = inspect.getargspec(getattr(klass, method))\n        if spec != actual:\n            raise InterfaceNotImplemented(\n                \"{0}.{1}'s signature differs from the expected. Expected: \"\n                \"{2!r}. Received: {3!r}\".format(\n                    klass, method, spec, actual\n                )\n            )\n\n\nif sys.version_info >= (2, 7):\n    def bit_length(x):\n        return x.bit_length()\nelse:\n    def bit_length(x):\n        return len(bin(x)) - (2 + (x <= 0))\n\n\nclass _DeprecatedValue(object):\n    def __init__(self, value, message, warning_class):\n        self.value = value\n        self.message = message\n        self.warning_class = warning_class\n\n\nclass _ModuleWithDeprecations(object):\n    def __init__(self, module):\n        self.__dict__[\"_module\"] = module\n\n    def __getattr__(self, attr):\n        obj = getattr(self._module, attr)\n        if isinstance(obj, _DeprecatedValue):\n            warnings.warn(obj.message, obj.warning_class, stacklevel=2)\n            obj = obj.value\n        return obj\n\n    def __setattr__(self, attr, value):\n        setattr(self._module, attr, value)\n\n    def __dir__(self):\n        return [\"_module\"] + dir(self._module)\n\n\ndef deprecated(value, module_name, message, warning_class):\n    module = sys.modules[module_name]\n    if not isinstance(module, _ModuleWithDeprecations):\n        sys.modules[module_name] = module = _ModuleWithDeprecations(module)\n    return _DeprecatedValue(value, message, warning_class)\n", "path": "src/cryptography/utils.py"}, {"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport warnings\n\nfrom pyasn1.codec.der import decoder, encoder\nfrom pyasn1.error import PyAsn1Error\nfrom pyasn1.type import namedtype, univ\n\nimport six\n\nfrom cryptography import utils\n\n\nclass _DSSSigValue(univ.Sequence):\n    componentType = namedtype.NamedTypes(\n        namedtype.NamedType('r', univ.Integer()),\n        namedtype.NamedType('s', univ.Integer())\n    )\n\n\ndef decode_rfc6979_signature(signature):\n    warnings.warn(\n        \"decode_rfc6979_signature is deprecated and will \"\n        \"be removed in a future version, use decode_dss_signature instead \"\n        \"instead.\",\n        utils.DeprecatedIn10,\n        stacklevel=2\n    )\n    return decode_dss_signature(signature)\n\n\ndef decode_dss_signature(signature):\n    try:\n        data, remaining = decoder.decode(signature, asn1Spec=_DSSSigValue())\n    except PyAsn1Error:\n        raise ValueError(\"Invalid signature data. Unable to decode ASN.1\")\n\n    if remaining:\n        raise ValueError(\n            \"The signature contains bytes after the end of the ASN.1 sequence.\"\n        )\n\n    r = int(data.getComponentByName('r'))\n    s = int(data.getComponentByName('s'))\n    return (r, s)\n\n\ndef encode_rfc6979_signature(r, s):\n    warnings.warn(\n        \"encode_rfc6979_signature is deprecated and will \"\n        \"be removed in a future version, use encode_dss_signature instead \"\n        \"instead.\",\n        utils.DeprecatedIn10,\n        stacklevel=2\n    )\n    return encode_dss_signature(r, s)\n\n\ndef encode_dss_signature(r, s):\n    if (\n        not isinstance(r, six.integer_types) or\n        not isinstance(s, six.integer_types)\n    ):\n        raise ValueError(\"Both r and s must be integers\")\n\n    sig = _DSSSigValue()\n    sig.setComponentByName('r', r)\n    sig.setComponentByName('s', s)\n    return encoder.encode(sig)\n", "path": "src/cryptography/hazmat/primitives/asymmetric/utils.py"}]}