Skip to content

Commit 59b6abc

Browse files
chore: add warning for rsa library (#1925)
The `rsa` library is archived, and scheduled to be removed. `google-auth` already supports an alternate implementation, using `cryptography`. This PR adds a warning to users still relying on the old library, and adds `rsa` as an optional dependency to allow users to continue to opt-in to rsa during deprecation persion After release, a follow-up version will remove rsa as a required dependency, leaving it only for opt-in users
1 parent 056642b commit 59b6abc

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

packages/google-auth/google/auth/crypt/_python_rsa.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from __future__ import absolute_import
2323

2424
import io
25+
import warnings
2526

2627
from pyasn1.codec.der import decoder # type: ignore
2728
from pyasn1_modules import pem # type: ignore
@@ -39,6 +40,15 @@
3940
_PKCS8_MARKER = ("-----BEGIN PRIVATE KEY-----", "-----END PRIVATE KEY-----")
4041
_PKCS8_SPEC = PrivateKeyInfo()
4142

43+
warnings.warn(
44+
(
45+
"The 'rsa' library is deprecated and will be removed in a future release. "
46+
"Please migrate to 'cryptography'."
47+
),
48+
category=DeprecationWarning,
49+
stacklevel=2,
50+
)
51+
4252

4353
def _bit_list_to_bytes(bit_list):
4454
"""Converts an iterable of 1s and 0s to bytes.
@@ -64,6 +74,10 @@ def _bit_list_to_bytes(bit_list):
6474
class RSAVerifier(base.Verifier):
6575
"""Verifies RSA cryptographic signatures using public keys.
6676
77+
.. deprecated::
78+
The `rsa` library has been archived. Please migrate to
79+
`cryptography`.
80+
6781
Args:
6882
public_key (rsa.key.PublicKey): The public key used to verify
6983
signatures.
@@ -116,6 +130,10 @@ def from_string(cls, public_key):
116130
class RSASigner(base.Signer, base.FromServiceAccountMixin):
117131
"""Signs messages with an RSA private key.
118132
133+
.. deprecated::
134+
The `rsa` library has been archived. Please migrate to
135+
`cryptography`.
136+
119137
Args:
120138
private_key (rsa.key.PrivateKey): The private key to sign with.
121139
key_id (str): Optional key ID used to identify this private key. This

packages/google-auth/noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def unit(session):
129129
"--cov-report=term-missing",
130130
"tests",
131131
"tests_async",
132+
*session.posargs,
132133
)
133134

134135

packages/google-auth/tests/crypt/test__python_rsa.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,12 @@ def test_from_service_account_file(self):
191191

192192
assert signer.key_id == SERVICE_ACCOUNT_INFO[base._JSON_FILE_PRIVATE_KEY_ID]
193193
assert isinstance(signer._key, rsa.key.PrivateKey)
194+
195+
196+
class TestModule(object):
197+
def test_import_warning(self):
198+
import importlib
199+
from google.auth.crypt import _python_rsa
200+
201+
with pytest.warns(DeprecationWarning, match="The 'rsa' library is deprecated"):
202+
importlib.reload(_python_rsa)

0 commit comments

Comments
 (0)