Skip to content

Commit

Permalink
Replace deprecated abstractproperty (#7943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Dec 27, 2022
1 parent 4fd0ff0 commit 7d5ec53
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 92 deletions.
6 changes: 4 additions & 2 deletions src/cryptography/hazmat/primitives/asymmetric/dsa.py
Expand Up @@ -28,7 +28,8 @@ def parameter_numbers(self) -> "DSAParameterNumbers":


class DSAPrivateKey(metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def key_size(self) -> int:
"""
The bit length of the prime modulus.
Expand Down Expand Up @@ -78,7 +79,8 @@ def private_bytes(


class DSAPublicKey(metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def key_size(self) -> int:
"""
The bit length of the prime modulus.
Expand Down
21 changes: 14 additions & 7 deletions src/cryptography/hazmat/primitives/asymmetric/ec.py
Expand Up @@ -35,21 +35,24 @@ class EllipticCurveOID:


class EllipticCurve(metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def name(self) -> str:
"""
The name of the curve. e.g. secp256r1.
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def key_size(self) -> int:
"""
Bit size of a secret scalar for the curve.
"""


class EllipticCurveSignatureAlgorithm(metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def algorithm(
self,
) -> typing.Union[asym_utils.Prehashed, hashes.HashAlgorithm]:
Expand All @@ -74,13 +77,15 @@ def public_key(self) -> "EllipticCurvePublicKey":
The EllipticCurvePublicKey for this private key.
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def curve(self) -> EllipticCurve:
"""
The EllipticCurve that this key is on.
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def key_size(self) -> int:
"""
Bit size of a secret scalar for the curve.
Expand Down Expand Up @@ -118,13 +123,15 @@ def private_bytes(


class EllipticCurvePublicKey(metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def curve(self) -> EllipticCurve:
"""
The EllipticCurve that this key is on.
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def key_size(self) -> int:
"""
Bit size of a secret scalar for the curve.
Expand Down
6 changes: 4 additions & 2 deletions src/cryptography/hazmat/primitives/asymmetric/rsa.py
Expand Up @@ -19,7 +19,8 @@ def decrypt(self, ciphertext: bytes, padding: AsymmetricPadding) -> bytes:
Decrypts the provided ciphertext.
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def key_size(self) -> int:
"""
The bit length of the public modulus.
Expand Down Expand Up @@ -70,7 +71,8 @@ def encrypt(self, plaintext: bytes, padding: AsymmetricPadding) -> bytes:
Encrypts the given plaintext.
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def key_size(self) -> int:
"""
The bit length of the public modulus.
Expand Down
3 changes: 2 additions & 1 deletion src/cryptography/hazmat/primitives/ciphers/base.py
Expand Up @@ -60,7 +60,8 @@ def finalize_with_tag(self, tag: bytes) -> bytes:


class AEADEncryptionContext(AEADCipherContext, metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def tag(self) -> bytes:
"""
Returns tag bytes. This is only available after encryption is
Expand Down
15 changes: 10 additions & 5 deletions src/cryptography/hazmat/primitives/ciphers/modes.py
Expand Up @@ -16,7 +16,8 @@


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


class ModeWithInitializationVector(Mode, metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def initialization_vector(self) -> bytes:
"""
The value of the initialization vector for this mode as bytes.
"""


class ModeWithTweak(Mode, metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def tweak(self) -> bytes:
"""
The value of the tweak for this mode as bytes.
"""


class ModeWithNonce(Mode, metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def nonce(self) -> bytes:
"""
The value of the nonce for this mode as bytes.
"""


class ModeWithAuthenticationTag(Mode, metaclass=abc.ABCMeta):
@abc.abstractproperty
@property
@abc.abstractmethod
def tag(self) -> typing.Optional[bytes]:
"""
The value of the tag supplied to the constructor of this mode.
Expand Down

0 comments on commit 7d5ec53

Please sign in to comment.