Skip to content

Commit 725be62

Browse files
authored
[Key Vault] Fix key instantiation errors. (#41205)
The latest version of `cryptography` now defines `__copy__` as an abstract method in both RSAPublicKey and RSAPrivateKey. `KeyVaultRSAPublicKey` and `KeyVaultRSAPrivateKey` need to implement this method so that they can be successfully instantiated. This change adds the `__copy__` method to both classes, returning `self` in each case. This mirrors behavior in `cryptography` and is appropriate because the key objects are immutable. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
1 parent 2f2eff8 commit 725be62

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

sdk/keyvault/azure-keyvault-keys/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- Fixed a bug where `KeyVaultRSAPublicKey` and `KeyVaultRSAPrivateKey` were not correctly implementing the `cryptography` library's `RSAPublicKey` and `RSAPrivateKey` interfaces, causing instantiation errors. ([#41205](https://github.com/Azure/azure-sdk-for-python/pull/41205))
1011

1112
### Other Changes
1213

@@ -151,7 +152,7 @@
151152
## 4.6.1 (2022-08-11)
152153

153154
### Other Changes
154-
- Documentation improvements
155+
- Documentation improvements
155156
([#25039](https://github.com/Azure/azure-sdk-for-python/issues/25039))
156157

157158
## 4.6.0b1 (2022-06-07)

sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/crypto/_models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
from __future__ import annotations
56
from typing import Any, cast, Optional, NoReturn, Union, TYPE_CHECKING
67

78
from cryptography.exceptions import InvalidSignature
@@ -308,6 +309,14 @@ def __eq__(self, other: object) -> bool:
308309
return all(getattr(self._key, field) == getattr(other, field) for field in self._key._FIELDS)
309310
return False
310311

312+
def __copy__(self) -> KeyVaultRSAPublicKey:
313+
"""Returns this instance since it is treated as immutable.
314+
315+
:returns: This instance.
316+
:rtype: ~azure.keyvault.keys.crypto.KeyVaultRSAPublicKey
317+
"""
318+
return self
319+
311320
def verifier( # pylint:disable=docstring-missing-param,docstring-missing-return,docstring-missing-rtype
312321
self, signature: bytes, padding: AsymmetricPadding, algorithm: HashAlgorithm
313322
) -> NoReturn:
@@ -482,6 +491,14 @@ def signer( # pylint:disable=docstring-missing-param,docstring-missing-return,d
482491
"""Not implemented. This method was deprecated in `cryptography` 2.0 and removed in 37.0.0."""
483492
raise NotImplementedError()
484493

494+
def __copy__(self) -> KeyVaultRSAPrivateKey:
495+
"""Returns this instance since it is treated as immutable.
496+
497+
:returns: This instance.
498+
:rtype: ~azure.keyvault.keys.crypto.KeyVaultRSAPrivateKey
499+
"""
500+
return self
501+
485502

486503
class DecryptResult:
487504
"""The result of a decrypt operation.

0 commit comments

Comments
 (0)