From 700efc43ddb1cac6e5c3f457b99bf775ffdede67 Mon Sep 17 00:00:00 2001 From: Brandon Lin Date: Wed, 15 Aug 2018 20:50:56 -0700 Subject: [PATCH] add missing stubs in cryptography `rsa`/`serialization` (#2376) --- .../hazmat/primitives/asymmetric/rsa.pyi | 59 ++++++++++++++++++- .../hazmat/primitives/serialization.pyi | 21 ++++--- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi b/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi index 57e3bef65..8ec4c98b9 100644 --- a/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi +++ b/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi @@ -1,4 +1,57 @@ -# Minimal stub expressing only the classes required by OpenSSL.crypto. +from cryptography.hazmat.primitives.serialization import Encoding, KeySerializationEncryption, PrivateFormat, PublicFormat +from typing import Tuple -class RSAPrivateKey: ... -class RSAPublicKey: ... +class RSAPrivateKey: + def signer(self, padding, algorithm): ... + def decrypt(self, ciphertext: bytes, padding) -> bytes: ... + def public_key(self) -> RSAPublicKey: ... + @property + def key_size(self) -> int: ... + def sign(self, data: bytes, padding, algorithm) -> bytes: ... + +class RSAPrivateKeyWithSerialization(RSAPrivateKey): + def private_numbers(self) -> RSAPrivateNumbers: ... + def private_bytes(self, encoding: Encoding, format: PrivateFormat, encryption_algorithm: KeySerializationEncryption) -> bytes: ... + +class RSAPublicKey: + def verifier(self, signature: bytes, padding, algorithm): ... + def encrypt(self, plaintext: bytes, padding) -> bytes: ... + @property + def key_size(self) -> int: ... + def public_numbers(self) -> RSAPublicNumbers: ... + def public_bytes(self, encoding: Encoding, format: PublicFormat) -> bytes: ... + def verify(self, signature: bytes, data: bytes, padding, algorithm) -> None: ... + +RSAPublicKeyWithSerialization = RSAPublicKey + +def generate_private_key(public_exponent: int, key_size: int, backend) -> RSAPrivateKey: ... +def rsa_crt_iqmp(p: int, q: int) -> int: ... +def rsa_crt_dmp1(private_exponent: int, p: int) -> int: ... +def rsa_crt_dmq1(private_exponent: int, q: int) -> int: ... +def rsa_recover_prime_factors(n: int, e: int, d: int) -> Tuple[int, int]: ... + +class RSAPrivateNumbers: + def __init__(self, p: int, q: int, d: int, dmp1: int, dmq1: int, iqmp: int, public_numbers: RSAPublicNumbers) -> None: ... + @property + def p(self) -> int: ... + @property + def q(self) -> int: ... + @property + def d(self) -> int: ... + @property + def dmp1(self) -> int: ... + @property + def dmq1(self) -> int: ... + @property + def iqmp(self) -> int: ... + @property + def public_numbers(self) -> RSAPublicNumbers: ... + def private_key(self, backend) -> RSAPrivateKey: ... + +class RSAPublicNumbers: + def __init__(self, e: int, n: int) -> None: ... + @property + def p(self) -> int: ... + @property + def q(self) -> int: ... + def public_key(self, backend) -> RSAPublicKey: ... diff --git a/third_party/2/cryptography/hazmat/primitives/serialization.pyi b/third_party/2/cryptography/hazmat/primitives/serialization.pyi index e2c506b0e..f37ebeeb6 100644 --- a/third_party/2/cryptography/hazmat/primitives/serialization.pyi +++ b/third_party/2/cryptography/hazmat/primitives/serialization.pyi @@ -1,15 +1,16 @@ -from typing import Any +from typing import Any, Optional from enum import Enum -def load_pem_private_key(data, password, backend): ... -def load_pem_public_key(data, backend): ... -def load_der_private_key(data, password, backend): ... -def load_der_public_key(data, backend): ... -def load_ssh_public_key(data, backend): ... +def load_pem_private_key(data: bytes, password: Optional[bytes], backend): ... +def load_pem_public_key(data: bytes, backend): ... +def load_der_private_key(data: bytes, password: Optional[bytes], backend): ... +def load_der_public_key(data: bytes, backend): ... +def load_ssh_public_key(data: bytes, backend): ... class Encoding(Enum): PEM = ... # type: str DER = ... # type: str + OpenSSH = ... # type: str class PrivateFormat(Enum): PKCS8 = ... # type: str @@ -18,11 +19,15 @@ class PrivateFormat(Enum): class PublicFormat(Enum): SubjectPublicKeyInfo = ... # type: str PKCS1 = ... # type: str + OpenSSH = ... # type: str + +class ParameterFormat(Enum): + PKCS3 = ... # type: str class KeySerializationEncryption: ... -class BestAvailableEncryption: +class BestAvailableEncryption(KeySerializationEncryption): password = ... # type: Any def __init__(self, password) -> None: ... -class NoEncryption: ... +class NoEncryption(KeySerializationEncryption): ...