Satisfy mypy

This commit is contained in:
Alex Stokes 2019-08-20 19:28:32 +02:00
parent 87d943aa39
commit e1d3f1601f
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086

View File

@ -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: