py2docfx 0.1.20rc2195074__py3-none-any.whl → 0.1.20rc2245107__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 (107) hide show
  1. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/api.py +3 -2
  2. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/legacy.py +17 -1
  3. py2docfx/venv/basevenv/Lib/site-packages/charset_normalizer/version.py +1 -1
  4. py2docfx/venv/basevenv/Lib/site-packages/requests/__version__.py +2 -2
  5. py2docfx/venv/basevenv/Lib/site-packages/requests/adapters.py +17 -40
  6. py2docfx/venv/basevenv/Lib/site-packages/requests/sessions.py +1 -1
  7. py2docfx/venv/venv1/Lib/site-packages/azure/core/_version.py +1 -1
  8. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/policies/_authentication.py +21 -9
  9. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/policies/_authentication_async.py +21 -9
  10. py2docfx/venv/venv1/Lib/site-packages/azure/core/pipeline/policies/_retry.py +1 -1
  11. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_bearer_token_provider.py +1 -1
  12. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/authorization_code.py +1 -1
  13. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azd_cli.py +82 -17
  14. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_cli.py +28 -5
  15. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_powershell.py +28 -4
  16. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/broker.py +79 -0
  17. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/chained.py +9 -3
  18. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +153 -53
  19. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/imds.py +25 -1
  20. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/shared_cache.py +12 -5
  21. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/vscode.py +163 -144
  22. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/workload_identity.py +23 -12
  23. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/__init__.py +4 -0
  24. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/interactive.py +14 -2
  25. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/pipeline.py +4 -2
  26. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/utils.py +96 -0
  27. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
  28. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_bearer_token_provider.py +3 -3
  29. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/authorization_code.py +1 -1
  30. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azd_cli.py +32 -13
  31. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_cli.py +26 -5
  32. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_powershell.py +13 -2
  33. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/chained.py +1 -1
  34. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +120 -55
  35. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/imds.py +27 -1
  36. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/on_behalf_of.py +1 -1
  37. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/shared_cache.py +12 -5
  38. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/vscode.py +15 -67
  39. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/workload_identity.py +17 -13
  40. py2docfx/venv/venv1/Lib/site-packages/cffi/__init__.py +2 -2
  41. py2docfx/venv/venv1/Lib/site-packages/cffi/cparser.py +1 -1
  42. py2docfx/venv/venv1/Lib/site-packages/cffi/recompiler.py +5 -5
  43. py2docfx/venv/venv1/Lib/site-packages/cffi/setuptools_ext.py +13 -0
  44. py2docfx/venv/venv1/Lib/site-packages/cffi/vengine_cpy.py +3 -0
  45. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/api.py +3 -2
  46. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/legacy.py +17 -1
  47. py2docfx/venv/venv1/Lib/site-packages/charset_normalizer/version.py +1 -1
  48. py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +1 -1
  49. py2docfx/venv/venv1/Lib/site-packages/cryptography/__init__.py +0 -13
  50. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/_oid.py +8 -0
  51. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/asn1/__init__.py +10 -0
  52. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/asn1/asn1.py +116 -0
  53. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/backends/openssl/backend.py +3 -9
  54. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/declarative_asn1.pyi +32 -0
  55. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/openssl/kdf.pyi +23 -0
  56. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/_rust/x509.pyi +1 -13
  57. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/openssl/_conditional.py +16 -0
  58. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/bindings/openssl/binding.py +16 -1
  59. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py +0 -2
  60. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py +8 -0
  61. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py +0 -47
  62. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/hkdf.py +6 -91
  63. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/kdf/kbkdf.py +1 -3
  64. py2docfx/venv/venv1/Lib/site-packages/cryptography/hazmat/primitives/serialization/ssh.py +1 -1
  65. py2docfx/venv/venv1/Lib/site-packages/cryptography/utils.py +0 -2
  66. py2docfx/venv/venv1/Lib/site-packages/cryptography/x509/name.py +2 -3
  67. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/__init__.py +1 -1
  68. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/any_pb2.py +2 -2
  69. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/api_pb2.py +12 -8
  70. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/compiler/plugin_pb2.py +2 -2
  71. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor.py +398 -246
  72. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor_pb2.py +74 -72
  73. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/descriptor_pool.py +5 -4
  74. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/duration_pb2.py +2 -2
  75. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/empty_pb2.py +2 -2
  76. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/field_mask_pb2.py +2 -2
  77. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/api_implementation.py +0 -6
  78. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/extension_dict.py +3 -3
  79. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/field_mask.py +3 -3
  80. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/python_edition_defaults.py +1 -1
  81. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/python_message.py +10 -2
  82. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/internal/type_checkers.py +47 -5
  83. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/json_format.py +55 -32
  84. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/runtime_version.py +6 -26
  85. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/source_context_pb2.py +2 -2
  86. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/struct_pb2.py +2 -2
  87. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/text_format.py +30 -19
  88. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/timestamp_pb2.py +2 -2
  89. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/type_pb2.py +2 -2
  90. py2docfx/venv/venv1/Lib/site-packages/google/protobuf/wrappers_pb2.py +2 -2
  91. py2docfx/venv/venv1/Lib/site-packages/pycparser/__init__.py +1 -1
  92. py2docfx/venv/venv1/Lib/site-packages/pycparser/c_generator.py +1 -1
  93. py2docfx/venv/venv1/Lib/site-packages/pycparser/c_lexer.py +14 -0
  94. py2docfx/venv/venv1/Lib/site-packages/pycparser/c_parser.py +30 -7
  95. py2docfx/venv/venv1/Lib/site-packages/pycparser/lextab.py +1 -1
  96. py2docfx/venv/venv1/Lib/site-packages/pycparser/yacctab.py +132 -127
  97. py2docfx/venv/venv1/Lib/site-packages/requests/__version__.py +2 -2
  98. py2docfx/venv/venv1/Lib/site-packages/requests/adapters.py +17 -40
  99. py2docfx/venv/venv1/Lib/site-packages/requests/sessions.py +1 -1
  100. py2docfx/venv/venv1/Lib/site-packages/typing_extensions.py +91 -18
  101. {py2docfx-0.1.20rc2195074.dist-info → py2docfx-0.1.20rc2245107.dist-info}/METADATA +1 -1
  102. {py2docfx-0.1.20rc2195074.dist-info → py2docfx-0.1.20rc2245107.dist-info}/RECORD +104 -103
  103. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/linux_vscode_adapter.py +0 -100
  104. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/macos_vscode_adapter.py +0 -34
  105. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/win_vscode_adapter.py +0 -77
  106. {py2docfx-0.1.20rc2195074.dist-info → py2docfx-0.1.20rc2245107.dist-info}/WHEEL +0 -0
  107. {py2docfx-0.1.20rc2195074.dist-info → py2docfx-0.1.20rc2245107.dist-info}/top_level.txt +0 -0
@@ -2,49 +2,37 @@
2
2
  # Copyright (c) Microsoft Corporation.
3
3
  # Licensed under the MIT License.
4
4
  # ------------------------------------
5
- from typing import cast, Optional, Any
5
+ from typing import Optional, Any
6
6
 
7
7
  from azure.core.credentials import AccessToken, AccessTokenInfo, TokenRequestOptions
8
- from azure.core.exceptions import ClientAuthenticationError
9
- from ..._exceptions import CredentialUnavailableError
10
8
  from .._internal import AsyncContextManager
11
- from .._internal.aad_client import AadClient
12
- from .._internal.get_token_mixin import GetTokenMixin
13
9
  from .._internal.decorators import log_get_token_async
14
- from ..._credentials.vscode import _VSCodeCredentialBase
15
- from ..._internal import within_dac
10
+ from ..._credentials.vscode import VisualStudioCodeCredential as SyncVSCodeCredential
16
11
 
17
12
 
18
- class VisualStudioCodeCredential(_VSCodeCredentialBase, AsyncContextManager, GetTokenMixin):
19
- """Authenticates as the Azure user signed in to Visual Studio Code via the 'Azure Account' extension.
13
+ class VisualStudioCodeCredential(AsyncContextManager):
14
+ """Authenticates as the Azure user signed in to Visual Studio Code via the 'Azure Resources' extension.
20
15
 
21
- **Deprecated**: This credential is deprecated because the Azure Account extension for Visual Studio Code, which
22
- this credential relies on, has been deprecated. See the Azure Account extension deprecation notice here:
23
- https://github.com/microsoft/vscode-azure-account/issues/964. Consider using other developer credentials such as
24
- AzureCliCredential, AzureDeveloperCliCredential, or AzurePowerShellCredential.
16
+ This currently only works in Windows/WSL environments and requires the 'azure-identity-broker'
17
+ package to be installed.
25
18
 
26
- :keyword str authority: Authority of a Microsoft Entra endpoint, for example "login.microsoftonline.com".
27
- This argument is required for a custom cloud and usually unnecessary otherwise. Defaults to the authority
28
- matching the "Azure: Cloud" setting in VS Code's user settings or, when that setting has no value, the
29
- authority for Azure Public Cloud.
30
- :keyword str tenant_id: ID of the tenant the credential should authenticate in. Defaults to the "Azure: Tenant"
31
- setting in VS Code's user settings or, when that setting has no value, the "organizations" tenant, which
32
- supports only Microsoft Entra work or school accounts.
19
+ :keyword str tenant_id: A Microsoft Entra tenant ID. Defaults to the tenant specified in the authentication
20
+ record file used by the Azure Resources extension.
33
21
  :keyword List[str] additionally_allowed_tenants: Specifies tenants in addition to the specified "tenant_id"
34
22
  for which the credential may acquire tokens. Add the wildcard value "*" to allow the credential to
35
23
  acquire tokens for any tenant the application can access.
36
24
  """
37
25
 
26
+ def __init__(self, **kwargs: Any) -> None:
27
+ self._sync_credential = SyncVSCodeCredential(**kwargs)
28
+
38
29
  async def __aenter__(self) -> "VisualStudioCodeCredential":
39
- if self._client:
40
- await self._client.__aenter__()
30
+ self._sync_credential.__enter__()
41
31
  return self
42
32
 
43
33
  async def close(self) -> None:
44
34
  """Close the credential's transport session."""
45
-
46
- if self._client:
47
- await self._client.__aexit__()
35
+ self._sync_credential.close()
48
36
 
49
37
  @log_get_token_async
50
38
  async def get_token(
@@ -66,22 +54,7 @@ class VisualStudioCodeCredential(_VSCodeCredentialBase, AsyncContextManager, Get
66
54
  :raises ~azure.identity.CredentialUnavailableError: the credential cannot retrieve user details from Visual
67
55
  Studio Code
68
56
  """
69
- if self._unavailable_reason:
70
- error_message = (
71
- self._unavailable_reason + "\n"
72
- "Visit https://aka.ms/azsdk/python/identity/vscodecredential/troubleshoot"
73
- " to troubleshoot this issue."
74
- )
75
- raise CredentialUnavailableError(message=error_message)
76
- if not self._client:
77
- raise CredentialUnavailableError("Initialization failed")
78
- if within_dac.get():
79
- try:
80
- token = await super().get_token(*scopes, claims=claims, tenant_id=tenant_id, **kwargs)
81
- return token
82
- except ClientAuthenticationError as ex:
83
- raise CredentialUnavailableError(message=ex.message) from ex
84
- return await super().get_token(*scopes, claims=claims, tenant_id=tenant_id, **kwargs)
57
+ return self._sync_credential.get_token(*scopes, claims=claims, tenant_id=tenant_id, **kwargs)
85
58
 
86
59
  async def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptions] = None) -> AccessTokenInfo:
87
60
  """Request an access token for `scopes` as the user currently signed in to Visual Studio Code.
@@ -99,29 +72,4 @@ class VisualStudioCodeCredential(_VSCodeCredentialBase, AsyncContextManager, Get
99
72
  :raises ~azure.identity.CredentialUnavailableError: the credential cannot retrieve user details from Visual
100
73
  Studio Code.
101
74
  """
102
- if self._unavailable_reason:
103
- error_message = (
104
- self._unavailable_reason + "\n"
105
- "Visit https://aka.ms/azsdk/python/identity/vscodecredential/troubleshoot"
106
- " to troubleshoot this issue."
107
- )
108
- raise CredentialUnavailableError(message=error_message)
109
- if within_dac.get():
110
- try:
111
- token = await super().get_token_info(*scopes, options=options)
112
- return token
113
- except ClientAuthenticationError as ex:
114
- raise CredentialUnavailableError(message=ex.message) from ex
115
- return await super().get_token_info(*scopes, options=options)
116
-
117
- async def _acquire_token_silently(self, *scopes: str, **kwargs: Any) -> Optional[AccessTokenInfo]:
118
- self._client = cast(AadClient, self._client)
119
- return self._client.get_cached_access_token(scopes, **kwargs)
120
-
121
- async def _request_token(self, *scopes: str, **kwargs: Any) -> AccessTokenInfo:
122
- refresh_token = self._get_refresh_token()
123
- self._client = cast(AadClient, self._client)
124
- return await self._client.obtain_token_by_refresh_token(scopes, refresh_token, **kwargs)
125
-
126
- def _get_client(self, **kwargs: Any) -> AadClient:
127
- return AadClient(**kwargs)
75
+ return self._sync_credential.get_token_info(*scopes, options=options)
@@ -5,7 +5,7 @@
5
5
  import os
6
6
  from typing import Any, Optional
7
7
  from .client_assertion import ClientAssertionCredential
8
- from ..._credentials.workload_identity import TokenFileMixin
8
+ from ..._credentials.workload_identity import TokenFileMixin, WORKLOAD_CONFIG_ERROR
9
9
  from ..._constants import EnvironmentVariables
10
10
 
11
11
 
@@ -52,21 +52,25 @@ class WorkloadIdentityCredential(ClientAssertionCredential, TokenFileMixin):
52
52
  tenant_id = tenant_id or os.environ.get(EnvironmentVariables.AZURE_TENANT_ID)
53
53
  client_id = client_id or os.environ.get(EnvironmentVariables.AZURE_CLIENT_ID)
54
54
  token_file_path = token_file_path or os.environ.get(EnvironmentVariables.AZURE_FEDERATED_TOKEN_FILE)
55
+
56
+ missing_args = []
55
57
  if not tenant_id:
56
- raise ValueError(
57
- "'tenant_id' is required. Please pass it in or set the "
58
- f"{EnvironmentVariables.AZURE_TENANT_ID} environment variable"
59
- )
58
+ missing_args.append("'tenant_id'")
60
59
  if not client_id:
61
- raise ValueError(
62
- "'client_id' is required. Please pass it in or set the "
63
- f"{EnvironmentVariables.AZURE_CLIENT_ID} environment variable"
64
- )
60
+ missing_args.append("'client_id'")
65
61
  if not token_file_path:
66
- raise ValueError(
67
- "'token_file_path' is required. Please pass it in or set the "
68
- f"{EnvironmentVariables.AZURE_FEDERATED_TOKEN_FILE} environment variable"
69
- )
62
+ missing_args.append("'token_file_path'")
63
+
64
+ if missing_args:
65
+ missing_args_str = ", ".join(missing_args)
66
+ error_message = f"{WORKLOAD_CONFIG_ERROR}. Missing required arguments: {missing_args_str}."
67
+ raise ValueError(error_message)
68
+
69
+ # Type assertions since we've validated these are not None
70
+ assert tenant_id is not None
71
+ assert client_id is not None
72
+ assert token_file_path is not None
73
+
70
74
  self._token_file_path = token_file_path
71
75
  super().__init__(
72
76
  tenant_id=tenant_id,
@@ -5,8 +5,8 @@ from .api import FFI
5
5
  from .error import CDefError, FFIError, VerificationError, VerificationMissing
6
6
  from .error import PkgConfigError
7
7
 
8
- __version__ = "1.17.1"
9
- __version_info__ = (1, 17, 1)
8
+ __version__ = "2.0.0"
9
+ __version_info__ = (2, 0, 0)
10
10
 
11
11
  # The verifier module file names are based on the CRC32 of a string that
12
12
  # contains the following version number. It may be older than __version__
@@ -59,7 +59,7 @@ def _workaround_for_old_pycparser(csource):
59
59
  # for "char***(*const)". This means we can't tell the difference
60
60
  # afterwards. But "char(*const(***))" gives us the right syntax
61
61
  # tree. The issue only occurs if there are several stars in
62
- # sequence with no parenthesis inbetween, just possibly qualifiers.
62
+ # sequence with no parenthesis in between, just possibly qualifiers.
63
63
  # Attempt to fix it by adding some parentheses in the source: each
64
64
  # time we see "* const" or "* const *", we add an opening
65
65
  # parenthesis before each star---the hard part is figuring out where
@@ -1,4 +1,4 @@
1
- import os, sys, io
1
+ import io, os, sys, sysconfig
2
2
  from . import ffiplatform, model
3
3
  from .error import VerificationError
4
4
  from .cffi_opcode import *
@@ -7,9 +7,9 @@ VERSION_BASE = 0x2601
7
7
  VERSION_EMBEDDED = 0x2701
8
8
  VERSION_CHAR16CHAR32 = 0x2801
9
9
 
10
- USE_LIMITED_API = (sys.platform != 'win32' or sys.version_info < (3, 0) or
11
- sys.version_info >= (3, 5))
12
-
10
+ USE_LIMITED_API = ((sys.platform != 'win32' or sys.version_info < (3, 0) or
11
+ sys.version_info >= (3, 5)) and
12
+ not sysconfig.get_config_var("Py_GIL_DISABLED")) # free-threaded doesn't yet support limited API
13
13
 
14
14
  class GlobalExpr:
15
15
  def __init__(self, name, address, type_op, size=0, check_value=0):
@@ -953,7 +953,7 @@ class Recompiler:
953
953
  if cname is None or fbitsize >= 0:
954
954
  offset = '(size_t)-1'
955
955
  elif named_ptr is not None:
956
- offset = '((char *)&((%s)4096)->%s) - (char *)4096' % (
956
+ offset = '(size_t)(((char *)&((%s)4096)->%s) - (char *)4096)' % (
957
957
  named_ptr.name, fldname)
958
958
  else:
959
959
  offset = 'offsetof(%s, %s)' % (tp.get_c_name(''), fldname)
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import sys
3
+ import sysconfig
3
4
 
4
5
  try:
5
6
  basestring
@@ -87,6 +88,7 @@ def _set_py_limited_api(Extension, kwds):
87
88
  Recently (2020) we started shipping only >= 3.5 wheels, though. So
88
89
  we'll give it another try and set py_limited_api on Windows >= 3.5.
89
90
  """
91
+ from cffi._shimmed_dist_utils import log
90
92
  from cffi import recompiler
91
93
 
92
94
  if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount')
@@ -101,6 +103,17 @@ def _set_py_limited_api(Extension, kwds):
101
103
  # try to set 'py_limited_api' anyway. At worst, we get a
102
104
  # warning.
103
105
  kwds['py_limited_api'] = True
106
+
107
+ if sysconfig.get_config_var("Py_GIL_DISABLED"):
108
+ if kwds.get('py_limited_api'):
109
+ log.info("Ignoring py_limited_api=True for free-threaded build.")
110
+
111
+ kwds['py_limited_api'] = False
112
+
113
+ if kwds.get('py_limited_api') is False:
114
+ # avoid setting Py_LIMITED_API if py_limited_api=False
115
+ # which _cffi_include.h does unless _CFFI_NO_LIMITED_API is defined
116
+ kwds.setdefault("define_macros", []).append(("_CFFI_NO_LIMITED_API", None))
104
117
  return kwds
105
118
 
106
119
  def _add_c_module(dist, ffi, module_name, source, source_extension, kwds):
@@ -124,6 +124,9 @@ class VCPythonEngine(object):
124
124
  prnt(' Py_DECREF(lib);')
125
125
  prnt(' return NULL;')
126
126
  prnt(' }')
127
+ prnt('#if Py_GIL_DISABLED')
128
+ prnt(' PyUnstable_Module_SetGIL(lib, Py_MOD_GIL_NOT_USED);')
129
+ prnt('#endif')
127
130
  prnt(' return lib;')
128
131
  prnt('}')
129
132
  prnt()
@@ -369,14 +369,15 @@ def from_bytes(
369
369
  # Preparing those fallbacks in case we got nothing.
370
370
  if (
371
371
  enable_fallback
372
- and encoding_iana in ["ascii", "utf_8", specified_encoding]
372
+ and encoding_iana
373
+ in ["ascii", "utf_8", specified_encoding, "utf_16", "utf_32"]
373
374
  and not lazy_str_hard_failure
374
375
  ):
375
376
  fallback_entry = CharsetMatch(
376
377
  sequences,
377
378
  encoding_iana,
378
379
  threshold,
379
- False,
380
+ bom_or_sig_available,
380
381
  [],
381
382
  decoded_payload,
382
383
  preemptive_declaration=specified_encoding,
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Any
4
4
  from warnings import warn
5
5
 
6
6
  from .api import from_bytes
7
- from .constant import CHARDET_CORRESPONDENCE
7
+ from .constant import CHARDET_CORRESPONDENCE, TOO_SMALL_SEQUENCE
8
8
 
9
9
  # TODO: remove this check when dropping Python 3.7 support
10
10
  if TYPE_CHECKING:
@@ -49,6 +49,22 @@ def detect(
49
49
  language = r.language if r is not None and r.language != "Unknown" else ""
50
50
  confidence = 1.0 - r.chaos if r is not None else None
51
51
 
52
+ # automatically lower confidence
53
+ # on small bytes samples.
54
+ # https://github.com/jawah/charset_normalizer/issues/391
55
+ if (
56
+ confidence is not None
57
+ and confidence >= 0.9
58
+ and encoding
59
+ not in {
60
+ "utf_8",
61
+ "ascii",
62
+ }
63
+ and r.bom is False # type: ignore[union-attr]
64
+ and len(byte_str) < TOO_SMALL_SEQUENCE
65
+ ):
66
+ confidence -= 0.2
67
+
52
68
  # Note: CharsetNormalizer does not return 'UTF-8-SIG' as the sig get stripped in the detection/normalization process
53
69
  # but chardet does return 'utf-8-sig' and it is a valid codec name.
54
70
  if r is not None and encoding == "utf_8" and r.bom:
@@ -4,5 +4,5 @@ Expose version
4
4
 
5
5
  from __future__ import annotations
6
6
 
7
- __version__ = "3.4.2"
7
+ __version__ = "3.4.3"
8
8
  VERSION = __version__.split(".")
@@ -10,7 +10,7 @@ __all__ = [
10
10
  "__version__",
11
11
  ]
12
12
 
13
- __version__ = "45.0.6"
13
+ __version__ = "46.0.1"
14
14
 
15
15
 
16
16
  __author__ = "The Python Cryptographic Authority and individual contributors"
@@ -4,10 +4,6 @@
4
4
 
5
5
  from __future__ import annotations
6
6
 
7
- import sys
8
- import warnings
9
-
10
- from cryptography import utils
11
7
  from cryptography.__about__ import __author__, __copyright__, __version__
12
8
 
13
9
  __all__ = [
@@ -15,12 +11,3 @@ __all__ = [
15
11
  "__copyright__",
16
12
  "__version__",
17
13
  ]
18
-
19
- if sys.version_info[:2] == (3, 7):
20
- warnings.warn(
21
- "Python 3.7 is no longer supported by the Python core team "
22
- "and support for it is deprecated in cryptography. The next release "
23
- "of cryptography will remove support for Python 3.7.",
24
- utils.CryptographyDeprecationWarning,
25
- stacklevel=2,
26
- )
@@ -166,6 +166,10 @@ class HashAlgorithmOID:
166
166
  SHA3_256 = ObjectIdentifier("1.3.6.1.4.1.37476.3.2.1.99.7.256")
167
167
  SHA3_384 = ObjectIdentifier("1.3.6.1.4.1.37476.3.2.1.99.7.384")
168
168
  SHA3_512 = ObjectIdentifier("1.3.6.1.4.1.37476.3.2.1.99.7.512")
169
+ SHA3_224_NIST = ObjectIdentifier("2.16.840.1.101.3.4.2.7")
170
+ SHA3_256_NIST = ObjectIdentifier("2.16.840.1.101.3.4.2.8")
171
+ SHA3_384_NIST = ObjectIdentifier("2.16.840.1.101.3.4.2.9")
172
+ SHA3_512_NIST = ObjectIdentifier("2.16.840.1.101.3.4.2.10")
169
173
 
170
174
 
171
175
  class PublicKeyAlgorithmOID:
@@ -290,6 +294,10 @@ _OID_NAMES = {
290
294
  HashAlgorithmOID.SHA3_256: "sha3_256",
291
295
  HashAlgorithmOID.SHA3_384: "sha3_384",
292
296
  HashAlgorithmOID.SHA3_512: "sha3_512",
297
+ HashAlgorithmOID.SHA3_224_NIST: "sha3_224",
298
+ HashAlgorithmOID.SHA3_256_NIST: "sha3_256",
299
+ HashAlgorithmOID.SHA3_384_NIST: "sha3_384",
300
+ HashAlgorithmOID.SHA3_512_NIST: "sha3_512",
293
301
  PublicKeyAlgorithmOID.DSA: "dsaEncryption",
294
302
  PublicKeyAlgorithmOID.EC_PUBLIC_KEY: "id-ecPublicKey",
295
303
  PublicKeyAlgorithmOID.RSAES_PKCS1_v1_5: "rsaEncryption",
@@ -0,0 +1,10 @@
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from cryptography.hazmat.asn1.asn1 import encode_der, sequence
6
+
7
+ __all__ = [
8
+ "encode_der",
9
+ "sequence",
10
+ ]
@@ -0,0 +1,116 @@
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import dataclasses
8
+ import sys
9
+ import typing
10
+
11
+ if sys.version_info < (3, 11):
12
+ import typing_extensions
13
+
14
+ # We use the `include_extras` parameter of `get_type_hints`, which was
15
+ # added in Python 3.9. This can be replaced by the `typing` version
16
+ # once the min version is >= 3.9
17
+ if sys.version_info < (3, 9):
18
+ get_type_hints = typing_extensions.get_type_hints
19
+ else:
20
+ get_type_hints = typing.get_type_hints
21
+ else:
22
+ get_type_hints = typing.get_type_hints
23
+
24
+ from cryptography.hazmat.bindings._rust import declarative_asn1
25
+
26
+ T = typing.TypeVar("T", covariant=True)
27
+ U = typing.TypeVar("U")
28
+
29
+
30
+ encode_der = declarative_asn1.encode_der
31
+
32
+
33
+ def _normalize_field_type(
34
+ field_type: typing.Any, field_name: str
35
+ ) -> declarative_asn1.AnnotatedType:
36
+ annotation = declarative_asn1.Annotation()
37
+
38
+ if hasattr(field_type, "__asn1_root__"):
39
+ annotated_root = field_type.__asn1_root__
40
+ if not isinstance(annotated_root, declarative_asn1.AnnotatedType):
41
+ raise TypeError(f"unsupported root type: {annotated_root}")
42
+ return annotated_root
43
+ else:
44
+ rust_field_type = declarative_asn1.non_root_python_to_rust(field_type)
45
+
46
+ return declarative_asn1.AnnotatedType(rust_field_type, annotation)
47
+
48
+
49
+ def _annotate_fields(
50
+ raw_fields: dict[str, type],
51
+ ) -> dict[str, declarative_asn1.AnnotatedType]:
52
+ fields = {}
53
+ for field_name, field_type in raw_fields.items():
54
+ # Recursively normalize the field type into something that the
55
+ # Rust code can understand.
56
+ annotated_field_type = _normalize_field_type(field_type, field_name)
57
+ fields[field_name] = annotated_field_type
58
+
59
+ return fields
60
+
61
+
62
+ def _register_asn1_sequence(cls: type[U]) -> None:
63
+ raw_fields = get_type_hints(cls, include_extras=True)
64
+ root = declarative_asn1.AnnotatedType(
65
+ declarative_asn1.Type.Sequence(cls, _annotate_fields(raw_fields)),
66
+ declarative_asn1.Annotation(),
67
+ )
68
+
69
+ setattr(cls, "__asn1_root__", root)
70
+
71
+
72
+ # Due to https://github.com/python/mypy/issues/19731, we can't define an alias
73
+ # for `dataclass_transform` that conditionally points to `typing` or
74
+ # `typing_extensions` depending on the Python version (like we do for
75
+ # `get_type_hints`).
76
+ # We work around it by making the whole decorated class conditional on the
77
+ # Python version.
78
+ if sys.version_info < (3, 11):
79
+
80
+ @typing_extensions.dataclass_transform(kw_only_default=True)
81
+ def sequence(cls: type[U]) -> type[U]:
82
+ # We use `dataclasses.dataclass` to add an __init__ method
83
+ # to the class with keyword-only parameters.
84
+ if sys.version_info >= (3, 10):
85
+ dataclass_cls = dataclasses.dataclass(
86
+ repr=False,
87
+ eq=False,
88
+ # `match_args` was added in Python 3.10 and defaults
89
+ # to True
90
+ match_args=False,
91
+ # `kw_only` was added in Python 3.10 and defaults to
92
+ # False
93
+ kw_only=True,
94
+ )(cls)
95
+ else:
96
+ dataclass_cls = dataclasses.dataclass(
97
+ repr=False,
98
+ eq=False,
99
+ )(cls)
100
+ _register_asn1_sequence(dataclass_cls)
101
+ return dataclass_cls
102
+
103
+ else:
104
+
105
+ @typing.dataclass_transform(kw_only_default=True)
106
+ def sequence(cls: type[U]) -> type[U]:
107
+ # Only add an __init__ method, with keyword-only
108
+ # parameters.
109
+ dataclass_cls = dataclasses.dataclass(
110
+ repr=False,
111
+ eq=False,
112
+ match_args=False,
113
+ kw_only=True,
114
+ )(cls)
115
+ _register_asn1_sequence(dataclass_cls)
116
+ return dataclass_cls
@@ -260,9 +260,7 @@ class Backend:
260
260
  return self._lib.Cryptography_HAS_EVP_PKEY_DHX == 1
261
261
 
262
262
  def x25519_supported(self) -> bool:
263
- if self._fips_enabled:
264
- return False
265
- return True
263
+ return not self._fips_enabled
266
264
 
267
265
  def x448_supported(self) -> bool:
268
266
  if self._fips_enabled:
@@ -274,9 +272,7 @@ class Backend:
274
272
  )
275
273
 
276
274
  def ed25519_supported(self) -> bool:
277
- if self._fips_enabled:
278
- return False
279
- return True
275
+ return not self._fips_enabled
280
276
 
281
277
  def ed448_supported(self) -> bool:
282
278
  if self._fips_enabled:
@@ -294,9 +290,7 @@ class Backend:
294
290
  )
295
291
 
296
292
  def poly1305_supported(self) -> bool:
297
- if self._fips_enabled:
298
- return False
299
- return True
293
+ return not self._fips_enabled
300
294
 
301
295
  def pkcs7_supported(self) -> bool:
302
296
  return (
@@ -0,0 +1,32 @@
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+ import typing
5
+
6
+ def encode_der(value: typing.Any) -> bytes: ...
7
+ def non_root_python_to_rust(cls: type) -> Type: ...
8
+
9
+ # Type is a Rust enum with tuple variants. For now, we express the type
10
+ # annotations like this:
11
+ class Type:
12
+ Sequence: typing.ClassVar[type]
13
+ PyInt: typing.ClassVar[type]
14
+
15
+ class Annotation:
16
+ def __new__(
17
+ cls,
18
+ ) -> Annotation: ...
19
+
20
+ class AnnotatedType:
21
+ inner: Type
22
+ annotation: Annotation
23
+
24
+ def __new__(cls, inner: Type, annotation: Annotation) -> AnnotatedType: ...
25
+
26
+ class AnnotatedTypeObject:
27
+ annotated_type: AnnotatedType
28
+ value: typing.Any
29
+
30
+ def __new__(
31
+ cls, annotated_type: AnnotatedType, value: typing.Any
32
+ ) -> AnnotatedTypeObject: ...
@@ -47,3 +47,26 @@ class Argon2id:
47
47
  def verify_phc_encoded(
48
48
  cls, key_material: bytes, phc_encoded: str, secret: bytes | None = None
49
49
  ) -> None: ...
50
+
51
+ class HKDF:
52
+ def __init__(
53
+ self,
54
+ algorithm: HashAlgorithm,
55
+ length: int,
56
+ salt: bytes | None,
57
+ info: bytes | None,
58
+ backend: typing.Any = None,
59
+ ): ...
60
+ def derive(self, key_material: Buffer) -> bytes: ...
61
+ def verify(self, key_material: bytes, expected_key: bytes) -> None: ...
62
+
63
+ class HKDFExpand:
64
+ def __init__(
65
+ self,
66
+ algorithm: HashAlgorithm,
67
+ length: int,
68
+ info: bytes | None,
69
+ backend: typing.Any = None,
70
+ ): ...
71
+ def derive(self, key_material: Buffer) -> bytes: ...
72
+ def verify(self, key_material: bytes, expected_key: bytes) -> None: ...
@@ -198,7 +198,6 @@ class CertificateSigningRequest:
198
198
  def tbs_certrequest_bytes(self) -> bytes: ...
199
199
  @property
200
200
  def is_signature_valid(self) -> bool: ...
201
- def get_attribute_for_oid(self, oid: x509.ObjectIdentifier) -> bytes: ...
202
201
 
203
202
  class PolicyBuilder:
204
203
  def time(self, time: datetime.datetime) -> PolicyBuilder: ...
@@ -278,10 +277,6 @@ class ClientVerifier:
278
277
  @property
279
278
  def policy(self) -> Policy: ...
280
279
  @property
281
- def validation_time(self) -> datetime.datetime: ...
282
- @property
283
- def max_chain_depth(self) -> int: ...
284
- @property
285
280
  def store(self) -> Store: ...
286
281
  def verify(
287
282
  self,
@@ -293,12 +288,6 @@ class ServerVerifier:
293
288
  @property
294
289
  def policy(self) -> Policy: ...
295
290
  @property
296
- def subject(self) -> x509.verification.Subject: ...
297
- @property
298
- def validation_time(self) -> datetime.datetime: ...
299
- @property
300
- def max_chain_depth(self) -> int: ...
301
- @property
302
291
  def store(self) -> Store: ...
303
292
  def verify(
304
293
  self,
@@ -309,5 +298,4 @@ class ServerVerifier:
309
298
  class Store:
310
299
  def __init__(self, certs: list[x509.Certificate]) -> None: ...
311
300
 
312
- class VerificationError(Exception):
313
- pass
301
+ class VerificationError(Exception): ...