8000 Make `AbstractKey` an actual abstract class · sybrenstuvel/python-rsa@0b52e74 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 20, 2025. It is now read-only.

Commit 0b52e74

Browse files
committed
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.
1 parent 92fda66 commit 0b52e74

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rsa/key.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
3232
"""
3333

34+
import abc
3435
import threading
3536
import typing
3637
import warnings
@@ -48,7 +49,7 @@
4849
T = typing.TypeVar("T", bound="AbstractKey")
4950

5051

51-
class AbstractKey:
52+
class AbstractKey(metaclass=abc.ABCMeta):
5253
"""Abstract superclass for private and public keys."""
5354

5455
__slots__ = ("n", "e", "blindfac", "blindfac_inverse", "mutex")
@@ -65,6 +66,7 @@ def __init__(self, n: int, e: int) -> None:
6566
self.mutex = threading.Lock()
6667

6768
@classmethod
69+
@abc.abstractmethod
6870
def _load_pkcs1_pem(cls: typing.Type[T], keyfile: bytes) -> T:
6971
"""Loads a key in PKCS#1 PEM format, implement in a subclass.
7072
@@ -77,6 +79,7 @@ def _load_pkcs1_pem(cls: typing.Type[T], keyfile: bytes) -> T:
7779
"""
7880

7981
@classmethod
82+
@abc.abstractmethod
8083
def _load_pkcs1_der(cls: typing.Type[T], keyfile: bytes) -> T:
8184
"""Loads a key in PKCS#1 PEM format, implement in a subclass.
8285
@@ -88,13 +91,15 @@ def _load_pkcs1_der(cls: typing.Type[T], keyfile: bytes) -> T:
8891
:rtype: AbstractKey
8992
"""
9093

94+
@abc.abstractmethod
9195
def _save_pkcs1_pem(self) -> bytes:
9296
"""Saves the key in PKCS#1 PEM format, implement in a subclass.
9397
9498
:returns: the PEM-encoded key.
9599
:rtype: bytes
96100
"""
97101

102+
@abc.abstractmethod
98103
def _save_pkcs1_der(self) -> bytes:
99104
"""Saves the key in PKCS#1 DER format, implement in a subclass.
100105

0 commit comments

Comments
 (0)
0