Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 9a8043f

Browse files
committed
import rsa only when needed
1 parent 1ac38ff commit 9a8043f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

google/auth/crypt/rsa.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
from google.auth import _helpers
2626
from google.auth.crypt import _cryptography_rsa
27-
from google.auth.crypt import _python_rsa
2827
from google.auth.crypt import base
2928

3029
RSA_KEY_MODULE_PREFIX = "rsa.key"
@@ -43,6 +42,7 @@ class RSAVerifier(base.Verifier):
4342
public_key (Union[rsa.key.PublicKey, cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey]):
4443
The public key used to verify signatures.
4544
Raises:
45+
ImportError: if called with an rsa.key.PublicKey, when the rsa library is not installed
4646
ValueError: if an unrecognized public key is provided
4747
"""
4848

@@ -51,6 +51,7 @@ def __init__(self, public_key):
5151
if isinstance(public_key, RSAPublicKey):
5252
impl_lib = _cryptography_rsa
5353
elif module_str.startswith(RSA_KEY_MODULE_PREFIX):
54+
from google.auth.crypt import _python_rsa
5455
impl_lib = _python_rsa
5556
else:
5657
raise ValueError(f"unrecognized public key type: {type(public_key)}")
@@ -97,6 +98,7 @@ class RSASigner(base.Signer, base.FromServiceAccountMixin):
9798
public key or certificate.
9899
99100
Raises:
101+
ImportError: if called with an rsa.key.PublicKey, when the rsa library is not installed
100102
ValueError: if an unrecognized public key is provided
101103
"""
102104

@@ -105,6 +107,7 @@ def __init__(self, private_key, key_id=None):
105107
if isinstance(private_key, RSAPrivateKey):
106108
impl_lib = _cryptography_rsa
107109
elif module_str.startswith(RSA_KEY_MODULE_PREFIX):
110+
from google.auth.crypt import _python_rsa
108111
impl_lib = _python_rsa
109112
else:
110113
raise ValueError(f"unrecognized private key type: {type(private_key)}")

0 commit comments

Comments
 (0)