Skip to content

Commit c34a4c3

Browse files
committed
Address first round of review comments
1 parent 5fd41f9 commit c34a4c3

File tree

9 files changed

+127
-77
lines changed

9 files changed

+127
-77
lines changed

third_party/2and3/cryptography/exceptions.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class AlreadyFinalized(Exception): ...
22
class AlreadyUpdated(Exception): ...
3+
class InvalidKey(Exception): ...
34
class InvalidSignature(Exception): ...
45
class InvalidTag(Exception): ...
56
class NotYetFinalized(Exception): ...
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from typing import List, Optional
22

3-
class Fernet:
3+
class InvalidToken(Exception): ...
4+
5+
class Fernet(object):
46
def __init__(self, key: bytes) -> None: ...
5-
def decrypt(self, token: bytes, ttl: Optional[int]) -> bytes: ...
7+
def decrypt(self, token: bytes, ttl: Optional[int] = ...) -> bytes: ...
68
def encrypt(self, data: bytes) -> bytes: ...
79
def extract_timestamp(self, token: bytes) -> int: ...
810
@classmethod
911
def generate_key(cls) -> bytes: ...
1012

11-
class MultiFernet:
13+
class MultiFernet(object):
1214
def __init__(self, fernets: List[Fernet]) -> None: ...
13-
def decrypt(self, token: bytes, ttl: Optional[int]) -> bytes: ...
15+
def decrypt(self, token: bytes, ttl: Optional[int] = ...) -> bytes: ...
1416
def encrypt(self, data: bytes) -> bytes: ...
1517
def rotate(self, msg: bytes) -> bytes: ...
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import Any
1+
from typing import Any, Optional
22

3-
class Binding:
4-
ffi: Any
5-
lib: Any
3+
class Binding(object):
4+
ffi: Optional[Any]
5+
lib: Optional[Any]
66
def init_static_locks(self) -> None: ...

third_party/2and3/cryptography/hazmat/primitives/asymmetric/dh.pyi

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ class DHParameters(metaclass=ABCMeta):
2020

2121
DHParametersWithSerialization = DHParameters
2222

23-
class DHParameterNumbers:
24-
p: int
25-
g: int
26-
q: int
23+
class DHParameterNumbers(object):
24+
@property
25+
def p(self) -> int: ...
26+
@property
27+
def g(self) -> int: ...
28+
@property
29+
def q(self) -> int: ...
2730
def __init__(self, p: int, g: int, q: Optional[int]) -> None: ...
2831
def parameters(self, backend: DHBackend) -> DHParameters: ...
2932

@@ -44,14 +47,18 @@ class DHPrivateKeyWithSerialization(DHPrivateKey):
4447
@abstractmethod
4548
def private_numbers(self) -> DHPrivateNumbers: ...
4649

47-
class DHPrivateNumbers:
48-
public_numbers: DHPublicNumbers
49-
x: int
50+
class DHPrivateNumbers(object):
51+
@property
52+
def public_numbers(self) -> DHPublicNumbers: ...
53+
@property
54+
def x(self) -> int: ...
5055
def __init__(self, x: int, public_numbers: DHPublicNumbers) -> None: ...
5156
def private_key(self, backend: DHBackend) -> DHPrivateKey: ...
5257

5358
class DHPublicKey(metaclass=ABCMeta):
54-
key_size: int
59+
@property
60+
@abstractmethod
61+
def key_size(self) -> int: ...
5562
@abstractmethod
5663
def parameters(self) -> DHParameters: ...
5764
@abstractmethod
@@ -61,8 +68,10 @@ class DHPublicKey(metaclass=ABCMeta):
6168

6269
DHPublicKeyWithSerialization = DHPublicKey
6370

64-
class DHPublicNumbers:
65-
parameter_numbers: DHParameterNumbers
66-
y: int
71+
class DHPublicNumbers(object):
72+
@property
73+
def parameter_numbers(self) -> DHParameterNumbers: ...
74+
@property
75+
def y(self) -> int: ...
6776
def __init__(self, y: int, parameter_numbers: DHParameterNumbers) -> None: ...
6877
def public_key(self, backend: DHBackend) -> DHPublicKey: ...

third_party/2and3/cryptography/hazmat/primitives/asymmetric/dsa.pyi

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ class DSAParametersWithNumbers(DSAParameters):
1313
@abstractmethod
1414
def parameter_numbers(self) -> DSAParameterNumbers: ...
1515

16-
class DSAParameterNumbers:
17-
p: int
18-
q: int
19-
g: int
16+
class DSAParameterNumbers(object):
17+
@property
18+
def p(self) -> int: ...
19+
@property
20+
def q(self) -> int: ...
21+
@property
22+
def g(self) -> int: ...
2023
def __init__(self, p: int, q: int, g: int) -> None: ...
2124
def parameters(self, backend: DSABackend) -> DSAParameters: ...
2225

2326
class DSAPrivateKey(metaclass=ABCMeta):
24-
key_size: int
27+
@property
28+
@abstractmethod
29+
def key_size(self) -> int: ...
2530
@abstractmethod
2631
def parameters(self) -> DSAParameters: ...
2732
@abstractmethod
@@ -37,13 +42,17 @@ class DSAPrivateKeyWithSerialization(DSAPrivateKey):
3742
@abstractmethod
3843
def private_numbers(self) -> DSAPrivateNumbers: ...
3944

40-
class DSAPrivateNumbers:
41-
x: int
42-
public_numbers: DSAPublicNumbers
45+
class DSAPrivateNumbers(object):
46+
@property
47+
def x(self) -> int: ...
48+
@property
49+
def public_numbers(self) -> DSAPublicNumbers: ...
4350
def __init__(self, x: int, public_numbers: DSAPublicNumbers) -> None: ...
4451

4552
class DSAPublicKey(metaclass=ABCMeta):
46-
key_size: int
53+
@property
54+
@abstractmethod
55+
def key_size(self) -> int: ...
4756
@abstractmethod
4857
def public_bytes(self, encoding: Encoding, format: PublicFormat) -> bytes: ...
4958
@abstractmethod
@@ -55,9 +64,11 @@ class DSAPublicKey(metaclass=ABCMeta):
5564

5665
DSAPublicKeyWithSerialization = DSAPublicKey
5766

58-
class DSAPublicNumbers:
59-
y: int
60-
parameter_numbers: DSAParameterNumbers
67+
class DSAPublicNumbers(object):
68+
@property
69+
def y(self) -> int: ...
70+
@property
71+
def parameter_numbers(self) -> DSAParameterNumbers: ...
6172
def __init__(self, y: int, parameter_numbers: DSAParameterNumbers) -> None: ...
6273

6374
def generate_parameters(key_size: int, backend: DSABackend) -> DSAParameters: ...

third_party/2and3/cryptography/hazmat/primitives/asymmetric/ec.pyi

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABCMeta, abstractmethod
2-
from typing import Union
2+
from typing import ClassVar, Union
33

44
from cryptography.hazmat.backends.interfaces import EllipticCurveBackend
55
from cryptography.hazmat.primitives.asymmetric.padding import AsymmetricPadding
@@ -9,8 +9,12 @@ from cryptography.hazmat.primitives.serialization import Encoding, KeySerializat
99
from cryptography.x509 import ObjectIdentifier
1010

1111
class EllipticCurve(metaclass=ABCMeta):
12-
key_size: int
13-
name: str
12+
@property
13+
@abstractmethod
14+
def key_size(self) -> int: ...
15+
@property
16+
@abstractmethod
17+
def name(self) -> str: ...
1418

1519
class BrainpoolP256R1(EllipticCurve): ...
1620
class BrainpoolP384R1(EllipticCurve): ...
@@ -32,29 +36,34 @@ class SECT409R1(EllipticCurve): ...
3236
class SECT571K1(EllipticCurve): ...
3337
class SECT571R1(EllipticCurve): ...
3438

35-
class EllipticCurveOID:
36-
SECP192R1: ObjectIdentifier
37-
SECP224R1: ObjectIdentifier
38-
SECP256K1: ObjectIdentifier
39-
SECP256R1: ObjectIdentifier
40-
SECP384R1: ObjectIdentifier
41-
SECP521R1: ObjectIdentifier
42-
BRAINPOOLP256R1: ObjectIdentifier
43-
BRAINPOOLP384R1: ObjectIdentifier
44-
BRAINPOOLP512R1: ObjectIdentifier
45-
SECT163K1: ObjectIdentifier
46-
SECT163R2: ObjectIdentifier
47-
SECT233K1: ObjectIdentifier
48-
SECT233R1: ObjectIdentifier
49-
SECT283K1: ObjectIdentifier
50-
SECT283R1: ObjectIdentifier
51-
SECT409K1: ObjectIdentifier
52-
SECT409R1: ObjectIdentifier
53-
SECT571K1: ObjectIdentifier
54-
SECT571R1: ObjectIdentifier
39+
class EllipticCurveOID(object):
40+
SECP192R1: ClassVar[ObjectIdentifier]
41+
SECP224R1: ClassVar[ObjectIdentifier]
42+
SECP256K1: ClassVar[ObjectIdentifier]
43+
SECP256R1: ClassVar[ObjectIdentifier]
44+
SECP384R1: ClassVar[ObjectIdentifier]
45+
SECP521R1: ClassVar[ObjectIdentifier]
46+
BRAINPOOLP256R1: ClassVar[ObjectIdentifier]
47+
BRAINPOOLP384R1: ClassVar[ObjectIdentifier]
48+
BRAINPOOLP512R1: ClassVar[ObjectIdentifier]
49+
SECT163K1: ClassVar[ObjectIdentifier]
50+
SECT163R2: ClassVar[ObjectIdentifier]
51+
SECT233K1: ClassVar[ObjectIdentifier]
52+
SECT233R1: ClassVar[ObjectIdentifier]
53+
SECT283K1: ClassVar[ObjectIdentifier]
54+
SECT283R1: ClassVar[ObjectIdentifier]
55+
SECT409K1: ClassVar[ObjectIdentifier]
56+
SECT409R1: ClassVar[ObjectIdentifier]
57+
SECT571K1: ClassVar[ObjectIdentifier]
58+
SECT571R1: ClassVar[ObjectIdentifier]
5559

5660
class EllipticCurvePrivateKey(metaclass=ABCMeta):
57-
key_size: int
61+
@property
62+
@abstractmethod
63+
def curve(self) -> EllipticCurve: ...
64+
@property
65+
@abstractmethod
66+
def key_size(self) -> int: ...
5867
@abstractmethod
5968
def exchange(self, algorithm: ECDH, peer_public_key: EllipticCurvePublicKey) -> bytes: ...
6069
@abstractmethod
@@ -68,15 +77,21 @@ class EllipticCurvePrivateKeyWithSerialization(EllipticCurvePrivateKey):
6877
@abstractmethod
6978
def private_numbers(self) -> EllipticCurvePrivateNumbers: ...
7079

71-
class EllipticCurvePrivateNumbers:
72-
private_value: int
73-
public_numbers: EllipticCurvePublicNumbers
80+
class EllipticCurvePrivateNumbers(object):
81+
@property
82+
def private_value(self) -> int: ...
83+
@property
84+
def public_numbers(self) -> EllipticCurvePublicNumbers: ...
7485
def __init__(self, private_value: int, public_numbers: EllipticCurvePublicNumbers) -> None: ...
7586
def private_key(self, backend: EllipticCurveBackend) -> EllipticCurvePrivateKey: ...
7687

7788
class EllipticCurvePublicKey(metaclass=ABCMeta):
78-
curve: EllipticCurve
79-
key_size: int
89+
@property
90+
@abstractmethod
91+
def curve(self) -> EllipticCurve: ...
92+
@property
93+
@abstractmethod
94+
def key_size(self) -> int: ...
8095
@classmethod
8196
def from_encoded_point(cls, curve: EllipticCurve, data: bytes) -> EllipticCurvePublicKey: ...
8297
@abstractmethod
@@ -90,19 +105,24 @@ class EllipticCurvePublicKey(metaclass=ABCMeta):
90105

91106
EllipticCurvePublicKeyWithSerialization = EllipticCurvePublicKey
92107

93-
class EllipticCurvePublicNumbers:
94-
curve: EllipticCurve
95-
x: int
96-
y: int
108+
class EllipticCurvePublicNumbers(object):
109+
@property
110+
def curve(self) -> EllipticCurve: ...
111+
@property
112+
def x(self) -> int: ...
113+
@property
114+
def y(self) -> int: ...
97115
def __init__(self, x: int, y: int, curve: EllipticCurve) -> None: ...
98116
@classmethod
99117
def from_encoded_point(cls, curve: EllipticCurve, data: bytes) -> EllipticCurvePublicNumbers: ...
100118
def public_key(self, backend: EllipticCurveBackend) -> EllipticCurvePublicKey: ...
101119

102120
class EllipticCurveSignatureAlgorithm(metaclass=ABCMeta):
103-
algorithm: Union[HashAlgorithm, Prehashed]
121+
@property
122+
@abstractmethod
123+
def algorithm(self) -> Union[HashAlgorithm, Prehashed]: ...
104124

105-
class ECDH: ...
125+
class ECDH(object): ...
106126

107127
class ECDSA(EllipticCurveSignatureAlgorithm):
108128
def __init__(self, algorithm: HashAlgorithm): ...
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
from typing import Optional
1+
from abc import ABCMeta, abstractmethod
2+
from typing import ClassVar, Optional
23

34
from cryptography.hazmat.primitives.hashes import HashAlgorithm
45

5-
class AsymmetricPadding:
6-
name: str
6+
class AsymmetricPadding(metaclass=ABCMeta):
7+
@property
8+
@abstractmethod
9+
def name(self) -> str: ...
710

8-
class MGF1:
9-
def __init__(self, algorithm: HashAlgorithm): ...
11+
class MGF1(object):
12+
def __init__(self, algorithm: HashAlgorithm) -> None: ...
1013

1114
class OAEP(AsymmetricPadding):
12-
def __init__(self, mgf: MGF1, algorithm: HashAlgorithm, label: Optional[bytes]): ...
15+
def __init__(self, mgf: MGF1, algorithm: HashAlgorithm, label: Optional[bytes]) -> None: ...
1316

1417
class PKCS1v15(AsymmetricPadding): ...
1518

1619
class PSS(AsymmetricPadding):
17-
MAX_LENGTH: int
18-
def __init__(self, mgf: MGF1, salt_length: int): ...
20+
MAX_LENGTH: ClassVar[object]
21+
def __init__(self, mgf: MGF1, salt_length: int) -> None: ...

third_party/2and3/cryptography/hazmat/primitives/asymmetric/rsa.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ from cryptography.hazmat.primitives.hashes import HashAlgorithm
88
from cryptography.hazmat.primitives.serialization import Encoding, KeySerializationEncryption, PrivateFormat, PublicFormat
99

1010
class RSAPrivateKey(metaclass=ABCMeta):
11-
key_size: int
11+
@property
12+
@abstractmethod
13+
def key_size(self) -> int: ...
1214
@abstractmethod
1315
def decrypt(self, ciphertext: bytes, padding: AsymmetricPadding) -> bytes: ...
1416
@abstractmethod
@@ -25,7 +27,9 @@ class RSAPrivateKeyWithSerialization(RSAPrivateKey):
2527
def private_numbers(self) -> RSAPrivateNumbers: ...
2628

2729
class RSAPublicKey(metaclass=ABCMeta):
28-
key_size: int
30+
@property
31+
@abstractmethod
32+
def key_size(self) -> int: ...
2933
@abstractmethod
3034
def encrypt(self, plaintext: bytes, padding: AsymmetricPadding) -> bytes: ...
3135
@abstractmethod

third_party/2and3/cryptography/hazmat/primitives/asymmetric/utils.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ from typing import Tuple
33
def decode_dss_signature(signature: bytes) -> Tuple[int, int]: ...
44
def encode_dss_signature(r: int, s: int) -> bytes: ...
55

6-
class Prehashed: ...
6+
class Prehashed(object): ...

0 commit comments

Comments
 (0)