From 0b52e7401ce0f34939a03d6d8da747352a6a7b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Sun, 23 Apr 2023 14:47:19 +0200 Subject: Make `AbstractKey` an actual abstract class Decorate functions that subclassess should implement with `@abc.abstractmethod`. This is to fix a mypy error that'll show up when upgrading mypy. That upgrade will follow shortly -- I just wanted to make sure things keep working. --- rsa/key.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rsa/key.py b/rsa/key.py index f800644..fa195eb 100644 --- a/rsa/key.py +++ b/rsa/key.py @@ -31,6 +31,7 @@ of pyasn1. """ +import abc import threading import typing import warnings @@ -48,7 +49,7 @@ DEFAULT_EXPONENT = 65537 T = typing.TypeVar("T", bound="AbstractKey") -class AbstractKey: +class AbstractKey(metaclass=abc.ABCMeta): """Abstract superclass for private and public keys.""" __slots__ = ("n", "e", "blindfac", "blindfac_inverse", "mutex") @@ -65,6 +66,7 @@ class AbstractKey: self.mutex = threading.Lock() @classmethod + @abc.abstractmethod def _load_pkcs1_pem(cls: typing.Type[T], keyfile: bytes) -> T: """Loads a key in PKCS#1 PEM format, implement in a subclass. @@ -77,6 +79,7 @@ class AbstractKey: """ @classmethod + @abc.abstractmethod def _load_pkcs1_der(cls: typing.Type[T], keyfile: bytes) -> T: """Loads a key in PKCS#1 PEM format, implement in a subclass. @@ -88,6 +91,7 @@ class AbstractKey: :rtype: AbstractKey """ + @abc.abstractmethod def _save_pkcs1_pem(self) -> bytes: """Saves the key in PKCS#1 PEM format, implement in a subclass. @@ -95,6 +99,7 @@ class AbstractKey: :rtype: bytes """ + @abc.abstractmethod def _save_pkcs1_der(self) -> bytes: """Saves the key in PKCS#1 DER format, implement in a subclass. -- cgit v1.2.1