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

Commit 1ac38ff

Browse files
committed
improved from_string
1 parent 2958fe1 commit 1ac38ff

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

google/auth/crypt/rsa.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def from_string(cls, public_key):
7575
Raises:
7676
ValueError: If the public_key can't be parsed.
7777
"""
78-
return _cryptography_rsa.RSAVerifier.from_string(public_key)
78+
instance = cls.__new__(cls)
79+
instance._impl = _cryptography_rsa.RSAVerifier.from_string(public_key)
80+
return instance
7981

8082

8183
class RSASigner(base.Signer, base.FromServiceAccountMixin):
@@ -132,4 +134,6 @@ def from_string(cls, key, key_id=None):
132134
ValueError: If the key cannot be parsed as PKCS#1 or PKCS#8 in
133135
PEM format.
134136
"""
135-
return _cryptography_rsa.RSASigner.from_string(key, key_id=key_id)
137+
instance = cls.__new__(cls)
138+
instance._impl = _cryptography_rsa.RSASigner.from_string(key, key_id=key_id)
139+
return instance

tests/crypt/test_rsa.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_from_string_cryptography(self, mock_crypto):
8181

8282
result = rsa.RSAVerifier.from_string(PUBLIC_KEY_BYTES)
8383

84-
assert result == expected_verifier
84+
assert result._impl == expected_verifier
8585
mock_crypto.RSAVerifier.from_string.assert_called_once_with(PUBLIC_KEY_BYTES)
8686

8787

@@ -125,7 +125,7 @@ def test_from_string_delegates_to_cryptography(self, mock_crypto):
125125

126126
result = rsa.RSASigner.from_string(PRIVATE_KEY_BYTES, key_id="123")
127127

128-
assert result == expected_signer
128+
assert result._impl == expected_signer
129129
mock_crypto.RSASigner.from_string.assert_called_once_with(
130130
PRIVATE_KEY_BYTES, key_id="123"
131131
)
@@ -137,8 +137,8 @@ def test_end_to_end_cryptography_lib(self):
137137
verifier = rsa.RSAVerifier.from_string(PUBLIC_KEY_BYTES)
138138
result = verifier.verify(message, sig)
139139
assert result is True
140-
assert isinstance(verifier, _cryptography_rsa.RSAVerifier)
141-
assert isinstance(signer, _cryptography_rsa.RSASigner)
140+
assert isinstance(verifier._impl, _cryptography_rsa.RSAVerifier)
141+
assert isinstance(signer._impl, _cryptography_rsa.RSASigner)
142142

143143
def test_end_to_end_rsa_lib(self):
144144
signer = rsa.RSASigner(RSA_PRIVATE_KEY)

0 commit comments

Comments
 (0)