Skip to content

Commit 7d5ec53

Browse files
authored
Replace deprecated abstractproperty (#7943)
Deprecated since version 3.3, see https://docs.python.org/3/library/abc.html#abc.abstractproperty
1 parent 4fd0ff0 commit 7d5ec53

File tree

9 files changed

+184
-92
lines changed

9 files changed

+184
-92
lines changed

src/cryptography/hazmat/primitives/asymmetric/dsa.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def parameter_numbers(self) -> "DSAParameterNumbers":
2828

2929

3030
class DSAPrivateKey(metaclass=abc.ABCMeta):
31-
@abc.abstractproperty
31+
@property
32+
@abc.abstractmethod
3233
def key_size(self) -> int:
3334
"""
3435
The bit length of the prime modulus.
@@ -78,7 +79,8 @@ def private_bytes(
7879

7980

8081
class DSAPublicKey(metaclass=abc.ABCMeta):
81-
@abc.abstractproperty
82+
@property
83+
@abc.abstractmethod
8284
def key_size(self) -> int:
8385
"""
8486
The bit length of the prime modulus.

src/cryptography/hazmat/primitives/asymmetric/ec.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,24 @@ class EllipticCurveOID:
3535

3636

3737
class EllipticCurve(metaclass=abc.ABCMeta):
38-
@abc.abstractproperty
38+
@property
39+
@abc.abstractmethod
3940
def name(self) -> str:
4041
"""
4142
The name of the curve. e.g. secp256r1.
4243
"""
4344

44-
@abc.abstractproperty
45+
@property
46+
@abc.abstractmethod
4547
def key_size(self) -> int:
4648
"""
4749
Bit size of a secret scalar for the curve.
4850
"""
4951

5052

5153
class EllipticCurveSignatureAlgorithm(metaclass=abc.ABCMeta):
52-
@abc.abstractproperty
54+
@property
55+
@abc.abstractmethod
5356
def algorithm(
5457
self,
5558
) -> typing.Union[asym_utils.Prehashed, hashes.HashAlgorithm]:
@@ -74,13 +77,15 @@ def public_key(self) -> "EllipticCurvePublicKey":
7477
The EllipticCurvePublicKey for this private key.
7578
"""
7679

77-
@abc.abstractproperty
80+
@property
81+
@abc.abstractmethod
7882
def curve(self) -> EllipticCurve:
7983
"""
8084
The EllipticCurve that this key is on.
8185
"""
8286

83-
@abc.abstractproperty
87+
@property
88+
@abc.abstractmethod
8489
def key_size(self) -> int:
8590
"""
8691
Bit size of a secret scalar for the curve.
@@ -118,13 +123,15 @@ def private_bytes(
118123

119124

120125
class EllipticCurvePublicKey(metaclass=abc.ABCMeta):
121-
@abc.abstractproperty
126+
@property
127+
@abc.abstractmethod
122128
def curve(self) -> EllipticCurve:
123129
"""
124130
The EllipticCurve that this key is on.
125131
"""
126132

127-
@abc.abstractproperty
133+
@property
134+
@abc.abstractmethod
128135
def key_size(self) -> int:
129136
"""
130137
Bit size of a secret scalar for the curve.

src/cryptography/hazmat/primitives/asymmetric/rsa.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def decrypt(self, ciphertext: bytes, padding: AsymmetricPadding) -> bytes:
1919
Decrypts the provided ciphertext.
2020
"""
2121

22-
@abc.abstractproperty
22+
@property
23+
@abc.abstractmethod
2324
def key_size(self) -> int:
2425
"""
2526
The bit length of the public modulus.
@@ -70,7 +71,8 @@ def encrypt(self, plaintext: bytes, padding: AsymmetricPadding) -> bytes:
7071
Encrypts the given plaintext.
7172
"""
7273

73-
@abc.abstractproperty
74+
@property
75+
@abc.abstractmethod
7476
def key_size(self) -> int:
7577
"""
7678
The bit length of the public modulus.

src/cryptography/hazmat/primitives/ciphers/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def finalize_with_tag(self, tag: bytes) -> bytes:
6060

6161

6262
class AEADEncryptionContext(AEADCipherContext, metaclass=abc.ABCMeta):
63-
@abc.abstractproperty
63+
@property
64+
@abc.abstractmethod
6465
def tag(self) -> bytes:
6566
"""
6667
Returns tag bytes. This is only available after encryption is

src/cryptography/hazmat/primitives/ciphers/modes.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717

1818
class Mode(metaclass=abc.ABCMeta):
19-
@abc.abstractproperty
19+
@property
20+
@abc.abstractmethod
2021
def name(self) -> str:
2122
"""
2223
A string naming this mode (e.g. "ECB", "CBC").
@@ -31,31 +32,35 @@ def validate_for_algorithm(self, algorithm: CipherAlgorithm) -> None:
3132

3233

3334
class ModeWithInitializationVector(Mode, metaclass=abc.ABCMeta):
34-
@abc.abstractproperty
35+
@property
36+
@abc.abstractmethod
3537
def initialization_vector(self) -> bytes:
3638
"""
3739
The value of the initialization vector for this mode as bytes.
3840
"""
3941

4042

4143
class ModeWithTweak(Mode, metaclass=abc.ABCMeta):
42-
@abc.abstractproperty
44+
@property
45+
@abc.abstractmethod
4346
def tweak(self) -> bytes:
4447
"""
4548
The value of the tweak for this mode as bytes.
4649
"""
4750

4851

4952
class ModeWithNonce(Mode, metaclass=abc.ABCMeta):
50-
@abc.abstractproperty
53+
@property
54+
@abc.abstractmethod
5155
def nonce(self) -> bytes:
5256
"""
5357
The value of the nonce for this mode as bytes.
5458
"""
5559

5660

5761
class ModeWithAuthenticationTag(Mode, metaclass=abc.ABCMeta):
58-
@abc.abstractproperty
62+
@property
63+
@abc.abstractmethod
5964
def tag(self) -> typing.Optional[bytes]:
6065
"""
6166
The value of the tag supplied to the constructor of this mode.

0 commit comments

Comments
 (0)