summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2023-04-23 14:47:19 +0200
committerSybren A. Stüvel <sybren@stuvel.eu>2023-04-23 15:10:44 +0200
commit0b52e7401ce0f34939a03d6d8da747352a6a7b94 (patch)
tree8c2ec2c2fce227853979c1a164893b8cb3697c6b
parent92fda6689b5167774d208555aa40ae23545c9123 (diff)
downloadrsa-git-0b52e7401ce0f34939a03d6d8da747352a6a7b94.tar.gz
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.
-rw-r--r--rsa/key.py7
1 files changed, 6 insertions, 1 deletions
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.