py2docfx 0.1.16.dev2064350__py3-none-any.whl → 0.1.17__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. py2docfx/convert_prepare/environment.py +1 -3
  2. py2docfx/convert_prepare/get_source.py +1 -6
  3. py2docfx/convert_prepare/package_info.py +1 -1
  4. py2docfx/docfx_yaml/miss_reference.py +1 -1
  5. py2docfx/docfx_yaml/parameter_utils.py +58 -6
  6. py2docfx/docfx_yaml/tests/roots/test-translator-typing/code_with_typing.py +14 -0
  7. py2docfx/docfx_yaml/tests/roots/test-translator-typing/conf.py +18 -0
  8. py2docfx/docfx_yaml/tests/test_translator_typing.py +39 -0
  9. py2docfx/docfx_yaml/utils.py +2 -2
  10. py2docfx/venv/basevenv/Lib/site-packages/certifi/__init__.py +1 -1
  11. py2docfx/venv/basevenv/Lib/site-packages/certifi/core.py +1 -32
  12. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/cli/__main__.py +62 -2
  13. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/constant.py +17 -0
  14. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/legacy.py +1 -3
  15. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/md.py +19 -14
  16. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/utils.py +6 -0
  17. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/version.py +1 -1
  18. py2docfx/venv/basevenv/Lib/site-packages/packaging/__init__.py +1 -1
  19. py2docfx/venv/basevenv/Lib/site-packages/packaging/_elffile.py +1 -2
  20. py2docfx/venv/basevenv/Lib/site-packages/packaging/_manylinux.py +1 -2
  21. py2docfx/venv/basevenv/Lib/site-packages/packaging/_parser.py +1 -2
  22. py2docfx/venv/basevenv/Lib/site-packages/packaging/_tokenizer.py +5 -4
  23. py2docfx/venv/basevenv/Lib/site-packages/packaging/licenses/__init__.py +1 -1
  24. py2docfx/venv/basevenv/Lib/site-packages/packaging/markers.py +53 -22
  25. py2docfx/venv/basevenv/Lib/site-packages/packaging/metadata.py +1 -2
  26. py2docfx/venv/basevenv/Lib/site-packages/packaging/specifiers.py +1 -2
  27. py2docfx/venv/basevenv/Lib/site-packages/packaging/tags.py +39 -0
  28. py2docfx/venv/basevenv/Lib/site-packages/pkg_resources/__init__.py +6 -7
  29. py2docfx/venv/basevenv/Lib/site-packages/pygments/__init__.py +1 -1
  30. py2docfx/venv/basevenv/Lib/site-packages/pygments/lexers/_sql_builtins.py +106 -0
  31. py2docfx/venv/basevenv/Lib/site-packages/pygments/lexers/scripting.py +5 -3
  32. py2docfx/venv/basevenv/Lib/site-packages/pygments/lexers/sql.py +24 -118
  33. py2docfx/venv/basevenv/Lib/site-packages/requests/__version__.py +2 -2
  34. py2docfx/venv/basevenv/Lib/site-packages/requests/compat.py +12 -0
  35. py2docfx/venv/basevenv/Lib/site-packages/requests/models.py +3 -1
  36. py2docfx/venv/basevenv/Lib/site-packages/requests/utils.py +6 -16
  37. py2docfx/venv/basevenv/Lib/site-packages/setuptools/__init__.py +0 -38
  38. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_discovery.py +33 -0
  39. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_distutils/command/build_scripts.py +1 -1
  40. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_distutils/command/config.py +0 -2
  41. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_unix.py +63 -0
  42. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_distutils/compilers/C/unix.py +5 -6
  43. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_entry_points.py +4 -0
  44. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_normalization.py +0 -2
  45. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_path.py +12 -3
  46. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_reqs.py +1 -1
  47. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_scripts.py +361 -0
  48. py2docfx/venv/basevenv/Lib/site-packages/setuptools/_shutil.py +6 -0
  49. py2docfx/venv/basevenv/Lib/site-packages/setuptools/build_meta.py +25 -37
  50. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/bdist_egg.py +9 -11
  51. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/bdist_wheel.py +1 -1
  52. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/build_ext.py +29 -28
  53. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/develop.py +39 -179
  54. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/easy_install.py +17 -2352
  55. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/editable_wheel.py +14 -31
  56. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/egg_info.py +0 -2
  57. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/install.py +3 -55
  58. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/install_scripts.py +5 -11
  59. py2docfx/venv/basevenv/Lib/site-packages/setuptools/command/sdist.py +1 -1
  60. py2docfx/venv/basevenv/Lib/site-packages/setuptools/compat/py310.py +11 -0
  61. py2docfx/venv/basevenv/Lib/site-packages/setuptools/dist.py +10 -12
  62. py2docfx/venv/basevenv/Lib/site-packages/setuptools/installer.py +34 -29
  63. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/contexts.py +0 -14
  64. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/fixtures.py +235 -0
  65. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/integration/test_pbr.py +20 -0
  66. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_build_meta.py +0 -24
  67. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_develop.py +1 -64
  68. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_dist.py +2 -2
  69. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_dist_info.py +0 -63
  70. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_editable_install.py +15 -41
  71. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_egg_info.py +3 -2
  72. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_scripts.py +12 -0
  73. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_wheel.py +12 -36
  74. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_windows_wrappers.py +3 -4
  75. py2docfx/venv/basevenv/Lib/site-packages/setuptools/wheel.py +49 -24
  76. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/__init__.py +6 -0
  77. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/arabic_stemmer.py +798 -797
  78. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/armenian_stemmer.py +212 -213
  79. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/basestemmer.py +20 -54
  80. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/basque_stemmer.py +202 -228
  81. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/catalan_stemmer.py +370 -375
  82. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/danish_stemmer.py +63 -61
  83. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/dutch_porter_stemmer.py +466 -0
  84. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/dutch_stemmer.py +1217 -343
  85. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/english_stemmer.py +295 -264
  86. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/esperanto_stemmer.py +588 -0
  87. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/estonian_stemmer.py +850 -0
  88. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/finnish_stemmer.py +144 -143
  89. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/french_stemmer.py +308 -246
  90. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/german_stemmer.py +224 -167
  91. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/greek_stemmer.py +1314 -1313
  92. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/hindi_stemmer.py +39 -38
  93. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/hungarian_stemmer.py +231 -256
  94. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/indonesian_stemmer.py +61 -64
  95. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/irish_stemmer.py +101 -106
  96. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/italian_stemmer.py +272 -272
  97. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/lithuanian_stemmer.py +233 -240
  98. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/nepali_stemmer.py +108 -134
  99. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/norwegian_stemmer.py +108 -63
  100. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/porter_stemmer.py +101 -108
  101. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/portuguese_stemmer.py +241 -250
  102. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/romanian_stemmer.py +332 -296
  103. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/russian_stemmer.py +178 -179
  104. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/serbian_stemmer.py +2331 -2332
  105. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/spanish_stemmer.py +254 -259
  106. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/swedish_stemmer.py +143 -70
  107. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/tamil_stemmer.py +638 -1491
  108. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/turkish_stemmer.py +326 -292
  109. py2docfx/venv/basevenv/Lib/site-packages/snowballstemmer/yiddish_stemmer.py +245 -246
  110. py2docfx/venv/basevenv/Lib/site-packages/urllib3/_version.py +2 -2
  111. py2docfx/venv/basevenv/Lib/site-packages/urllib3/connection.py +87 -38
  112. py2docfx/venv/basevenv/Lib/site-packages/urllib3/contrib/emscripten/fetch.py +20 -0
  113. py2docfx/venv/basevenv/Lib/site-packages/urllib3/poolmanager.py +17 -1
  114. py2docfx/venv/basevenv/Lib/site-packages/urllib3/response.py +53 -24
  115. py2docfx/venv/basevenv/Lib/site-packages/urllib3/util/request.py +12 -4
  116. py2docfx/venv/basevenv/Lib/site-packages/urllib3/util/ssl_.py +1 -1
  117. py2docfx/venv/venv1/Lib/site-packages/azure/core/_version.py +1 -1
  118. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/_base_async.py +1 -1
  119. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/transport/_aiohttp.py +1 -1
  120. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/transport/_base_async.py +2 -1
  121. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/transport/_requests_asyncio.py +1 -1
  122. py2docfx/venv/venv1/Lib/site-packages/azure/core/rest/_aiohttp.py +2 -2
  123. py2docfx/venv/venv1/Lib/site-packages/azure/core/rest/_requests_asyncio.py +1 -1
  124. py2docfx/venv/venv1/Lib/site-packages/azure/core/tracing/opentelemetry.py +13 -1
  125. py2docfx/venv/venv1/Lib/site-packages/azure/core/utils/_pipeline_transport_rest_shared_async.py +2 -1
  126. py2docfx/venv/venv1/Lib/site-packages/azure/core/utils/_utils.py +1 -1
  127. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_constants.py +1 -0
  128. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +23 -2
  129. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/environment.py +12 -16
  130. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/service_fabric.py +22 -1
  131. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/user_password.py +10 -6
  132. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/vscode.py +13 -4
  133. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/auth_code_redirect_handler.py +3 -5
  134. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_client.py +2 -1
  135. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_persistent_cache.py +3 -2
  136. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
  137. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azd_cli.py +1 -1
  138. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_cli.py +1 -1
  139. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_powershell.py +1 -1
  140. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/chained.py +1 -1
  141. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +22 -2
  142. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/environment.py +2 -2
  143. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/service_fabric.py +17 -1
  144. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/vscode.py +4 -4
  145. py2docfx/venv/venv1/Lib/site-packages/certifi/__init__.py +1 -1
  146. py2docfx/venv/venv1/Lib/site-packages/certifi/core.py +1 -32
  147. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/cli/__main__.py +62 -2
  148. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/constant.py +17 -0
  149. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/legacy.py +1 -3
  150. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/md.py +19 -14
  151. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/utils.py +6 -0
  152. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/version.py +1 -1
  153. py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +2 -2
  154. py2docfx/venv/venv1/Lib/site-packages/cryptography/__init__.py +2 -2
  155. py2docfx/venv/venv1/Lib/site-packages/cryptography/fernet.py +2 -1
  156. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/_oid.py +35 -2
  157. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/backends/openssl/backend.py +33 -10
  158. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/__init__.pyi +14 -5
  159. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/ocsp.pyi +2 -2
  160. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/__init__.pyi +3 -0
  161. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/aead.pyi +49 -45
  162. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/ciphers.pyi +2 -2
  163. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed25519.pyi +2 -1
  164. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed448.pyi +2 -1
  165. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/hashes.pyi +10 -1
  166. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/hmac.pyi +3 -2
  167. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/kdf.pyi +8 -2
  168. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/keys.pyi +3 -2
  169. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/poly1305.pyi +6 -4
  170. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/x25519.pyi +2 -1
  171. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/x448.pyi +2 -1
  172. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/pkcs12.pyi +9 -3
  173. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/pkcs7.pyi +7 -6
  174. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/test_support.pyi +2 -1
  175. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/x509.pyi +79 -12
  176. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/openssl/_conditional.py +9 -1
  177. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/openssl/binding.py +2 -1
  178. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/decrepit/ciphers/algorithms.py +5 -0
  179. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/_cipheralgorithm.py +4 -2
  180. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/_serialization.py +1 -2
  181. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/dh.py +12 -0
  182. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py +16 -3
  183. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py +47 -3
  184. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/ed25519.py +16 -3
  185. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py +16 -3
  186. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py +14 -0
  187. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py +14 -1
  188. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/x448.py +14 -1
  189. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py +6 -6
  190. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/ciphers/base.py +5 -4
  191. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/ciphers/modes.py +18 -18
  192. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/hashes.py +5 -1
  193. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.py +5 -4
  194. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/hkdf.py +4 -4
  195. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/kbkdf.py +7 -4
  196. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/pbkdf2.py +1 -1
  197. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/x963kdf.py +1 -1
  198. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/padding.py +7 -121
  199. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/serialization/__init__.py +2 -0
  200. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/serialization/pkcs12.py +21 -1
  201. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/serialization/pkcs7.py +48 -6
  202. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/serialization/ssh.py +68 -18
  203. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/twofactor/hotp.py +3 -2
  204. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/twofactor/totp.py +2 -1
  205. py2docfx/venv/venv1/Lib/site-packages/cryptography/utils.py +15 -3
  206. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/__init__.py +3 -0
  207. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/base.py +39 -6
  208. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/extensions.py +100 -49
  209. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/name.py +27 -15
  210. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/ocsp.py +60 -25
  211. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/oid.py +2 -0
  212. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/verification.py +6 -0
  213. py2docfx/venv/venv1/Lib/site-packages/google/api_core/bidi.py +17 -4
  214. py2docfx/venv/venv1/Lib/site-packages/google/api_core/client_info.py +6 -0
  215. py2docfx/venv/venv1/Lib/site-packages/google/api_core/gapic_v1/client_info.py +1 -0
  216. py2docfx/venv/venv1/Lib/site-packages/google/api_core/retry/retry_base.py +13 -4
  217. py2docfx/venv/venv1/Lib/site-packages/google/api_core/retry/retry_streaming.py +7 -6
  218. py2docfx/venv/venv1/Lib/site-packages/google/api_core/retry/retry_streaming_async.py +8 -5
  219. py2docfx/venv/venv1/Lib/site-packages/google/api_core/retry/retry_unary.py +7 -6
  220. py2docfx/venv/venv1/Lib/site-packages/google/api_core/retry/retry_unary_async.py +7 -6
  221. py2docfx/venv/venv1/Lib/site-packages/google/api_core/version.py +1 -1
  222. py2docfx/venv/venv1/Lib/site-packages/google/auth/_default.py +2 -36
  223. py2docfx/venv/venv1/Lib/site-packages/google/auth/_helpers.py +240 -0
  224. py2docfx/venv/venv1/Lib/site-packages/google/auth/aio/_helpers.py +62 -0
  225. py2docfx/venv/venv1/Lib/site-packages/google/auth/aio/transport/aiohttp.py +6 -0
  226. py2docfx/venv/venv1/Lib/site-packages/google/auth/compute_engine/_metadata.py +5 -1
  227. py2docfx/venv/venv1/Lib/site-packages/google/auth/compute_engine/credentials.py +2 -1
  228. py2docfx/venv/venv1/Lib/site-packages/google/auth/identity_pool.py +91 -2
  229. py2docfx/venv/venv1/Lib/site-packages/google/auth/impersonated_credentials.py +75 -0
  230. py2docfx/venv/venv1/Lib/site-packages/google/auth/transport/__init__.py +1 -0
  231. py2docfx/venv/venv1/Lib/site-packages/google/auth/transport/_aiohttp_requests.py +8 -1
  232. py2docfx/venv/venv1/Lib/site-packages/google/auth/transport/_http_client.py +3 -1
  233. py2docfx/venv/venv1/Lib/site-packages/google/auth/transport/requests.py +4 -1
  234. py2docfx/venv/venv1/Lib/site-packages/google/auth/transport/urllib3.py +15 -5
  235. py2docfx/venv/venv1/Lib/site-packages/google/auth/version.py +1 -1
  236. py2docfx/venv/venv1/Lib/site-packages/google/oauth2/id_token.py +12 -0
  237. py2docfx/venv/venv1/Lib/site-packages/google/oauth2/webauthn_types.py +1 -1
  238. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/__init__.py +1 -1
  239. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/any.py +15 -1
  240. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/any_pb2.py +3 -3
  241. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/api_pb2.py +3 -3
  242. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/compiler/plugin_pb2.py +3 -3
  243. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor.py +15 -2
  244. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor_pb2.py +258 -113
  245. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor_pool.py +22 -8
  246. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/duration_pb2.py +3 -3
  247. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/empty_pb2.py +3 -3
  248. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/field_mask_pb2.py +3 -3
  249. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/decoder.py +106 -23
  250. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/field_mask.py +3 -1
  251. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/python_edition_defaults.py +1 -1
  252. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/python_message.py +21 -18
  253. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/testing_refleaks.py +8 -2
  254. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/well_known_types.py +60 -43
  255. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/json_format.py +4 -5
  256. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/message_factory.py +16 -0
  257. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/runtime_version.py +2 -2
  258. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/source_context_pb2.py +3 -3
  259. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/struct_pb2.py +3 -3
  260. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/text_format.py +11 -7
  261. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/timestamp_pb2.py +3 -3
  262. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/type_pb2.py +3 -3
  263. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/wrappers_pb2.py +3 -3
  264. py2docfx/venv/venv1/Lib/site-packages/google/rpc/error_details_pb2.py +29 -23
  265. py2docfx/venv/venv1/Lib/site-packages/google/rpc/error_details_pb2.pyi +41 -2
  266. py2docfx/venv/venv1/Lib/site-packages/msal/application.py +1 -0
  267. py2docfx/venv/venv1/Lib/site-packages/msal/individual_cache.py +9 -5
  268. py2docfx/venv/venv1/Lib/site-packages/msal/managed_identity.py +4 -5
  269. py2docfx/venv/venv1/Lib/site-packages/msal/sku.py +1 -1
  270. py2docfx/venv/venv1/Lib/site-packages/msal/throttled_http_client.py +58 -30
  271. py2docfx/venv/venv1/Lib/site-packages/opencensus/__init__.py +1 -1
  272. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/__init__.py +1 -1
  273. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/__init__.py +1 -1
  274. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/common/__init__.py +138 -138
  275. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/common/exporter.py +93 -93
  276. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/common/processor.py +63 -63
  277. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/common/protocol.py +206 -206
  278. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/common/storage.py +205 -205
  279. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/common/transport.py +355 -355
  280. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/common/utils.py +79 -79
  281. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/common/version.py +15 -15
  282. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/log_exporter/__init__.py +314 -314
  283. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/metrics_exporter/__init__.py +190 -190
  284. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/metrics_exporter/standard_metrics/__init__.py +62 -62
  285. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/metrics_exporter/standard_metrics/cpu.py +50 -50
  286. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/metrics_exporter/standard_metrics/http_requests.py +176 -176
  287. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/metrics_exporter/standard_metrics/memory.py +42 -42
  288. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/metrics_exporter/standard_metrics/process.py +87 -87
  289. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/statsbeat/__init__.py +1 -1
  290. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/statsbeat/state.py +50 -50
  291. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/statsbeat/statsbeat.py +100 -100
  292. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/statsbeat/statsbeat_metrics.py +480 -480
  293. py2docfx/venv/venv1/Lib/site-packages/opencensus/ext/azure/trace_exporter/__init__.py +236 -236
  294. py2docfx/venv/venv1/Lib/site-packages/packaging/__init__.py +1 -1
  295. py2docfx/venv/venv1/Lib/site-packages/packaging/_elffile.py +1 -2
  296. py2docfx/venv/venv1/Lib/site-packages/packaging/_manylinux.py +1 -2
  297. py2docfx/venv/venv1/Lib/site-packages/packaging/_parser.py +1 -2
  298. py2docfx/venv/venv1/Lib/site-packages/packaging/_tokenizer.py +5 -4
  299. py2docfx/venv/venv1/Lib/site-packages/packaging/licenses/__init__.py +1 -1
  300. py2docfx/venv/venv1/Lib/site-packages/packaging/markers.py +53 -22
  301. py2docfx/venv/venv1/Lib/site-packages/packaging/metadata.py +1 -2
  302. py2docfx/venv/venv1/Lib/site-packages/packaging/specifiers.py +1 -2
  303. py2docfx/venv/venv1/Lib/site-packages/packaging/tags.py +39 -0
  304. py2docfx/venv/venv1/Lib/site-packages/pkg_resources/__init__.py +6 -7
  305. py2docfx/venv/venv1/Lib/site-packages/requests/__version__.py +2 -2
  306. py2docfx/venv/venv1/Lib/site-packages/requests/compat.py +12 -0
  307. py2docfx/venv/venv1/Lib/site-packages/requests/models.py +3 -1
  308. py2docfx/venv/venv1/Lib/site-packages/requests/utils.py +6 -16
  309. py2docfx/venv/venv1/Lib/site-packages/rsa/__init__.py +2 -2
  310. py2docfx/venv/venv1/Lib/site-packages/rsa/asn1.py +52 -52
  311. py2docfx/venv/venv1/Lib/site-packages/rsa/cli.py +321 -321
  312. py2docfx/venv/venv1/Lib/site-packages/rsa/common.py +184 -184
  313. py2docfx/venv/venv1/Lib/site-packages/rsa/core.py +53 -53
  314. py2docfx/venv/venv1/Lib/site-packages/rsa/key.py +858 -858
  315. py2docfx/venv/venv1/Lib/site-packages/rsa/parallel.py +96 -96
  316. py2docfx/venv/venv1/Lib/site-packages/rsa/pem.py +134 -134
  317. py2docfx/venv/venv1/Lib/site-packages/rsa/pkcs1.py +485 -485
  318. py2docfx/venv/venv1/Lib/site-packages/rsa/pkcs1_v2.py +100 -100
  319. py2docfx/venv/venv1/Lib/site-packages/rsa/prime.py +198 -198
  320. py2docfx/venv/venv1/Lib/site-packages/rsa/py.typed +1 -1
  321. py2docfx/venv/venv1/Lib/site-packages/rsa/randnum.py +95 -95
  322. py2docfx/venv/venv1/Lib/site-packages/rsa/transform.py +72 -72
  323. py2docfx/venv/venv1/Lib/site-packages/rsa/util.py +97 -97
  324. py2docfx/venv/venv1/Lib/site-packages/setuptools/__init__.py +0 -38
  325. py2docfx/venv/venv1/Lib/site-packages/setuptools/_discovery.py +33 -0
  326. py2docfx/venv/venv1/Lib/site-packages/setuptools/_distutils/command/build_scripts.py +1 -1
  327. py2docfx/venv/venv1/Lib/site-packages/setuptools/_distutils/command/config.py +0 -2
  328. py2docfx/venv/venv1/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_unix.py +63 -0
  329. py2docfx/venv/venv1/Lib/site-packages/setuptools/_distutils/compilers/C/unix.py +5 -6
  330. py2docfx/venv/venv1/Lib/site-packages/setuptools/_entry_points.py +4 -0
  331. py2docfx/venv/venv1/Lib/site-packages/setuptools/_normalization.py +0 -2
  332. py2docfx/venv/venv1/Lib/site-packages/setuptools/_path.py +12 -3
  333. py2docfx/venv/venv1/Lib/site-packages/setuptools/_reqs.py +1 -1
  334. py2docfx/venv/venv1/Lib/site-packages/setuptools/_scripts.py +361 -0
  335. py2docfx/venv/venv1/Lib/site-packages/setuptools/_shutil.py +6 -0
  336. py2docfx/venv/venv1/Lib/site-packages/setuptools/build_meta.py +25 -37
  337. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/bdist_egg.py +9 -11
  338. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/bdist_wheel.py +1 -1
  339. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/build_ext.py +29 -28
  340. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/develop.py +39 -179
  341. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/easy_install.py +17 -2352
  342. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/editable_wheel.py +14 -31
  343. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/egg_info.py +0 -2
  344. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/install.py +3 -55
  345. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/install_scripts.py +5 -11
  346. py2docfx/venv/venv1/Lib/site-packages/setuptools/command/sdist.py +1 -1
  347. py2docfx/venv/venv1/Lib/site-packages/setuptools/compat/py310.py +11 -0
  348. py2docfx/venv/venv1/Lib/site-packages/setuptools/dist.py +10 -12
  349. py2docfx/venv/venv1/Lib/site-packages/setuptools/installer.py +34 -29
  350. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/contexts.py +0 -14
  351. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/fixtures.py +235 -0
  352. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/integration/test_pbr.py +20 -0
  353. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_build_meta.py +0 -24
  354. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_develop.py +1 -64
  355. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_dist.py +2 -2
  356. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_dist_info.py +0 -63
  357. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_editable_install.py +15 -41
  358. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_egg_info.py +3 -2
  359. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_scripts.py +12 -0
  360. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_wheel.py +12 -36
  361. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_windows_wrappers.py +3 -4
  362. py2docfx/venv/venv1/Lib/site-packages/setuptools/wheel.py +49 -24
  363. py2docfx/venv/venv1/Lib/site-packages/typing_extensions.py +357 -703
  364. py2docfx/venv/venv1/Lib/site-packages/urllib3/_version.py +2 -2
  365. py2docfx/venv/venv1/Lib/site-packages/urllib3/connection.py +87 -38
  366. py2docfx/venv/venv1/Lib/site-packages/urllib3/contrib/emscripten/fetch.py +20 -0
  367. py2docfx/venv/venv1/Lib/site-packages/urllib3/poolmanager.py +17 -1
  368. py2docfx/venv/venv1/Lib/site-packages/urllib3/response.py +53 -24
  369. py2docfx/venv/venv1/Lib/site-packages/urllib3/util/request.py +12 -4
  370. py2docfx/venv/venv1/Lib/site-packages/urllib3/util/ssl_.py +1 -1
  371. {py2docfx-0.1.16.dev2064350.dist-info → py2docfx-0.1.17.dist-info}/METADATA +1 -1
  372. {py2docfx-0.1.16.dev2064350.dist-info → py2docfx-0.1.17.dist-info}/RECORD +374 -372
  373. {py2docfx-0.1.16.dev2064350.dist-info → py2docfx-0.1.17.dist-info}/WHEEL +1 -1
  374. py2docfx/venv/basevenv/Lib/site-packages/setuptools/package_index.py +0 -1137
  375. py2docfx/venv/basevenv/Lib/site-packages/setuptools/sandbox.py +0 -536
  376. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/server.py +0 -86
  377. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_easy_install.py +0 -1476
  378. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_packageindex.py +0 -267
  379. py2docfx/venv/basevenv/Lib/site-packages/setuptools/tests/test_sandbox.py +0 -134
  380. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/application.py +0 -119
  381. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/application.py +0 -121
  382. py2docfx/venv/venv1/Lib/site-packages/setuptools/package_index.py +0 -1137
  383. py2docfx/venv/venv1/Lib/site-packages/setuptools/sandbox.py +0 -536
  384. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/server.py +0 -86
  385. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_easy_install.py +0 -1476
  386. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_packageindex.py +0 -267
  387. py2docfx/venv/venv1/Lib/site-packages/setuptools/tests/test_sandbox.py +0 -134
  388. {py2docfx-0.1.16.dev2064350.dist-info → py2docfx-0.1.17.dist-info}/top_level.txt +0 -0
@@ -1,485 +1,485 @@
1
- # Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- """Functions for PKCS#1 version 1.5 encryption and signing
16
-
17
- This module implements certain functionality from PKCS#1 version 1.5. For a
18
- very clear example, read http://www.di-mgt.com.au/rsa_alg.html#pkcs1schemes
19
-
20
- At least 8 bytes of random padding is used when encrypting a message. This makes
21
- these methods much more secure than the ones in the ``rsa`` module.
22
-
23
- WARNING: this module leaks information when decryption fails. The exceptions
24
- that are raised contain the Python traceback information, which can be used to
25
- deduce where in the process the failure occurred. DO NOT PASS SUCH INFORMATION
26
- to your users.
27
- """
28
-
29
- import hashlib
30
- import os
31
- import sys
32
- import typing
33
- from hmac import compare_digest
34
-
35
- from . import common, transform, core, key
36
-
37
- if typing.TYPE_CHECKING:
38
- HashType = hashlib._Hash
39
- else:
40
- HashType = typing.Any
41
-
42
- # ASN.1 codes that describe the hash algorithm used.
43
- HASH_ASN1 = {
44
- "MD5": b"\x30\x20\x30\x0c\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x05\x05\x00\x04\x10",
45
- "SHA-1": b"\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14",
46
- "SHA-224": b"\x30\x2d\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x04\x05\x00\x04\x1c",
47
- "SHA-256": b"\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20",
48
- "SHA-384": b"\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02\x05\x00\x04\x30",
49
- "SHA-512": b"\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40",
50
- }
51
-
52
- HASH_METHODS: typing.Dict[str, typing.Callable[[], HashType]] = {
53
- "MD5": hashlib.md5,
54
- "SHA-1": hashlib.sha1,
55
- "SHA-224": hashlib.sha224,
56
- "SHA-256": hashlib.sha256,
57
- "SHA-384": hashlib.sha384,
58
- "SHA-512": hashlib.sha512,
59
- }
60
- """Hash methods supported by this library."""
61
-
62
-
63
- if sys.version_info >= (3, 6):
64
- # Python 3.6 introduced SHA3 support.
65
- HASH_ASN1.update(
66
- {
67
- "SHA3-256": b"\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x08\x05\x00\x04\x20",
68
- "SHA3-384": b"\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x09\x05\x00\x04\x30",
69
- "SHA3-512": b"\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x0a\x05\x00\x04\x40",
70
- }
71
- )
72
-
73
- HASH_METHODS.update(
74
- {
75
- "SHA3-256": hashlib.sha3_256,
76
- "SHA3-384": hashlib.sha3_384,
77
- "SHA3-512": hashlib.sha3_512,
78
- }
79
- )
80
-
81
-
82
- class CryptoError(Exception):
83
- """Base class for all exceptions in this module."""
84
-
85
-
86
- class DecryptionError(CryptoError):
87
- """Raised when decryption fails."""
88
-
89
-
90
- class VerificationError(CryptoError):
91
- """Raised when verification fails."""
92
-
93
-
94
- def _pad_for_encryption(message: bytes, target_length: int) -> bytes:
95
- r"""Pads the message for encryption, returning the padded message.
96
-
97
- :return: 00 02 RANDOM_DATA 00 MESSAGE
98
-
99
- >>> block = _pad_for_encryption(b'hello', 16)
100
- >>> len(block)
101
- 16
102
- >>> block[0:2]
103
- b'\x00\x02'
104
- >>> block[-6:]
105
- b'\x00hello'
106
-
107
- """
108
-
109
- max_msglength = target_length - 11
110
- msglength = len(message)
111
-
112
- if msglength > max_msglength:
113
- raise OverflowError(
114
- "%i bytes needed for message, but there is only"
115
- " space for %i" % (msglength, max_msglength)
116
- )
117
-
118
- # Get random padding
119
- padding = b""
120
- padding_length = target_length - msglength - 3
121
-
122
- # We remove 0-bytes, so we'll end up with less padding than we've asked for,
123
- # so keep adding data until we're at the correct length.
124
- while len(padding) < padding_length:
125
- needed_bytes = padding_length - len(padding)
126
-
127
- # Always read at least 8 bytes more than we need, and trim off the rest
128
- # after removing the 0-bytes. This increases the chance of getting
129
- # enough bytes, especially when needed_bytes is small
130
- new_padding = os.urandom(needed_bytes + 5)
131
- new_padding = new_padding.replace(b"\x00", b"")
132
- padding = padding + new_padding[:needed_bytes]
133
-
134
- assert len(padding) == padding_length
135
-
136
- return b"".join([b"\x00\x02", padding, b"\x00", message])
137
-
138
-
139
- def _pad_for_signing(message: bytes, target_length: int) -> bytes:
140
- r"""Pads the message for signing, returning the padded message.
141
-
142
- The padding is always a repetition of FF bytes.
143
-
144
- :return: 00 01 PADDING 00 MESSAGE
145
-
146
- >>> block = _pad_for_signing(b'hello', 16)
147
- >>> len(block)
148
- 16
149
- >>> block[0:2]
150
- b'\x00\x01'
151
- >>> block[-6:]
152
- b'\x00hello'
153
- >>> block[2:-6]
154
- b'\xff\xff\xff\xff\xff\xff\xff\xff'
155
-
156
- """
157
-
158
- max_msglength = target_length - 11
159
- msglength = len(message)
160
-
161
- if msglength > max_msglength:
162
- raise OverflowError(
163
- "%i bytes needed for message, but there is only"
164
- " space for %i" % (msglength, max_msglength)
165
- )
166
-
167
- padding_length = target_length - msglength - 3
168
-
169
- return b"".join([b"\x00\x01", padding_length * b"\xff", b"\x00", message])
170
-
171
-
172
- def encrypt(message: bytes, pub_key: key.PublicKey) -> bytes:
173
- """Encrypts the given message using PKCS#1 v1.5
174
-
175
- :param message: the message to encrypt. Must be a byte string no longer than
176
- ``k-11`` bytes, where ``k`` is the number of bytes needed to encode
177
- the ``n`` component of the public key.
178
- :param pub_key: the :py:class:`rsa.PublicKey` to encrypt with.
179
- :raise OverflowError: when the message is too large to fit in the padded
180
- block.
181
-
182
- >>> from rsa import key, common
183
- >>> (pub_key, priv_key) = key.newkeys(256)
184
- >>> message = b'hello'
185
- >>> crypto = encrypt(message, pub_key)
186
-
187
- The crypto text should be just as long as the public key 'n' component:
188
-
189
- >>> len(crypto) == common.byte_size(pub_key.n)
190
- True
191
-
192
- """
193
-
194
- keylength = common.byte_size(pub_key.n)
195
- padded = _pad_for_encryption(message, keylength)
196
-
197
- payload = transform.bytes2int(padded)
198
- encrypted = core.encrypt_int(payload, pub_key.e, pub_key.n)
199
- block = transform.int2bytes(encrypted, keylength)
200
-
201
- return block
202
-
203
-
204
- def decrypt(crypto: bytes, priv_key: key.PrivateKey) -> bytes:
205
- r"""Decrypts the given message using PKCS#1 v1.5
206
-
207
- The decryption is considered 'failed' when the resulting cleartext doesn't
208
- start with the bytes 00 02, or when the 00 byte between the padding and
209
- the message cannot be found.
210
-
211
- :param crypto: the crypto text as returned by :py:func:`rsa.encrypt`
212
- :param priv_key: the :py:class:`rsa.PrivateKey` to decrypt with.
213
- :raise DecryptionError: when the decryption fails. No details are given as
214
- to why the code thinks the decryption fails, as this would leak
215
- information about the private key.
216
-
217
-
218
- >>> import rsa
219
- >>> (pub_key, priv_key) = rsa.newkeys(256)
220
-
221
- It works with strings:
222
-
223
- >>> crypto = encrypt(b'hello', pub_key)
224
- >>> decrypt(crypto, priv_key)
225
- b'hello'
226
-
227
- And with binary data:
228
-
229
- >>> crypto = encrypt(b'\x00\x00\x00\x00\x01', pub_key)
230
- >>> decrypt(crypto, priv_key)
231
- b'\x00\x00\x00\x00\x01'
232
-
233
- Altering the encrypted information will *likely* cause a
234
- :py:class:`rsa.pkcs1.DecryptionError`. If you want to be *sure*, use
235
- :py:func:`rsa.sign`.
236
-
237
-
238
- .. warning::
239
-
240
- Never display the stack trace of a
241
- :py:class:`rsa.pkcs1.DecryptionError` exception. It shows where in the
242
- code the exception occurred, and thus leaks information about the key.
243
- It's only a tiny bit of information, but every bit makes cracking the
244
- keys easier.
245
-
246
- >>> crypto = encrypt(b'hello', pub_key)
247
- >>> crypto = crypto[0:5] + b'X' + crypto[6:] # change a byte
248
- >>> decrypt(crypto, priv_key)
249
- Traceback (most recent call last):
250
- ...
251
- rsa.pkcs1.DecryptionError: Decryption failed
252
-
253
- """
254
-
255
- blocksize = common.byte_size(priv_key.n)
256
- encrypted = transform.bytes2int(crypto)
257
- decrypted = priv_key.blinded_decrypt(encrypted)
258
- cleartext = transform.int2bytes(decrypted, blocksize)
259
-
260
- # Detect leading zeroes in the crypto. These are not reflected in the
261
- # encrypted value (as leading zeroes do not influence the value of an
262
- # integer). This fixes CVE-2020-13757.
263
- if len(crypto) > blocksize:
264
- # This is operating on public information, so doesn't need to be constant-time.
265
- raise DecryptionError("Decryption failed")
266
-
267
- # If we can't find the cleartext marker, decryption failed.
268
- cleartext_marker_bad = not compare_digest(cleartext[:2], b"\x00\x02")
269
-
270
- # Find the 00 separator between the padding and the message
271
- sep_idx = cleartext.find(b"\x00", 2)
272
-
273
- # sep_idx indicates the position of the `\x00` separator that separates the
274
- # padding from the actual message. The padding should be at least 8 bytes
275
- # long (see https://tools.ietf.org/html/rfc8017#section-7.2.2 step 3), which
276
- # means the separator should be at least at index 10 (because of the
277
- # `\x00\x02` marker that precedes it).
278
- sep_idx_bad = sep_idx < 10
279
-
280
- anything_bad = cleartext_marker_bad | sep_idx_bad
281
- if anything_bad:
282
- raise DecryptionError("Decryption failed")
283
-
284
- return cleartext[sep_idx + 1 :]
285
-
286
-
287
- def sign_hash(hash_value: bytes, priv_key: key.PrivateKey, hash_method: str) -> bytes:
288
- """Signs a precomputed hash with the private key.
289
-
290
- Hashes the message, then signs the hash with the given key. This is known
291
- as a "detached signature", because the message itself isn't altered.
292
-
293
- :param hash_value: A precomputed hash to sign (ignores message).
294
- :param priv_key: the :py:class:`rsa.PrivateKey` to sign with
295
- :param hash_method: the hash method used on the message. Use 'MD5', 'SHA-1',
296
- 'SHA-224', SHA-256', 'SHA-384' or 'SHA-512'.
297
- :return: a message signature block.
298
- :raise OverflowError: if the private key is too small to contain the
299
- requested hash.
300
-
301
- """
302
-
303
- # Get the ASN1 code for this hash method
304
- if hash_method not in HASH_ASN1:
305
- raise ValueError("Invalid hash method: %s" % hash_method)
306
- asn1code = HASH_ASN1[hash_method]
307
-
308
- # Encrypt the hash with the private key
309
- cleartext = asn1code + hash_value
310
- keylength = common.byte_size(priv_key.n)
311
- padded = _pad_for_signing(cleartext, keylength)
312
-
313
- payload = transform.bytes2int(padded)
314
- encrypted = priv_key.blinded_encrypt(payload)
315
- block = transform.int2bytes(encrypted, keylength)
316
-
317
- return block
318
-
319
-
320
- def sign(message: bytes, priv_key: key.PrivateKey, hash_method: str) -> bytes:
321
- """Signs the message with the private key.
322
-
323
- Hashes the message, then signs the hash with the given key. This is known
324
- as a "detached signature", because the message itself isn't altered.
325
-
326
- :param message: the message to sign. Can be an 8-bit string or a file-like
327
- object. If ``message`` has a ``read()`` method, it is assumed to be a
328
- file-like object.
329
- :param priv_key: the :py:class:`rsa.PrivateKey` to sign with
330
- :param hash_method: the hash method used on the message. Use 'MD5', 'SHA-1',
331
- 'SHA-224', SHA-256', 'SHA-384' or 'SHA-512'.
332
- :return: a message signature block.
333
- :raise OverflowError: if the private key is too small to contain the
334
- requested hash.
335
-
336
- """
337
-
338
- msg_hash = compute_hash(message, hash_method)
339
- return sign_hash(msg_hash, priv_key, hash_method)
340
-
341
-
342
- def verify(message: bytes, signature: bytes, pub_key: key.PublicKey) -> str:
343
- """Verifies that the signature matches the message.
344
-
345
- The hash method is detected automatically from the signature.
346
-
347
- :param message: the signed message. Can be an 8-bit string or a file-like
348
- object. If ``message`` has a ``read()`` method, it is assumed to be a
349
- file-like object.
350
- :param signature: the signature block, as created with :py:func:`rsa.sign`.
351
- :param pub_key: the :py:class:`rsa.PublicKey` of the person signing the message.
352
- :raise VerificationError: when the signature doesn't match the message.
353
- :returns: the name of the used hash.
354
-
355
- """
356
-
357
- keylength = common.byte_size(pub_key.n)
358
- encrypted = transform.bytes2int(signature)
359
- decrypted = core.decrypt_int(encrypted, pub_key.e, pub_key.n)
360
- clearsig = transform.int2bytes(decrypted, keylength)
361
-
362
- # Get the hash method
363
- method_name = _find_method_hash(clearsig)
364
- message_hash = compute_hash(message, method_name)
365
-
366
- # Reconstruct the expected padded hash
367
- cleartext = HASH_ASN1[method_name] + message_hash
368
- expected = _pad_for_signing(cleartext, keylength)
369
-
370
- if len(signature) != keylength:
371
- raise VerificationError("Verification failed")
372
-
373
- # Compare with the signed one
374
- if expected != clearsig:
375
- raise VerificationError("Verification failed")
376
-
377
- return method_name
378
-
379
-
380
- def find_signature_hash(signature: bytes, pub_key: key.PublicKey) -> str:
381
- """Returns the hash name detected from the signature.
382
-
383
- If you also want to verify the message, use :py:func:`rsa.verify()` instead.
384
- It also returns the name of the used hash.
385
-
386
- :param signature: the signature block, as created with :py:func:`rsa.sign`.
387
- :param pub_key: the :py:class:`rsa.PublicKey` of the person signing the message.
388
- :returns: the name of the used hash.
389
- """
390
-
391
- keylength = common.byte_size(pub_key.n)
392
- encrypted = transform.bytes2int(signature)
393
- decrypted = core.decrypt_int(encrypted, pub_key.e, pub_key.n)
394
- clearsig = transform.int2bytes(decrypted, keylength)
395
-
396
- return _find_method_hash(clearsig)
397
-
398
-
399
- def yield_fixedblocks(infile: typing.BinaryIO, blocksize: int) -> typing.Iterator[bytes]:
400
- """Generator, yields each block of ``blocksize`` bytes in the input file.
401
-
402
- :param infile: file to read and separate in blocks.
403
- :param blocksize: block size in bytes.
404
- :returns: a generator that yields the contents of each block
405
- """
406
-
407
- while True:
408
- block = infile.read(blocksize)
409
-
410
- read_bytes = len(block)
411
- if read_bytes == 0:
412
- break
413
-
414
- yield block
415
-
416
- if read_bytes < blocksize:
417
- break
418
-
419
-
420
- def compute_hash(message: typing.Union[bytes, typing.BinaryIO], method_name: str) -> bytes:
421
- """Returns the message digest.
422
-
423
- :param message: the signed message. Can be an 8-bit string or a file-like
424
- object. If ``message`` has a ``read()`` method, it is assumed to be a
425
- file-like object.
426
- :param method_name: the hash method, must be a key of
427
- :py:const:`rsa.pkcs1.HASH_METHODS`.
428
-
429
- """
430
-
431
- if method_name not in HASH_METHODS:
432
- raise ValueError("Invalid hash method: %s" % method_name)
433
-
434
- method = HASH_METHODS[method_name]
435
- hasher = method()
436
-
437
- if isinstance(message, bytes):
438
- hasher.update(message)
439
- else:
440
- assert hasattr(message, "read") and hasattr(message.read, "__call__")
441
- # read as 1K blocks
442
- for block in yield_fixedblocks(message, 1024):
443
- hasher.update(block)
444
-
445
- return hasher.digest()
446
-
447
-
448
- def _find_method_hash(clearsig: bytes) -> str:
449
- """Finds the hash method.
450
-
451
- :param clearsig: full padded ASN1 and hash.
452
- :return: the used hash method.
453
- :raise VerificationFailed: when the hash method cannot be found
454
- """
455
-
456
- for (hashname, asn1code) in HASH_ASN1.items():
457
- if asn1code in clearsig:
458
- return hashname
459
-
460
- raise VerificationError("Verification failed")
461
-
462
-
463
- __all__ = [
464
- "encrypt",
465
- "decrypt",
466
- "sign",
467
- "verify",
468
- "DecryptionError",
469
- "VerificationError",
470
- "CryptoError",
471
- ]
472
-
473
- if __name__ == "__main__":
474
- print("Running doctests 1000x or until failure")
475
- import doctest
476
-
477
- for count in range(1000):
478
- (failures, tests) = doctest.testmod()
479
- if failures:
480
- break
481
-
482
- if count % 100 == 0 and count:
483
- print("%i times" % count)
484
-
485
- print("Doctests done")
1
+ # Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Functions for PKCS#1 version 1.5 encryption and signing
16
+
17
+ This module implements certain functionality from PKCS#1 version 1.5. For a
18
+ very clear example, read http://www.di-mgt.com.au/rsa_alg.html#pkcs1schemes
19
+
20
+ At least 8 bytes of random padding is used when encrypting a message. This makes
21
+ these methods much more secure than the ones in the ``rsa`` module.
22
+
23
+ WARNING: this module leaks information when decryption fails. The exceptions
24
+ that are raised contain the Python traceback information, which can be used to
25
+ deduce where in the process the failure occurred. DO NOT PASS SUCH INFORMATION
26
+ to your users.
27
+ """
28
+
29
+ import hashlib
30
+ import os
31
+ import sys
32
+ import typing
33
+ from hmac import compare_digest
34
+
35
+ from . import common, transform, core, key
36
+
37
+ if typing.TYPE_CHECKING:
38
+ HashType = hashlib._Hash
39
+ else:
40
+ HashType = typing.Any
41
+
42
+ # ASN.1 codes that describe the hash algorithm used.
43
+ HASH_ASN1 = {
44
+ "MD5": b"\x30\x20\x30\x0c\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x05\x05\x00\x04\x10",
45
+ "SHA-1": b"\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14",
46
+ "SHA-224": b"\x30\x2d\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x04\x05\x00\x04\x1c",
47
+ "SHA-256": b"\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20",
48
+ "SHA-384": b"\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02\x05\x00\x04\x30",
49
+ "SHA-512": b"\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40",
50
+ }
51
+
52
+ HASH_METHODS: typing.Dict[str, typing.Callable[[], HashType]] = {
53
+ "MD5": hashlib.md5,
54
+ "SHA-1": hashlib.sha1,
55
+ "SHA-224": hashlib.sha224,
56
+ "SHA-256": hashlib.sha256,
57
+ "SHA-384": hashlib.sha384,
58
+ "SHA-512": hashlib.sha512,
59
+ }
60
+ """Hash methods supported by this library."""
61
+
62
+
63
+ if sys.version_info >= (3, 6):
64
+ # Python 3.6 introduced SHA3 support.
65
+ HASH_ASN1.update(
66
+ {
67
+ "SHA3-256": b"\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x08\x05\x00\x04\x20",
68
+ "SHA3-384": b"\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x09\x05\x00\x04\x30",
69
+ "SHA3-512": b"\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x0a\x05\x00\x04\x40",
70
+ }
71
+ )
72
+
73
+ HASH_METHODS.update(
74
+ {
75
+ "SHA3-256": hashlib.sha3_256,
76
+ "SHA3-384": hashlib.sha3_384,
77
+ "SHA3-512": hashlib.sha3_512,
78
+ }
79
+ )
80
+
81
+
82
+ class CryptoError(Exception):
83
+ """Base class for all exceptions in this module."""
84
+
85
+
86
+ class DecryptionError(CryptoError):
87
+ """Raised when decryption fails."""
88
+
89
+
90
+ class VerificationError(CryptoError):
91
+ """Raised when verification fails."""
92
+
93
+
94
+ def _pad_for_encryption(message: bytes, target_length: int) -> bytes:
95
+ r"""Pads the message for encryption, returning the padded message.
96
+
97
+ :return: 00 02 RANDOM_DATA 00 MESSAGE
98
+
99
+ >>> block = _pad_for_encryption(b'hello', 16)
100
+ >>> len(block)
101
+ 16
102
+ >>> block[0:2]
103
+ b'\x00\x02'
104
+ >>> block[-6:]
105
+ b'\x00hello'
106
+
107
+ """
108
+
109
+ max_msglength = target_length - 11
110
+ msglength = len(message)
111
+
112
+ if msglength > max_msglength:
113
+ raise OverflowError(
114
+ "%i bytes needed for message, but there is only"
115
+ " space for %i" % (msglength, max_msglength)
116
+ )
117
+
118
+ # Get random padding
119
+ padding = b""
120
+ padding_length = target_length - msglength - 3
121
+
122
+ # We remove 0-bytes, so we'll end up with less padding than we've asked for,
123
+ # so keep adding data until we're at the correct length.
124
+ while len(padding) < padding_length:
125
+ needed_bytes = padding_length - len(padding)
126
+
127
+ # Always read at least 8 bytes more than we need, and trim off the rest
128
+ # after removing the 0-bytes. This increases the chance of getting
129
+ # enough bytes, especially when needed_bytes is small
130
+ new_padding = os.urandom(needed_bytes + 5)
131
+ new_padding = new_padding.replace(b"\x00", b"")
132
+ padding = padding + new_padding[:needed_bytes]
133
+
134
+ assert len(padding) == padding_length
135
+
136
+ return b"".join([b"\x00\x02", padding, b"\x00", message])
137
+
138
+
139
+ def _pad_for_signing(message: bytes, target_length: int) -> bytes:
140
+ r"""Pads the message for signing, returning the padded message.
141
+
142
+ The padding is always a repetition of FF bytes.
143
+
144
+ :return: 00 01 PADDING 00 MESSAGE
145
+
146
+ >>> block = _pad_for_signing(b'hello', 16)
147
+ >>> len(block)
148
+ 16
149
+ >>> block[0:2]
150
+ b'\x00\x01'
151
+ >>> block[-6:]
152
+ b'\x00hello'
153
+ >>> block[2:-6]
154
+ b'\xff\xff\xff\xff\xff\xff\xff\xff'
155
+
156
+ """
157
+
158
+ max_msglength = target_length - 11
159
+ msglength = len(message)
160
+
161
+ if msglength > max_msglength:
162
+ raise OverflowError(
163
+ "%i bytes needed for message, but there is only"
164
+ " space for %i" % (msglength, max_msglength)
165
+ )
166
+
167
+ padding_length = target_length - msglength - 3
168
+
169
+ return b"".join([b"\x00\x01", padding_length * b"\xff", b"\x00", message])
170
+
171
+
172
+ def encrypt(message: bytes, pub_key: key.PublicKey) -> bytes:
173
+ """Encrypts the given message using PKCS#1 v1.5
174
+
175
+ :param message: the message to encrypt. Must be a byte string no longer than
176
+ ``k-11`` bytes, where ``k`` is the number of bytes needed to encode
177
+ the ``n`` component of the public key.
178
+ :param pub_key: the :py:class:`rsa.PublicKey` to encrypt with.
179
+ :raise OverflowError: when the message is too large to fit in the padded
180
+ block.
181
+
182
+ >>> from rsa import key, common
183
+ >>> (pub_key, priv_key) = key.newkeys(256)
184
+ >>> message = b'hello'
185
+ >>> crypto = encrypt(message, pub_key)
186
+
187
+ The crypto text should be just as long as the public key 'n' component:
188
+
189
+ >>> len(crypto) == common.byte_size(pub_key.n)
190
+ True
191
+
192
+ """
193
+
194
+ keylength = common.byte_size(pub_key.n)
195
+ padded = _pad_for_encryption(message, keylength)
196
+
197
+ payload = transform.bytes2int(padded)
198
+ encrypted = core.encrypt_int(payload, pub_key.e, pub_key.n)
199
+ block = transform.int2bytes(encrypted, keylength)
200
+
201
+ return block
202
+
203
+
204
+ def decrypt(crypto: bytes, priv_key: key.PrivateKey) -> bytes:
205
+ r"""Decrypts the given message using PKCS#1 v1.5
206
+
207
+ The decryption is considered 'failed' when the resulting cleartext doesn't
208
+ start with the bytes 00 02, or when the 00 byte between the padding and
209
+ the message cannot be found.
210
+
211
+ :param crypto: the crypto text as returned by :py:func:`rsa.encrypt`
212
+ :param priv_key: the :py:class:`rsa.PrivateKey` to decrypt with.
213
+ :raise DecryptionError: when the decryption fails. No details are given as
214
+ to why the code thinks the decryption fails, as this would leak
215
+ information about the private key.
216
+
217
+
218
+ >>> import rsa
219
+ >>> (pub_key, priv_key) = rsa.newkeys(256)
220
+
221
+ It works with strings:
222
+
223
+ >>> crypto = encrypt(b'hello', pub_key)
224
+ >>> decrypt(crypto, priv_key)
225
+ b'hello'
226
+
227
+ And with binary data:
228
+
229
+ >>> crypto = encrypt(b'\x00\x00\x00\x00\x01', pub_key)
230
+ >>> decrypt(crypto, priv_key)
231
+ b'\x00\x00\x00\x00\x01'
232
+
233
+ Altering the encrypted information will *likely* cause a
234
+ :py:class:`rsa.pkcs1.DecryptionError`. If you want to be *sure*, use
235
+ :py:func:`rsa.sign`.
236
+
237
+
238
+ .. warning::
239
+
240
+ Never display the stack trace of a
241
+ :py:class:`rsa.pkcs1.DecryptionError` exception. It shows where in the
242
+ code the exception occurred, and thus leaks information about the key.
243
+ It's only a tiny bit of information, but every bit makes cracking the
244
+ keys easier.
245
+
246
+ >>> crypto = encrypt(b'hello', pub_key)
247
+ >>> crypto = crypto[0:5] + b'X' + crypto[6:] # change a byte
248
+ >>> decrypt(crypto, priv_key)
249
+ Traceback (most recent call last):
250
+ ...
251
+ rsa.pkcs1.DecryptionError: Decryption failed
252
+
253
+ """
254
+
255
+ blocksize = common.byte_size(priv_key.n)
256
+ encrypted = transform.bytes2int(crypto)
257
+ decrypted = priv_key.blinded_decrypt(encrypted)
258
+ cleartext = transform.int2bytes(decrypted, blocksize)
259
+
260
+ # Detect leading zeroes in the crypto. These are not reflected in the
261
+ # encrypted value (as leading zeroes do not influence the value of an
262
+ # integer). This fixes CVE-2020-13757.
263
+ if len(crypto) > blocksize:
264
+ # This is operating on public information, so doesn't need to be constant-time.
265
+ raise DecryptionError("Decryption failed")
266
+
267
+ # If we can't find the cleartext marker, decryption failed.
268
+ cleartext_marker_bad = not compare_digest(cleartext[:2], b"\x00\x02")
269
+
270
+ # Find the 00 separator between the padding and the message
271
+ sep_idx = cleartext.find(b"\x00", 2)
272
+
273
+ # sep_idx indicates the position of the `\x00` separator that separates the
274
+ # padding from the actual message. The padding should be at least 8 bytes
275
+ # long (see https://tools.ietf.org/html/rfc8017#section-7.2.2 step 3), which
276
+ # means the separator should be at least at index 10 (because of the
277
+ # `\x00\x02` marker that precedes it).
278
+ sep_idx_bad = sep_idx < 10
279
+
280
+ anything_bad = cleartext_marker_bad | sep_idx_bad
281
+ if anything_bad:
282
+ raise DecryptionError("Decryption failed")
283
+
284
+ return cleartext[sep_idx + 1 :]
285
+
286
+
287
+ def sign_hash(hash_value: bytes, priv_key: key.PrivateKey, hash_method: str) -> bytes:
288
+ """Signs a precomputed hash with the private key.
289
+
290
+ Hashes the message, then signs the hash with the given key. This is known
291
+ as a "detached signature", because the message itself isn't altered.
292
+
293
+ :param hash_value: A precomputed hash to sign (ignores message).
294
+ :param priv_key: the :py:class:`rsa.PrivateKey` to sign with
295
+ :param hash_method: the hash method used on the message. Use 'MD5', 'SHA-1',
296
+ 'SHA-224', SHA-256', 'SHA-384' or 'SHA-512'.
297
+ :return: a message signature block.
298
+ :raise OverflowError: if the private key is too small to contain the
299
+ requested hash.
300
+
301
+ """
302
+
303
+ # Get the ASN1 code for this hash method
304
+ if hash_method not in HASH_ASN1:
305
+ raise ValueError("Invalid hash method: %s" % hash_method)
306
+ asn1code = HASH_ASN1[hash_method]
307
+
308
+ # Encrypt the hash with the private key
309
+ cleartext = asn1code + hash_value
310
+ keylength = common.byte_size(priv_key.n)
311
+ padded = _pad_for_signing(cleartext, keylength)
312
+
313
+ payload = transform.bytes2int(padded)
314
+ encrypted = priv_key.blinded_encrypt(payload)
315
+ block = transform.int2bytes(encrypted, keylength)
316
+
317
+ return block
318
+
319
+
320
+ def sign(message: bytes, priv_key: key.PrivateKey, hash_method: str) -> bytes:
321
+ """Signs the message with the private key.
322
+
323
+ Hashes the message, then signs the hash with the given key. This is known
324
+ as a "detached signature", because the message itself isn't altered.
325
+
326
+ :param message: the message to sign. Can be an 8-bit string or a file-like
327
+ object. If ``message`` has a ``read()`` method, it is assumed to be a
328
+ file-like object.
329
+ :param priv_key: the :py:class:`rsa.PrivateKey` to sign with
330
+ :param hash_method: the hash method used on the message. Use 'MD5', 'SHA-1',
331
+ 'SHA-224', SHA-256', 'SHA-384' or 'SHA-512'.
332
+ :return: a message signature block.
333
+ :raise OverflowError: if the private key is too small to contain the
334
+ requested hash.
335
+
336
+ """
337
+
338
+ msg_hash = compute_hash(message, hash_method)
339
+ return sign_hash(msg_hash, priv_key, hash_method)
340
+
341
+
342
+ def verify(message: bytes, signature: bytes, pub_key: key.PublicKey) -> str:
343
+ """Verifies that the signature matches the message.
344
+
345
+ The hash method is detected automatically from the signature.
346
+
347
+ :param message: the signed message. Can be an 8-bit string or a file-like
348
+ object. If ``message`` has a ``read()`` method, it is assumed to be a
349
+ file-like object.
350
+ :param signature: the signature block, as created with :py:func:`rsa.sign`.
351
+ :param pub_key: the :py:class:`rsa.PublicKey` of the person signing the message.
352
+ :raise VerificationError: when the signature doesn't match the message.
353
+ :returns: the name of the used hash.
354
+
355
+ """
356
+
357
+ keylength = common.byte_size(pub_key.n)
358
+ encrypted = transform.bytes2int(signature)
359
+ decrypted = core.decrypt_int(encrypted, pub_key.e, pub_key.n)
360
+ clearsig = transform.int2bytes(decrypted, keylength)
361
+
362
+ # Get the hash method
363
+ method_name = _find_method_hash(clearsig)
364
+ message_hash = compute_hash(message, method_name)
365
+
366
+ # Reconstruct the expected padded hash
367
+ cleartext = HASH_ASN1[method_name] + message_hash
368
+ expected = _pad_for_signing(cleartext, keylength)
369
+
370
+ if len(signature) != keylength:
371
+ raise VerificationError("Verification failed")
372
+
373
+ # Compare with the signed one
374
+ if expected != clearsig:
375
+ raise VerificationError("Verification failed")
376
+
377
+ return method_name
378
+
379
+
380
+ def find_signature_hash(signature: bytes, pub_key: key.PublicKey) -> str:
381
+ """Returns the hash name detected from the signature.
382
+
383
+ If you also want to verify the message, use :py:func:`rsa.verify()` instead.
384
+ It also returns the name of the used hash.
385
+
386
+ :param signature: the signature block, as created with :py:func:`rsa.sign`.
387
+ :param pub_key: the :py:class:`rsa.PublicKey` of the person signing the message.
388
+ :returns: the name of the used hash.
389
+ """
390
+
391
+ keylength = common.byte_size(pub_key.n)
392
+ encrypted = transform.bytes2int(signature)
393
+ decrypted = core.decrypt_int(encrypted, pub_key.e, pub_key.n)
394
+ clearsig = transform.int2bytes(decrypted, keylength)
395
+
396
+ return _find_method_hash(clearsig)
397
+
398
+
399
+ def yield_fixedblocks(infile: typing.BinaryIO, blocksize: int) -> typing.Iterator[bytes]:
400
+ """Generator, yields each block of ``blocksize`` bytes in the input file.
401
+
402
+ :param infile: file to read and separate in blocks.
403
+ :param blocksize: block size in bytes.
404
+ :returns: a generator that yields the contents of each block
405
+ """
406
+
407
+ while True:
408
+ block = infile.read(blocksize)
409
+
410
+ read_bytes = len(block)
411
+ if read_bytes == 0:
412
+ break
413
+
414
+ yield block
415
+
416
+ if read_bytes < blocksize:
417
+ break
418
+
419
+
420
+ def compute_hash(message: typing.Union[bytes, typing.BinaryIO], method_name: str) -> bytes:
421
+ """Returns the message digest.
422
+
423
+ :param message: the signed message. Can be an 8-bit string or a file-like
424
+ object. If ``message`` has a ``read()`` method, it is assumed to be a
425
+ file-like object.
426
+ :param method_name: the hash method, must be a key of
427
+ :py:const:`rsa.pkcs1.HASH_METHODS`.
428
+
429
+ """
430
+
431
+ if method_name not in HASH_METHODS:
432
+ raise ValueError("Invalid hash method: %s" % method_name)
433
+
434
+ method = HASH_METHODS[method_name]
435
+ hasher = method()
436
+
437
+ if isinstance(message, bytes):
438
+ hasher.update(message)
439
+ else:
440
+ assert hasattr(message, "read") and hasattr(message.read, "__call__")
441
+ # read as 1K blocks
442
+ for block in yield_fixedblocks(message, 1024):
443
+ hasher.update(block)
444
+
445
+ return hasher.digest()
446
+
447
+
448
+ def _find_method_hash(clearsig: bytes) -> str:
449
+ """Finds the hash method.
450
+
451
+ :param clearsig: full padded ASN1 and hash.
452
+ :return: the used hash method.
453
+ :raise VerificationFailed: when the hash method cannot be found
454
+ """
455
+
456
+ for (hashname, asn1code) in HASH_ASN1.items():
457
+ if asn1code in clearsig:
458
+ return hashname
459
+
460
+ raise VerificationError("Verification failed")
461
+
462
+
463
+ __all__ = [
464
+ "encrypt",
465
+ "decrypt",
466
+ "sign",
467
+ "verify",
468
+ "DecryptionError",
469
+ "VerificationError",
470
+ "CryptoError",
471
+ ]
472
+
473
+ if __name__ == "__main__":
474
+ print("Running doctests 1000x or until failure")
475
+ import doctest
476
+
477
+ for count in range(1000):
478
+ (failures, tests) = doctest.testmod()
479
+ if failures:
480
+ break
481
+
482
+ if count % 100 == 0 and count:
483
+ print("%i times" % count)
484
+
485
+ print("Doctests done")