Skip to content

Commit fd4abe5

Browse files
Russ Allberyambv
authored andcommitted
Add full Python 2 type stubs for OpenSSL.crypto
Also adds the bare minimum of stubs for cryptography.hazmat.primitives.asymmetric to define the types referenced here. (cryptography is a full project in its own right, with lots of types and internal references.) This tries to use bytes in places where the module documentation emphasized that this was opaque bytes and str for arguments and return values that the module seemd to be treating as regular Python strings, even though this distinction is not horribly meaningful for Python 2.
1 parent 2580702 commit fd4abe5

File tree

7 files changed

+191
-4
lines changed

7 files changed

+191
-4
lines changed

third_party/2/OpenSSL/crypto.pyi

Lines changed: 183 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,185 @@
1+
# Stubs for OpenSSL.crypto (Python 2)
2+
3+
from typing import Any, Callable, Iterable, List, Optional, Set, Text, Tuple, Union
4+
5+
from cryptography.hazmat.primitives.asymmetric import dsa, rsa
6+
7+
FILETYPE_PEM = ... # type: int
8+
FILETYPE_ASN1 = ... # type: int
9+
FILETYPE_TEXT = ... # type: int
10+
TYPE_RSA = ... # type: int
11+
TYPE_DSA = ... # type: int
12+
13+
class Error(Exception): ...
14+
15+
class PKey:
16+
def __init__(self) -> None: ...
17+
def to_cryptography_key(self) -> Union[rsa.RSAPublicKey, rsa.RSAPrivateKey, dsa.DSAPublicKey, dsa.DSAPrivateKey]: ...
18+
@classmethod
19+
def from_cryptography_key(cls, crypto_key: Union[rsa.RSAPublicKey, rsa.RSAPrivateKey, dsa.DSAPublicKey, dsa.DSAPrivateKey]): ...
20+
def generate_key(self, type: int, bits: int) -> None: ...
21+
def check(self) -> bool: ...
22+
def type(self) -> int: ...
23+
def bits(self) -> int: ...
24+
25+
class _EllipticCurve:
26+
name = ... # type: Text
27+
28+
def get_elliptic_curves() -> Set[_EllipticCurve]: ...
29+
def get_elliptic_curve(name: str) -> _EllipticCurve: ...
30+
31+
class X509Name:
32+
def __init__(self, name: X509Name) -> None: ...
33+
countryName = ... # type: Union[str, unicode]
34+
stateOrProvinceName = ... # type: Union[str, unicode]
35+
localityName = ... # type: Union[str, unicode]
36+
organizationName = ... # type: Union[str, unicode]
37+
organizationalUnitName = ... # type: Union[str, unicode]
38+
commonName = ... # type: Union[str, unicode]
39+
emailAddress = ... # type: Union[str, unicode]
40+
C = ... # type: Union[str, unicode]
41+
ST = ... # type: Union[str, unicode]
42+
L = ... # type: Union[str, unicode]
43+
O = ... # type: Union[str, unicode]
44+
OU = ... # type: Union[str, unicode]
45+
CN = ... # type: Union[str, unicode]
46+
def hash(self) -> int: ...
47+
def der(self) -> bytes: ...
48+
def get_components(self) -> List[Tuple[str, str]]: ...
49+
50+
class X509Extension:
51+
def __init__(self, type_name: bytes, critical: bool, value: bytes, subject: Optional[X509] = ..., issuer: Optional[X509] = ...) -> None: ...
52+
def get_critical(self) -> bool: ...
53+
def get_short_name(self) -> str: ...
54+
def get_data(self) -> str: ...
55+
56+
class X509Req:
57+
def __init__(self) -> None: ...
58+
def set_pubkey(self, pkey: PKey) -> None: ...
59+
def get_pubkey(self) -> PKey: ...
60+
def set_version(self, version: int) -> None: ...
61+
def get_version(self) -> int: ...
62+
def get_subject(self) -> X509Name: ...
63+
def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ...
64+
def get_extensions(self) -> List[X509Extension]: ...
65+
def sign(self, pkey: PKey, digest: str) -> None: ...
66+
def verify(self, pkey: PKey) -> bool: ...
67+
168
class X509:
2-
...
69+
def __init__(self) -> None: ...
70+
def set_version(self, version: int) -> None: ...
71+
def get_version(self) -> int: ...
72+
def get_pubkey(self) -> PKey: ...
73+
def set_pubkey(self, pkey: PKey) -> None: ...
74+
def sign(self, pkey: PKey, digest: str) -> None: ...
75+
def get_signature_algorithm(self) -> str: ...
76+
def digest(self, digest_name: str) -> str: ...
77+
def subject_name_hash(self) -> str: ...
78+
def set_serial_number(self, serial: int) -> None: ...
79+
def get_serial_number(self) -> int: ...
80+
def gmtime_adj_notAfter(self, amount: int) -> None: ...
81+
def gmtime_adj_notBefore(self, amount: int) -> None: ...
82+
def has_expired(self) -> bool: ...
83+
def get_notBefore(self) -> str: ...
84+
def set_notBefore(self, when: str) -> None: ...
85+
def get_notAfter(self) -> str: ...
86+
def set_notAfter(self, when: str) -> None: ...
87+
def get_issuer(self) -> X509Name: ...
88+
def set_issuer(self, issuer: X509Name) -> None: ...
89+
def get_subject(self) -> X509Name: ...
90+
def set_subject(self, subject: X509Name) -> None: ...
91+
def get_extension_count(self) -> int: ...
92+
def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ...
93+
def get_extension(self, index: int) -> X509Extension: ...
94+
95+
class X509StoreFlags:
96+
CRL_CHECK = ... # type: int
97+
CRL_CHECK_ALL = ... # type: int
98+
IGNORE_CRITICAL = ... # type: int
99+
X509_STRICT = ... # type: int
100+
ALLOW_PROXY_CERTS = ... # type: int
101+
POLICY_CHECK = ... # type: int
102+
EXPLICIT_POLICY = ... # type: int
103+
INHIBIT_MAP = ... # type: int
104+
NOTIFY_POLICY = ... # type: int
105+
CHECK_SS_SIGNATURE = ... # type: int
106+
CB_ISSUER_CHECK = ... # type: int
107+
108+
class X509Store:
109+
def __init__(self) -> None: ...
110+
def add_cert(self, cert: X509) -> None: ...
111+
def add_crl(self, crl: CRL) -> None: ...
112+
def set_flags(self, flags: int) -> None: ...
113+
114+
class X509StoreContextError(Exception):
115+
certificate = ... # type: X509
116+
def __init__(self, message: str, certificate: X509) -> None: ...
117+
118+
class X509StoreContext:
119+
def __init__(self, store: X509Store, certificate: X509) -> None: ...
120+
def set_store(self, store: X509Store) -> None: ...
121+
def verify_certificate(self) -> None: ...
122+
123+
def load_certificate(type: int, buffer: Union[str, unicode]) -> X509: ...
124+
def dump_certificate(type: int, cert: X509) -> bytes: ...
125+
def dump_publickey(type: int, pkey: PKey) -> bytes: ...
126+
def dump_privatekey(type: int, pkey: PKey, cipher: Optional[str] = ..., passphrase: Optional[Union[str, Callable[[int], int]]] = ...) -> bytes: ...
127+
128+
class Revoked:
129+
def __init__(self) -> None: ...
130+
def set_serial(self, hex_str: str) -> None: ...
131+
def get_serial(self) -> str: ...
132+
def set_reason(self, reason: str) -> None: ...
133+
def get_reason(self) -> str: ...
134+
def all_reasons(self) -> List[str]: ...
135+
def set_rev_date(self, when: str) -> None: ...
136+
def get_rev_date(self) -> str: ...
137+
138+
class CRL:
139+
def __init__(self) -> None: ...
140+
def get_revoked(self) -> Tuple[Revoked, ...]: ...
141+
def add_revoked(self, revoked: Revoked) -> None: ...
142+
def get_issuer(self) -> X509Name: ...
143+
def set_version(self, version: int) -> None: ...
144+
def set_lastUpdate(self, when: str) -> None: ...
145+
def set_nextUpdate(self, when: str) -> None: ...
146+
def sign(self, issuer_cert: X509, issuer_key: PKey, digest: str) -> None: ...
147+
def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: str = ...) -> bytes: ...
148+
149+
class PKCS7:
150+
def type_is_signed(self) -> bool: ...
151+
def type_is_enveloped(self) -> bool: ...
152+
def type_is_signedAndEnveloped(self) -> bool: ...
153+
def type_is_data(self) -> bool: ...
154+
def get_type_name(self) -> str: ...
155+
156+
class PKCS12:
157+
def __init__(self) -> None: ...
158+
def get_certificate(self) -> X509: ...
159+
def set_certificate(self, cert: X509) -> None: ...
160+
def get_privatekey(self) -> PKey: ...
161+
def set_privatekey(self, pkey: PKey) -> None: ...
162+
def get_ca_certificates(self) -> Tuple[X509, ...]: ...
163+
def set_ca_certificates(self, cacerts: Iterable[X509]) -> None: ...
164+
def set_friendlyname(self, name: bytes) -> None: ...
165+
def get_friendlyname(self) -> bytes: ...
166+
def export(self, passphrase: Optional[str] = ..., iter: int = ..., maciter: int = ...): ...
167+
168+
class NetscapeSPKI:
169+
def __init__(self) -> None: ...
170+
def sign(self, pkey: PKey, digest: str) -> None: ...
171+
def verify(self, key: PKey) -> bool: ...
172+
def b64_encode(self) -> str: ...
173+
def get_pubkey(self) -> PKey: ...
174+
def set_pubkey(self, pkey: PKey) -> None: ...
3175

4-
def sign(key: str, data: str, digest: str) -> str: ...
5-
def verify(certificate: X509, signature: str, data: str, digest: str) -> None:
6-
raise Exception()
176+
def load_publickey(type: int, buffer: Union[str, unicode]) -> PKey: ...
177+
def load_privatekey(type: int, buffer: bytes, passphrase: Optional[Union[str, Callable[[int], int]]] = ...): ...
178+
def dump_certificate_request(type: int, req: X509Req): ...
179+
def load_certificate_request(type, buffer: Union[str, unicode]) -> X509Req: ...
180+
def sign(pkey: PKey, data: Union[str, unicode], digest: str) -> bytes: ...
181+
def verify(cert: X509, signature: bytes, data: Union[str, unicode], digest: str) -> None: ...
182+
def dump_crl(type: int, crl: CRL) -> bytes: ...
183+
def load_crl(type: int, buffer: Union[str, unicode]) -> CRL: ...
184+
def load_pkcs7_data(type: int, buffer: Union[str, unicode]) -> PKCS7: ...
185+
def load_pkcs12(buffer: Union[str, unicode], passphrase: Optional[Union[str, Callable[[int], int]]] = ...) -> PKCS12: ...

third_party/2/cryptography/__init__.pyi

Whitespace-only changes.

third_party/2/cryptography/hazmat/__init__.pyi

Whitespace-only changes.

third_party/2/cryptography/hazmat/primitives/__init__.pyi

Whitespace-only changes.

third_party/2/cryptography/hazmat/primitives/asymmetric/__init__.pyi

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Minimal stub expressing only the classes required by OpenSSL.crypto.
2+
3+
class DSAPrivateKey: ...
4+
class DSAPublicKey: ...
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Minimal stub expressing only the classes required by OpenSSL.crypto.
2+
3+
class RSAPrivateKey: ...
4+
class RSAPublicKey: ...

0 commit comments

Comments
 (0)