From e1d3f1601f25dec828e1830d2fbad375129bf0fe Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 20 Aug 2019 19:28:32 +0200 Subject: [PATCH] Satisfy mypy --- libp2p/crypto/keys.py | 47 +++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/libp2p/crypto/keys.py b/libp2p/crypto/keys.py index f0485ad5..31caca00 100644 --- a/libp2p/crypto/keys.py +++ b/libp2p/crypto/keys.py @@ -32,29 +32,12 @@ class Key(ABC): """ ... - def _serialize_to_protobuf(self) -> protobuf.PublicKey: - """ - Return the protobuf representation of this ``Key``. - """ - key_type = self.get_type().value - data = self.to_bytes() - protobuf_key = self.protobuf_constructor(key_type=key_type, data=data) - return protobuf_key - - def serialize(self) -> bytes: - """ - Return the canonical serialization of this ``Key``. - """ - return self._serialize_to_protobuf().SerializeToString() - class PublicKey(Key): """ A ``PublicKey`` represents a cryptographic public key. """ - protobuf_constructor = protobuf.PublicKey - @abstractmethod def verify(self, data: bytes, signature: bytes) -> bool: """ @@ -62,6 +45,21 @@ class PublicKey(Key): """ ... + def _serialize_to_protobuf(self) -> protobuf.PublicKey: + """ + Return the protobuf representation of this ``Key``. + """ + key_type = self.get_type().value + data = self.to_bytes() + protobuf_key = protobuf.PublicKey(key_type=key_type, data=data) + return protobuf_key + + def serialize(self) -> bytes: + """ + Return the canonical serialization of this ``Key``. + """ + return self._serialize_to_protobuf().SerializeToString() + class PrivateKey(Key): """ @@ -78,6 +76,21 @@ class PrivateKey(Key): def get_public_key(self) -> PublicKey: ... + def _serialize_to_protobuf(self) -> protobuf.PrivateKey: + """ + Return the protobuf representation of this ``Key``. + """ + key_type = self.get_type().value + data = self.to_bytes() + protobuf_key = protobuf.PrivateKey(key_type=key_type, data=data) + return protobuf_key + + def serialize(self) -> bytes: + """ + Return the canonical serialization of this ``Key``. + """ + return self._serialize_to_protobuf().SerializeToString() + @dataclass(frozen=True) class KeyPair: