diff options
| author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2021-01-31 22:17:03 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-31 23:17:03 -0500 |
| commit | a47884cdfae4063d5a2187a2d269600b557ac6f6 (patch) | |
| tree | 41a320445b66e48e5728cb492f5dfd3c3950f99f /src | |
| parent | c05987e95182326dbe0ff061875968cd3f9ec37c (diff) | |
| download | cryptography-a47884cdfae4063d5a2187a2d269600b557ac6f6.tar.gz | |
ed448 type hints (#5730)
Diffstat (limited to 'src')
| -rw-r--r-- | src/cryptography/hazmat/backends/openssl/ed448.py | 31 | ||||
| -rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/ed448.py | 26 |
2 files changed, 37 insertions, 20 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/ed448.py b/src/cryptography/hazmat/backends/openssl/ed448.py index 0738c44e2..c787efdc6 100644 --- a/src/cryptography/hazmat/backends/openssl/ed448.py +++ b/src/cryptography/hazmat/backends/openssl/ed448.py @@ -3,7 +3,7 @@ # for complete details. -from cryptography import exceptions, utils +from cryptography import exceptions from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric.ed448 import ( Ed448PrivateKey, @@ -14,13 +14,16 @@ _ED448_KEY_SIZE = 57 _ED448_SIG_SIZE = 114 -@utils.register_interface(Ed448PublicKey) -class _Ed448PublicKey(object): +class _Ed448PublicKey(Ed448PublicKey): def __init__(self, backend, evp_pkey): self._backend = backend self._evp_pkey = evp_pkey - def public_bytes(self, encoding, format): + def public_bytes( + self, + encoding: serialization.Encoding, + format: serialization.PublicFormat, + ) -> bytes: if ( encoding is serialization.Encoding.Raw or format is serialization.PublicFormat.Raw @@ -39,7 +42,7 @@ class _Ed448PublicKey(object): encoding, format, self, self._evp_pkey, None ) - def _raw_public_bytes(self): + def _raw_public_bytes(self) -> bytes: buf = self._backend._ffi.new("unsigned char []", _ED448_KEY_SIZE) buflen = self._backend._ffi.new("size_t *", _ED448_KEY_SIZE) res = self._backend._lib.EVP_PKEY_get_raw_public_key( @@ -49,7 +52,7 @@ class _Ed448PublicKey(object): self._backend.openssl_assert(buflen[0] == _ED448_KEY_SIZE) return self._backend._ffi.buffer(buf, _ED448_KEY_SIZE)[:] - def verify(self, signature, data): + def verify(self, signature: bytes, data: bytes) -> None: evp_md_ctx = self._backend._lib.EVP_MD_CTX_new() self._backend.openssl_assert(evp_md_ctx != self._backend._ffi.NULL) evp_md_ctx = self._backend._ffi.gc( @@ -71,13 +74,12 @@ class _Ed448PublicKey(object): raise exceptions.InvalidSignature -@utils.register_interface(Ed448PrivateKey) -class _Ed448PrivateKey(object): +class _Ed448PrivateKey(Ed448PrivateKey): def __init__(self, backend, evp_pkey): self._backend = backend self._evp_pkey = evp_pkey - def public_key(self): + def public_key(self) -> Ed448PublicKey: buf = self._backend._ffi.new("unsigned char []", _ED448_KEY_SIZE) buflen = self._backend._ffi.new("size_t *", _ED448_KEY_SIZE) res = self._backend._lib.EVP_PKEY_get_raw_public_key( @@ -88,7 +90,7 @@ class _Ed448PrivateKey(object): public_bytes = self._backend._ffi.buffer(buf)[:] return self._backend.ed448_load_public_bytes(public_bytes) - def sign(self, data): + def sign(self, data: bytes) -> bytes: evp_md_ctx = self._backend._lib.EVP_MD_CTX_new() self._backend.openssl_assert(evp_md_ctx != self._backend._ffi.NULL) evp_md_ctx = self._backend._ffi.gc( @@ -111,7 +113,12 @@ class _Ed448PrivateKey(object): self._backend.openssl_assert(buflen[0] == _ED448_SIG_SIZE) return self._backend._ffi.buffer(buf, buflen[0])[:] - def private_bytes(self, encoding, format, encryption_algorithm): + def private_bytes( + self, + encoding: serialization.Encoding, + format: serialization.PrivateFormat, + encryption_algorithm: serialization.KeySerializationEncryption, + ) -> bytes: if ( encoding is serialization.Encoding.Raw or format is serialization.PublicFormat.Raw @@ -134,7 +141,7 @@ class _Ed448PrivateKey(object): encoding, format, encryption_algorithm, self, self._evp_pkey, None ) - def _raw_private_bytes(self): + def _raw_private_bytes(self) -> bytes: buf = self._backend._ffi.new("unsigned char []", _ED448_KEY_SIZE) buflen = self._backend._ffi.new("size_t *", _ED448_KEY_SIZE) res = self._backend._lib.EVP_PKEY_get_raw_private_key( diff --git a/src/cryptography/hazmat/primitives/asymmetric/ed448.py b/src/cryptography/hazmat/primitives/asymmetric/ed448.py index 3550e81e8..419854621 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/ed448.py +++ b/src/cryptography/hazmat/primitives/asymmetric/ed448.py @@ -6,11 +6,12 @@ import abc from cryptography.exceptions import UnsupportedAlgorithm, _Reasons +from cryptography.hazmat.primitives import _serialization class Ed448PublicKey(metaclass=abc.ABCMeta): @classmethod - def from_public_bytes(cls, data): + def from_public_bytes(cls, data: bytes) -> "Ed448PublicKey": from cryptography.hazmat.backends.openssl.backend import backend if not backend.ed448_supported(): @@ -22,13 +23,17 @@ class Ed448PublicKey(metaclass=abc.ABCMeta): return backend.ed448_load_public_bytes(data) @abc.abstractmethod - def public_bytes(self, encoding, format): + def public_bytes( + self, + encoding: _serialization.Encoding, + format: _serialization.PublicFormat, + ) -> bytes: """ The serialized bytes of the public key. """ @abc.abstractmethod - def verify(self, signature, data): + def verify(self, signature: bytes, data: bytes): """ Verify the signature. """ @@ -36,7 +41,7 @@ class Ed448PublicKey(metaclass=abc.ABCMeta): class Ed448PrivateKey(metaclass=abc.ABCMeta): @classmethod - def generate(cls): + def generate(cls) -> "Ed448PrivateKey": from cryptography.hazmat.backends.openssl.backend import backend if not backend.ed448_supported(): @@ -47,7 +52,7 @@ class Ed448PrivateKey(metaclass=abc.ABCMeta): return backend.ed448_generate_key() @classmethod - def from_private_bytes(cls, data): + def from_private_bytes(cls, data: bytes) -> "Ed448PrivateKey": from cryptography.hazmat.backends.openssl.backend import backend if not backend.ed448_supported(): @@ -59,19 +64,24 @@ class Ed448PrivateKey(metaclass=abc.ABCMeta): return backend.ed448_load_private_bytes(data) @abc.abstractmethod - def public_key(self): + def public_key(self) -> Ed448PublicKey: """ The Ed448PublicKey derived from the private key. """ @abc.abstractmethod - def sign(self, data): + def sign(self, data: bytes) -> bytes: """ Signs the data. """ @abc.abstractmethod - def private_bytes(self, encoding, format, encryption_algorithm): + def private_bytes( + self, + encoding: _serialization.Encoding, + format: _serialization.PrivateFormat, + encryption_algorithm: _serialization.KeySerializationEncryption, + ): """ The serialized bytes of the private key. """ |
