prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  dsa_private_key.pem vector has p and q whose lengths we don't normally allow
  We currently enforce that `p` and `q` have lengths which are one of:
  - `(1024, 160)`
  - `(2048, 256)`
  - `(3072, 256)`
  
  However, this vector has `(p, q)` with lengths of `(2048, 160)`. Do we need to be less restrictive, use a different vector?
  
  This was discovered in the process of writing a pure python PEM loader.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `cryptography/hazmat/primitives/asymmetric/dsa.py`
  Content:
  ```
  1 # Licensed under the Apache License, Version 2.0 (the "License");
  2 # you may not use this file except in compliance with the License.
  3 # You may obtain a copy of the License at
  4 #
  5 #    http://www.apache.org/licenses/LICENSE-2.0
  6 #
  7 # Unless required by applicable law or agreed to in writing, software
  8 # distributed under the License is distributed on an "AS IS" BASIS,
  9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10 # implied.
  11 # See the License for the specific language governing permissions and
  12 # limitations under the License.
  13 
  14 from __future__ import absolute_import, division, print_function
  15 
  16 import six
  17 
  18 from cryptography import utils
  19 
  20 
  21 def generate_parameters(key_size, backend):
  22     return backend.generate_dsa_parameters(key_size)
  23 
  24 
  25 def generate_private_key(key_size, backend):
  26     return backend.generate_dsa_private_key_and_parameters(key_size)
  27 
  28 
  29 def _check_dsa_parameters(parameters):
  30     if (utils.bit_length(parameters.p),
  31         utils.bit_length(parameters.q)) not in (
  32             (1024, 160),
  33             (2048, 256),
  34             (3072, 256)):
  35         raise ValueError(
  36             "p and q's bit-lengths must be one of these pairs (1024, 160), "
  37             "(2048, 256), or (3072, 256). Not ({0:d}, {1:d})".format(
  38                 utils.bit_length(parameters.p), utils.bit_length(parameters.q)
  39             )
  40         )
  41 
  42     if not (1 < parameters.g < parameters.p):
  43         raise ValueError("g, p don't satisfy 1 < g < p.")
  44 
  45 
  46 def _check_dsa_private_numbers(numbers):
  47     parameters = numbers.public_numbers.parameter_numbers
  48     _check_dsa_parameters(parameters)
  49     if numbers.x <= 0 or numbers.x >= parameters.q:
  50         raise ValueError("x must be > 0 and < q.")
  51 
  52     if numbers.public_numbers.y != pow(parameters.g, numbers.x, parameters.p):
  53         raise ValueError("y must be equal to (g ** x % p).")
  54 
  55 
  56 class DSAParameterNumbers(object):
  57     def __init__(self, p, q, g):
  58         if (
  59             not isinstance(p, six.integer_types) or
  60             not isinstance(q, six.integer_types) or
  61             not isinstance(g, six.integer_types)
  62         ):
  63             raise TypeError(
  64                 "DSAParameterNumbers p, q, and g arguments must be integers."
  65             )
  66 
  67         self._p = p
  68         self._q = q
  69         self._g = g
  70 
  71     @property
  72     def p(self):
  73         return self._p
  74 
  75     @property
  76     def q(self):
  77         return self._q
  78 
  79     @property
  80     def g(self):
  81         return self._g
  82 
  83     def parameters(self, backend):
  84         return backend.load_dsa_parameter_numbers(self)
  85 
  86 
  87 class DSAPublicNumbers(object):
  88     def __init__(self, y, parameter_numbers):
  89         if not isinstance(y, six.integer_types):
  90             raise TypeError("DSAPublicNumbers y argument must be an integer.")
  91 
  92         if not isinstance(parameter_numbers, DSAParameterNumbers):
  93             raise TypeError(
  94                 "parameter_numbers must be a DSAParameterNumbers instance."
  95             )
  96 
  97         self._y = y
  98         self._parameter_numbers = parameter_numbers
  99 
  100     @property
  101     def y(self):
  102         return self._y
  103 
  104     @property
  105     def parameter_numbers(self):
  106         return self._parameter_numbers
  107 
  108     def public_key(self, backend):
  109         return backend.load_dsa_public_numbers(self)
  110 
  111 
  112 class DSAPrivateNumbers(object):
  113     def __init__(self, x, public_numbers):
  114         if not isinstance(x, six.integer_types):
  115             raise TypeError("DSAPrivateNumbers x argument must be an integer.")
  116 
  117         if not isinstance(public_numbers, DSAPublicNumbers):
  118             raise TypeError(
  119                 "public_numbers must be a DSAPublicNumbers instance."
  120             )
  121         self._public_numbers = public_numbers
  122         self._x = x
  123 
  124     @property
  125     def x(self):
  126         return self._x
  127 
  128     @property
  129     def public_numbers(self):
  130         return self._public_numbers
  131 
  132     def private_key(self, backend):
  133         return backend.load_dsa_private_numbers(self)
  134
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/cryptography/hazmat/primitives/asymmetric/dsa.py b/cryptography/hazmat/primitives/asymmetric/dsa.py
  --- a/cryptography/hazmat/primitives/asymmetric/dsa.py
  +++ b/cryptography/hazmat/primitives/asymmetric/dsa.py
  @@ -27,17 +27,10 @@
   
   
   def _check_dsa_parameters(parameters):
  -    if (utils.bit_length(parameters.p),
  -        utils.bit_length(parameters.q)) not in (
  -            (1024, 160),
  -            (2048, 256),
  -            (3072, 256)):
  -        raise ValueError(
  -            "p and q's bit-lengths must be one of these pairs (1024, 160), "
  -            "(2048, 256), or (3072, 256). Not ({0:d}, {1:d})".format(
  -                utils.bit_length(parameters.p), utils.bit_length(parameters.q)
  -            )
  -        )
  +    if utils.bit_length(parameters.p) not in [1024, 2048, 3072]:
  +        raise ValueError("p must be exactly 1024, 2048, or 3072 bits long")
  +    if utils.bit_length(parameters.q) not in [160, 256]:
  +        raise ValueError("q must be exactly 160 or 256 bits long")
   
       if not (1 < parameters.g < parameters.p):
           raise ValueError("g, p don't satisfy 1 < g < p.")
  
verification_info: {"golden_diff": "diff --git a/cryptography/hazmat/primitives/asymmetric/dsa.py b/cryptography/hazmat/primitives/asymmetric/dsa.py\n--- a/cryptography/hazmat/primitives/asymmetric/dsa.py\n+++ b/cryptography/hazmat/primitives/asymmetric/dsa.py\n@@ -27,17 +27,10 @@\n \n \n def _check_dsa_parameters(parameters):\n-    if (utils.bit_length(parameters.p),\n-        utils.bit_length(parameters.q)) not in (\n-            (1024, 160),\n-            (2048, 256),\n-            (3072, 256)):\n-        raise ValueError(\n-            \"p and q's bit-lengths must be one of these pairs (1024, 160), \"\n-            \"(2048, 256), or (3072, 256). Not ({0:d}, {1:d})\".format(\n-                utils.bit_length(parameters.p), utils.bit_length(parameters.q)\n-            )\n-        )\n+    if utils.bit_length(parameters.p) not in [1024, 2048, 3072]:\n+        raise ValueError(\"p must be exactly 1024, 2048, or 3072 bits long\")\n+    if utils.bit_length(parameters.q) not in [160, 256]:\n+        raise ValueError(\"q must be exactly 160 or 256 bits long\")\n \n     if not (1 < parameters.g < parameters.p):\n         raise ValueError(\"g, p don't satisfy 1 < g < p.\")\n", "issue": "dsa_private_key.pem vector has p and q whose lengths we don't normally allow\nWe currently enforce that `p` and `q` have lengths which are one of:\n- `(1024, 160)`\n- `(2048, 256)`\n- `(3072, 256)`\n\nHowever, this vector has `(p, q)` with lengths of `(2048, 160)`. Do we need to be less restrictive, use a different vector?\n\nThis was discovered in the process of writing a pure python PEM loader.\n\n", "before_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n# implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport six\n\nfrom cryptography import utils\n\n\ndef generate_parameters(key_size, backend):\n    return backend.generate_dsa_parameters(key_size)\n\n\ndef generate_private_key(key_size, backend):\n    return backend.generate_dsa_private_key_and_parameters(key_size)\n\n\ndef _check_dsa_parameters(parameters):\n    if (utils.bit_length(parameters.p),\n        utils.bit_length(parameters.q)) not in (\n            (1024, 160),\n            (2048, 256),\n            (3072, 256)):\n        raise ValueError(\n            \"p and q's bit-lengths must be one of these pairs (1024, 160), \"\n            \"(2048, 256), or (3072, 256). Not ({0:d}, {1:d})\".format(\n                utils.bit_length(parameters.p), utils.bit_length(parameters.q)\n            )\n        )\n\n    if not (1 < parameters.g < parameters.p):\n        raise ValueError(\"g, p don't satisfy 1 < g < p.\")\n\n\ndef _check_dsa_private_numbers(numbers):\n    parameters = numbers.public_numbers.parameter_numbers\n    _check_dsa_parameters(parameters)\n    if numbers.x <= 0 or numbers.x >= parameters.q:\n        raise ValueError(\"x must be > 0 and < q.\")\n\n    if numbers.public_numbers.y != pow(parameters.g, numbers.x, parameters.p):\n        raise ValueError(\"y must be equal to (g ** x % p).\")\n\n\nclass DSAParameterNumbers(object):\n    def __init__(self, p, q, g):\n        if (\n            not isinstance(p, six.integer_types) or\n            not isinstance(q, six.integer_types) or\n            not isinstance(g, six.integer_types)\n        ):\n            raise TypeError(\n                \"DSAParameterNumbers p, q, and g arguments must be integers.\"\n            )\n\n        self._p = p\n        self._q = q\n        self._g = g\n\n    @property\n    def p(self):\n        return self._p\n\n    @property\n    def q(self):\n        return self._q\n\n    @property\n    def g(self):\n        return self._g\n\n    def parameters(self, backend):\n        return backend.load_dsa_parameter_numbers(self)\n\n\nclass DSAPublicNumbers(object):\n    def __init__(self, y, parameter_numbers):\n        if not isinstance(y, six.integer_types):\n            raise TypeError(\"DSAPublicNumbers y argument must be an integer.\")\n\n        if not isinstance(parameter_numbers, DSAParameterNumbers):\n            raise TypeError(\n                \"parameter_numbers must be a DSAParameterNumbers instance.\"\n            )\n\n        self._y = y\n        self._parameter_numbers = parameter_numbers\n\n    @property\n    def y(self):\n        return self._y\n\n    @property\n    def parameter_numbers(self):\n        return self._parameter_numbers\n\n    def public_key(self, backend):\n        return backend.load_dsa_public_numbers(self)\n\n\nclass DSAPrivateNumbers(object):\n    def __init__(self, x, public_numbers):\n        if not isinstance(x, six.integer_types):\n            raise TypeError(\"DSAPrivateNumbers x argument must be an integer.\")\n\n        if not isinstance(public_numbers, DSAPublicNumbers):\n            raise TypeError(\n                \"public_numbers must be a DSAPublicNumbers instance.\"\n            )\n        self._public_numbers = public_numbers\n        self._x = x\n\n    @property\n    def x(self):\n        return self._x\n\n    @property\n    def public_numbers(self):\n        return self._public_numbers\n\n    def private_key(self, backend):\n        return backend.load_dsa_private_numbers(self)\n", "path": "cryptography/hazmat/primitives/asymmetric/dsa.py"}], "after_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n# implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport six\n\nfrom cryptography import utils\n\n\ndef generate_parameters(key_size, backend):\n    return backend.generate_dsa_parameters(key_size)\n\n\ndef generate_private_key(key_size, backend):\n    return backend.generate_dsa_private_key_and_parameters(key_size)\n\n\ndef _check_dsa_parameters(parameters):\n    if utils.bit_length(parameters.p) not in [1024, 2048, 3072]:\n        raise ValueError(\"p must be exactly 1024, 2048, or 3072 bits long\")\n    if utils.bit_length(parameters.q) not in [160, 256]:\n        raise ValueError(\"q must be exactly 160 or 256 bits long\")\n\n    if not (1 < parameters.g < parameters.p):\n        raise ValueError(\"g, p don't satisfy 1 < g < p.\")\n\n\ndef _check_dsa_private_numbers(numbers):\n    parameters = numbers.public_numbers.parameter_numbers\n    _check_dsa_parameters(parameters)\n    if numbers.x <= 0 or numbers.x >= parameters.q:\n        raise ValueError(\"x must be > 0 and < q.\")\n\n    if numbers.public_numbers.y != pow(parameters.g, numbers.x, parameters.p):\n        raise ValueError(\"y must be equal to (g ** x % p).\")\n\n\nclass DSAParameterNumbers(object):\n    def __init__(self, p, q, g):\n        if (\n            not isinstance(p, six.integer_types) or\n            not isinstance(q, six.integer_types) or\n            not isinstance(g, six.integer_types)\n        ):\n            raise TypeError(\n                \"DSAParameterNumbers p, q, and g arguments must be integers.\"\n            )\n\n        self._p = p\n        self._q = q\n        self._g = g\n\n    @property\n    def p(self):\n        return self._p\n\n    @property\n    def q(self):\n        return self._q\n\n    @property\n    def g(self):\n        return self._g\n\n    def parameters(self, backend):\n        return backend.load_dsa_parameter_numbers(self)\n\n\nclass DSAPublicNumbers(object):\n    def __init__(self, y, parameter_numbers):\n        if not isinstance(y, six.integer_types):\n            raise TypeError(\"DSAPublicNumbers y argument must be an integer.\")\n\n        if not isinstance(parameter_numbers, DSAParameterNumbers):\n            raise TypeError(\n                \"parameter_numbers must be a DSAParameterNumbers instance.\"\n            )\n\n        self._y = y\n        self._parameter_numbers = parameter_numbers\n\n    @property\n    def y(self):\n        return self._y\n\n    @property\n    def parameter_numbers(self):\n        return self._parameter_numbers\n\n    def public_key(self, backend):\n        return backend.load_dsa_public_numbers(self)\n\n\nclass DSAPrivateNumbers(object):\n    def __init__(self, x, public_numbers):\n        if not isinstance(x, six.integer_types):\n            raise TypeError(\"DSAPrivateNumbers x argument must be an integer.\")\n\n        if not isinstance(public_numbers, DSAPublicNumbers):\n            raise TypeError(\n                \"public_numbers must be a DSAPublicNumbers instance.\"\n            )\n        self._public_numbers = public_numbers\n        self._x = x\n\n    @property\n    def x(self):\n        return self._x\n\n    @property\n    def public_numbers(self):\n        return self._public_numbers\n\n    def private_key(self, backend):\n        return backend.load_dsa_private_numbers(self)\n", "path": "cryptography/hazmat/primitives/asymmetric/dsa.py"}]}