Skip to content

Commit 370bc35

Browse files
Refactor: Remove rsa and make cryptography a core dependency
This commit removes the `rsa` library as a dependency and makes the `cryptography` library a required, core dependency. Previously, `cryptography` was an optional dependency, and the library would fall back to a pure Python RSA implementation using the `rsa` library if `cryptography` was not installed. Changes made: - Modified `setup.py` to remove `rsa` from dependencies and add `cryptography` with version constraints. - Updated `google/auth/crypt/rsa.py` to directly use the `cryptography`-based RSA implementation (`_cryptography_rsa.py`) and remove the fallback mechanism. - Removed the pure Python RSA implementation file (`google/auth/crypt/_python_rsa.py`). - Removed the corresponding tests for the pure Python RSA implementation (`tests/crypt/test__python_rsa.py`). Core unit tests pass after these changes.
1 parent 7c61c7d commit 370bc35

File tree

4 files changed

+7
-390
lines changed

4 files changed

+7
-390
lines changed

google/auth/crypt/_python_rsa.py

Lines changed: 0 additions & 175 deletions
This file was deleted.

google/auth/crypt/rsa.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,8 @@
1414

1515
"""RSA cryptography signer and verifier."""
1616

17+
from google.auth.crypt._cryptography_rsa import RSASigner
18+
from google.auth.crypt._cryptography_rsa import RSAVerifier
1719

18-
try:
19-
# Prefer cryptograph-based RSA implementation.
20-
from google.auth.crypt import _cryptography_rsa
2120

22-
RSASigner = _cryptography_rsa.RSASigner
23-
RSAVerifier = _cryptography_rsa.RSAVerifier
24-
except ImportError: # pragma: NO COVER
25-
# Fallback to pure-python RSA implementation if cryptography is
26-
# unavailable.
27-
from google.auth.crypt import _python_rsa
28-
29-
RSASigner = _python_rsa.RSASigner # type: ignore
30-
RSAVerifier = _python_rsa.RSAVerifier # type: ignore
21+
__all__ = ["RSASigner", "RSAVerifier"]

setup.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,22 @@
2424
"pyasn1-modules>=0.2.1",
2525
# rsa==4.5 is the last version to support 2.7
2626
# https://github.com/sybrenstuvel/python-rsa/issues/152#issuecomment-643470233
27-
"rsa>=3.1.4,<5",
28-
)
29-
30-
# TODO(https://github.com/googleapis/google-auth-library-python/issues/1737): Unit test fails with
31-
# `No module named 'cryptography.hazmat.backends.openssl.x509' for Python 3.7``.
32-
cryptography_base_require = [
3327
"cryptography >= 38.0.3",
3428
"cryptography < 39.0.0; python_version < '3.8'",
35-
]
29+
)
3630

3731
requests_extra_require = ["requests >= 2.20.0, < 3.0.0"]
3832

3933
aiohttp_extra_require = ["aiohttp >= 3.6.2, < 4.0.0", *requests_extra_require]
4034

41-
pyjwt_extra_require = ["pyjwt>=2.0", *cryptography_base_require]
35+
pyjwt_extra_require = ["pyjwt>=2.0"]
4236

4337
reauth_extra_require = ["pyu2f>=0.1.5"]
4438

4539
# TODO(https://github.com/googleapis/google-auth-library-python/issues/1738): Add bounds for cryptography and pyopenssl dependencies.
46-
enterprise_cert_extra_require = ["cryptography", "pyopenssl"]
40+
enterprise_cert_extra_require = ["pyopenssl"]
4741

48-
pyopenssl_extra_require = ["pyopenssl>=20.0.0", cryptography_base_require]
42+
pyopenssl_extra_require = ["pyopenssl>=20.0.0"]
4943

5044
# TODO(https://github.com/googleapis/google-auth-library-python/issues/1739): Add bounds for urllib3 and packaging dependencies.
5145
urllib3_extra_require = ["urllib3", "packaging"]

0 commit comments

Comments
 (0)