1919for implmentations using different third party libraries
2020"""
2121
22+ from cryptography .hazmat .primitives .asymmetric .rsa import RSAPrivateKey
23+ from cryptography .hazmat .primitives .asymmetric .rsa import RSAPublicKey
2224from google .auth import _helpers
2325from google .auth .crypt import base
2426from google .auth .crypt import _cryptography_rsa
2527from google .auth .crypt import _python_rsa
2628
2729RSA_KEY_MODULE_PREFIX = "rsa.key"
28- CRYPTOGRAPHY_KEY_MODULE_PREFIX = "cryptography."
30+
2931
3032class RSAVerifier (base .Verifier ):
3133 """Verifies RSA cryptographic signatures using public keys.
@@ -45,10 +47,10 @@ class RSAVerifier(base.Verifier):
4547
4648 def __init__ (self , public_key ):
4749 module_str = public_key .__class__ .__module__
48- if module_str .startswith (RSA_KEY_MODULE_PREFIX ):
49- impl_lib = _python_rsa
50- elif module_str .startswith (CRYPTOGRAPHY_KEY_MODULE_PREFIX ):
50+ if isinstance (public_key , RSAPublicKey ):
5151 impl_lib = _cryptography_rsa
52+ elif module_str .startswith (RSA_KEY_MODULE_PREFIX ):
53+ impl_lib = _python_rsa
5254 else :
5355 raise ValueError (f"unrecognized public key type: { type (public_key )} " )
5456 self ._impl = impl_lib .RSAVerifier (public_key )
@@ -97,10 +99,10 @@ class RSASigner(base.Signer, base.FromServiceAccountMixin):
9799
98100 def __init__ (self , private_key , key_id = None ):
99101 module_str = private_key .__class__ .__module__
100- if module_str .startswith (RSA_KEY_MODULE_PREFIX ):
101- impl_lib = _python_rsa
102- elif module_str .startswith (CRYPTOGRAPHY_KEY_MODULE_PREFIX ):
102+ if isinstance (private_key , RSAPrivateKey ):
103103 impl_lib = _cryptography_rsa
104+ elif module_str .startswith (RSA_KEY_MODULE_PREFIX ):
105+ impl_lib = _python_rsa
104106 else :
105107 raise ValueError (f"unrecognized private key type: { type (private_key )} " )
106108 self ._impl = impl_lib .RSASigner (private_key , key_id = key_id )
0 commit comments