prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  OpenSSL's HMAC Context isn't marked as implementing MACContext
  It ought to be.
  
  
  --- 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/backends/commoncrypto/hmac.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 from cryptography import utils
  17 from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
  18 from cryptography.hazmat.primitives import interfaces
  19 
  20 
  21 @utils.register_interface(interfaces.HashContext)
  22 class _HMACContext(object):
  23     def __init__(self, backend, key, algorithm, ctx=None):
  24         self.algorithm = algorithm
  25         self._backend = backend
  26         if ctx is None:
  27             ctx = self._backend._ffi.new("CCHmacContext *")
  28             try:
  29                 alg = self._backend._supported_hmac_algorithms[algorithm.name]
  30             except KeyError:
  31                 raise UnsupportedAlgorithm(
  32                     "{0} is not a supported HMAC hash on this backend.".format(
  33                         algorithm.name),
  34                     _Reasons.UNSUPPORTED_HASH
  35                 )
  36 
  37             self._backend._lib.CCHmacInit(ctx, alg, key, len(key))
  38 
  39         self._ctx = ctx
  40         self._key = key
  41 
  42     def copy(self):
  43         copied_ctx = self._backend._ffi.new("CCHmacContext *")
  44         # CommonCrypto has no APIs for copying HMACs, so we have to copy the
  45         # underlying struct.
  46         copied_ctx[0] = self._ctx[0]
  47         return _HMACContext(
  48             self._backend, self._key, self.algorithm, ctx=copied_ctx
  49         )
  50 
  51     def update(self, data):
  52         self._backend._lib.CCHmacUpdate(self._ctx, data, len(data))
  53 
  54     def finalize(self):
  55         buf = self._backend._ffi.new("unsigned char[]",
  56                                      self.algorithm.digest_size)
  57         self._backend._lib.CCHmacFinal(self._ctx, buf)
  58         return self._backend._ffi.buffer(buf)[:]
  59
  ```
  
  Path: `cryptography/hazmat/backends/openssl/hmac.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 
  17 from cryptography import utils
  18 from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
  19 from cryptography.hazmat.primitives import interfaces
  20 
  21 
  22 @utils.register_interface(interfaces.HashContext)
  23 class _HMACContext(object):
  24     def __init__(self, backend, key, algorithm, ctx=None):
  25         self.algorithm = algorithm
  26         self._backend = backend
  27 
  28         if ctx is None:
  29             ctx = self._backend._ffi.new("HMAC_CTX *")
  30             self._backend._lib.HMAC_CTX_init(ctx)
  31             ctx = self._backend._ffi.gc(
  32                 ctx, self._backend._lib.HMAC_CTX_cleanup
  33             )
  34             evp_md = self._backend._lib.EVP_get_digestbyname(
  35                 algorithm.name.encode('ascii'))
  36             if evp_md == self._backend._ffi.NULL:
  37                 raise UnsupportedAlgorithm(
  38                     "{0} is not a supported hash on this backend.".format(
  39                         algorithm.name),
  40                     _Reasons.UNSUPPORTED_HASH
  41                 )
  42             res = self._backend._lib.Cryptography_HMAC_Init_ex(
  43                 ctx, key, len(key), evp_md, self._backend._ffi.NULL
  44             )
  45             assert res != 0
  46 
  47         self._ctx = ctx
  48         self._key = key
  49 
  50     def copy(self):
  51         copied_ctx = self._backend._ffi.new("HMAC_CTX *")
  52         self._backend._lib.HMAC_CTX_init(copied_ctx)
  53         copied_ctx = self._backend._ffi.gc(
  54             copied_ctx, self._backend._lib.HMAC_CTX_cleanup
  55         )
  56         res = self._backend._lib.Cryptography_HMAC_CTX_copy(
  57             copied_ctx, self._ctx
  58         )
  59         assert res != 0
  60         return _HMACContext(
  61             self._backend, self._key, self.algorithm, ctx=copied_ctx
  62         )
  63 
  64     def update(self, data):
  65         res = self._backend._lib.Cryptography_HMAC_Update(
  66             self._ctx, data, len(data)
  67         )
  68         assert res != 0
  69 
  70     def finalize(self):
  71         buf = self._backend._ffi.new("unsigned char[]",
  72                                      self._backend._lib.EVP_MAX_MD_SIZE)
  73         outlen = self._backend._ffi.new("unsigned int *")
  74         res = self._backend._lib.Cryptography_HMAC_Final(
  75             self._ctx, buf, outlen
  76         )
  77         assert res != 0
  78         assert outlen[0] == self.algorithm.digest_size
  79         self._backend._lib.HMAC_CTX_cleanup(self._ctx)
  80         return self._backend._ffi.buffer(buf)[:outlen[0]]
  81
  ```
  --- 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/backends/commoncrypto/hmac.py b/cryptography/hazmat/backends/commoncrypto/hmac.py
  --- a/cryptography/hazmat/backends/commoncrypto/hmac.py
  +++ b/cryptography/hazmat/backends/commoncrypto/hmac.py
  @@ -18,6 +18,7 @@
   from cryptography.hazmat.primitives import interfaces
   
   
  +@utils.register_interface(interfaces.MACContext)
   @utils.register_interface(interfaces.HashContext)
   class _HMACContext(object):
       def __init__(self, backend, key, algorithm, ctx=None):
  diff --git a/cryptography/hazmat/backends/openssl/hmac.py b/cryptography/hazmat/backends/openssl/hmac.py
  --- a/cryptography/hazmat/backends/openssl/hmac.py
  +++ b/cryptography/hazmat/backends/openssl/hmac.py
  @@ -19,6 +19,7 @@
   from cryptography.hazmat.primitives import interfaces
   
   
  +@utils.register_interface(interfaces.MACContext)
   @utils.register_interface(interfaces.HashContext)
   class _HMACContext(object):
       def __init__(self, backend, key, algorithm, ctx=None):
  
verification_info: {"golden_diff": "diff --git a/cryptography/hazmat/backends/commoncrypto/hmac.py b/cryptography/hazmat/backends/commoncrypto/hmac.py\n--- a/cryptography/hazmat/backends/commoncrypto/hmac.py\n+++ b/cryptography/hazmat/backends/commoncrypto/hmac.py\n@@ -18,6 +18,7 @@\n from cryptography.hazmat.primitives import interfaces\n \n \n+@utils.register_interface(interfaces.MACContext)\n @utils.register_interface(interfaces.HashContext)\n class _HMACContext(object):\n     def __init__(self, backend, key, algorithm, ctx=None):\ndiff --git a/cryptography/hazmat/backends/openssl/hmac.py b/cryptography/hazmat/backends/openssl/hmac.py\n--- a/cryptography/hazmat/backends/openssl/hmac.py\n+++ b/cryptography/hazmat/backends/openssl/hmac.py\n@@ -19,6 +19,7 @@\n from cryptography.hazmat.primitives import interfaces\n \n \n+@utils.register_interface(interfaces.MACContext)\n @utils.register_interface(interfaces.HashContext)\n class _HMACContext(object):\n     def __init__(self, backend, key, algorithm, ctx=None):\n", "issue": "OpenSSL's HMAC Context isn't marked as implementing MACContext\nIt ought to be.\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\nfrom cryptography import utils\nfrom cryptography.exceptions import UnsupportedAlgorithm, _Reasons\nfrom cryptography.hazmat.primitives import interfaces\n\n\n@utils.register_interface(interfaces.HashContext)\nclass _HMACContext(object):\n    def __init__(self, backend, key, algorithm, ctx=None):\n        self.algorithm = algorithm\n        self._backend = backend\n        if ctx is None:\n            ctx = self._backend._ffi.new(\"CCHmacContext *\")\n            try:\n                alg = self._backend._supported_hmac_algorithms[algorithm.name]\n            except KeyError:\n                raise UnsupportedAlgorithm(\n                    \"{0} is not a supported HMAC hash on this backend.\".format(\n                        algorithm.name),\n                    _Reasons.UNSUPPORTED_HASH\n                )\n\n            self._backend._lib.CCHmacInit(ctx, alg, key, len(key))\n\n        self._ctx = ctx\n        self._key = key\n\n    def copy(self):\n        copied_ctx = self._backend._ffi.new(\"CCHmacContext *\")\n        # CommonCrypto has no APIs for copying HMACs, so we have to copy the\n        # underlying struct.\n        copied_ctx[0] = self._ctx[0]\n        return _HMACContext(\n            self._backend, self._key, self.algorithm, ctx=copied_ctx\n        )\n\n    def update(self, data):\n        self._backend._lib.CCHmacUpdate(self._ctx, data, len(data))\n\n    def finalize(self):\n        buf = self._backend._ffi.new(\"unsigned char[]\",\n                                     self.algorithm.digest_size)\n        self._backend._lib.CCHmacFinal(self._ctx, buf)\n        return self._backend._ffi.buffer(buf)[:]\n", "path": "cryptography/hazmat/backends/commoncrypto/hmac.py"}, {"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\n\nfrom cryptography import utils\nfrom cryptography.exceptions import UnsupportedAlgorithm, _Reasons\nfrom cryptography.hazmat.primitives import interfaces\n\n\n@utils.register_interface(interfaces.HashContext)\nclass _HMACContext(object):\n    def __init__(self, backend, key, algorithm, ctx=None):\n        self.algorithm = algorithm\n        self._backend = backend\n\n        if ctx is None:\n            ctx = self._backend._ffi.new(\"HMAC_CTX *\")\n            self._backend._lib.HMAC_CTX_init(ctx)\n            ctx = self._backend._ffi.gc(\n                ctx, self._backend._lib.HMAC_CTX_cleanup\n            )\n            evp_md = self._backend._lib.EVP_get_digestbyname(\n                algorithm.name.encode('ascii'))\n            if evp_md == self._backend._ffi.NULL:\n                raise UnsupportedAlgorithm(\n                    \"{0} is not a supported hash on this backend.\".format(\n                        algorithm.name),\n                    _Reasons.UNSUPPORTED_HASH\n                )\n            res = self._backend._lib.Cryptography_HMAC_Init_ex(\n                ctx, key, len(key), evp_md, self._backend._ffi.NULL\n            )\n            assert res != 0\n\n        self._ctx = ctx\n        self._key = key\n\n    def copy(self):\n        copied_ctx = self._backend._ffi.new(\"HMAC_CTX *\")\n        self._backend._lib.HMAC_CTX_init(copied_ctx)\n        copied_ctx = self._backend._ffi.gc(\n            copied_ctx, self._backend._lib.HMAC_CTX_cleanup\n        )\n        res = self._backend._lib.Cryptography_HMAC_CTX_copy(\n            copied_ctx, self._ctx\n        )\n        assert res != 0\n        return _HMACContext(\n            self._backend, self._key, self.algorithm, ctx=copied_ctx\n        )\n\n    def update(self, data):\n        res = self._backend._lib.Cryptography_HMAC_Update(\n            self._ctx, data, len(data)\n        )\n        assert res != 0\n\n    def finalize(self):\n        buf = self._backend._ffi.new(\"unsigned char[]\",\n                                     self._backend._lib.EVP_MAX_MD_SIZE)\n        outlen = self._backend._ffi.new(\"unsigned int *\")\n        res = self._backend._lib.Cryptography_HMAC_Final(\n            self._ctx, buf, outlen\n        )\n        assert res != 0\n        assert outlen[0] == self.algorithm.digest_size\n        self._backend._lib.HMAC_CTX_cleanup(self._ctx)\n        return self._backend._ffi.buffer(buf)[:outlen[0]]\n", "path": "cryptography/hazmat/backends/openssl/hmac.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\nfrom cryptography import utils\nfrom cryptography.exceptions import UnsupportedAlgorithm, _Reasons\nfrom cryptography.hazmat.primitives import interfaces\n\n\n@utils.register_interface(interfaces.MACContext)\n@utils.register_interface(interfaces.HashContext)\nclass _HMACContext(object):\n    def __init__(self, backend, key, algorithm, ctx=None):\n        self.algorithm = algorithm\n        self._backend = backend\n        if ctx is None:\n            ctx = self._backend._ffi.new(\"CCHmacContext *\")\n            try:\n                alg = self._backend._supported_hmac_algorithms[algorithm.name]\n            except KeyError:\n                raise UnsupportedAlgorithm(\n                    \"{0} is not a supported HMAC hash on this backend.\".format(\n                        algorithm.name),\n                    _Reasons.UNSUPPORTED_HASH\n                )\n\n            self._backend._lib.CCHmacInit(ctx, alg, key, len(key))\n\n        self._ctx = ctx\n        self._key = key\n\n    def copy(self):\n        copied_ctx = self._backend._ffi.new(\"CCHmacContext *\")\n        # CommonCrypto has no APIs for copying HMACs, so we have to copy the\n        # underlying struct.\n        copied_ctx[0] = self._ctx[0]\n        return _HMACContext(\n            self._backend, self._key, self.algorithm, ctx=copied_ctx\n        )\n\n    def update(self, data):\n        self._backend._lib.CCHmacUpdate(self._ctx, data, len(data))\n\n    def finalize(self):\n        buf = self._backend._ffi.new(\"unsigned char[]\",\n                                     self.algorithm.digest_size)\n        self._backend._lib.CCHmacFinal(self._ctx, buf)\n        return self._backend._ffi.buffer(buf)[:]\n", "path": "cryptography/hazmat/backends/commoncrypto/hmac.py"}, {"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\n\nfrom cryptography import utils\nfrom cryptography.exceptions import UnsupportedAlgorithm, _Reasons\nfrom cryptography.hazmat.primitives import interfaces\n\n\n@utils.register_interface(interfaces.MACContext)\n@utils.register_interface(interfaces.HashContext)\nclass _HMACContext(object):\n    def __init__(self, backend, key, algorithm, ctx=None):\n        self.algorithm = algorithm\n        self._backend = backend\n\n        if ctx is None:\n            ctx = self._backend._ffi.new(\"HMAC_CTX *\")\n            self._backend._lib.HMAC_CTX_init(ctx)\n            ctx = self._backend._ffi.gc(\n                ctx, self._backend._lib.HMAC_CTX_cleanup\n            )\n            evp_md = self._backend._lib.EVP_get_digestbyname(\n                algorithm.name.encode('ascii'))\n            if evp_md == self._backend._ffi.NULL:\n                raise UnsupportedAlgorithm(\n                    \"{0} is not a supported hash on this backend.\".format(\n                        algorithm.name),\n                    _Reasons.UNSUPPORTED_HASH\n                )\n            res = self._backend._lib.Cryptography_HMAC_Init_ex(\n                ctx, key, len(key), evp_md, self._backend._ffi.NULL\n            )\n            assert res != 0\n\n        self._ctx = ctx\n        self._key = key\n\n    def copy(self):\n        copied_ctx = self._backend._ffi.new(\"HMAC_CTX *\")\n        self._backend._lib.HMAC_CTX_init(copied_ctx)\n        copied_ctx = self._backend._ffi.gc(\n            copied_ctx, self._backend._lib.HMAC_CTX_cleanup\n        )\n        res = self._backend._lib.Cryptography_HMAC_CTX_copy(\n            copied_ctx, self._ctx\n        )\n        assert res != 0\n        return _HMACContext(\n            self._backend, self._key, self.algorithm, ctx=copied_ctx\n        )\n\n    def update(self, data):\n        res = self._backend._lib.Cryptography_HMAC_Update(\n            self._ctx, data, len(data)\n        )\n        assert res != 0\n\n    def finalize(self):\n        buf = self._backend._ffi.new(\"unsigned char[]\",\n                                     self._backend._lib.EVP_MAX_MD_SIZE)\n        outlen = self._backend._ffi.new(\"unsigned int *\")\n        res = self._backend._lib.Cryptography_HMAC_Final(\n            self._ctx, buf, outlen\n        )\n        assert res != 0\n        assert outlen[0] == self.algorithm.digest_size\n        self._backend._lib.HMAC_CTX_cleanup(self._ctx)\n        return self._backend._ffi.buffer(buf)[:outlen[0]]\n", "path": "cryptography/hazmat/backends/openssl/hmac.py"}]}