|
1 | 1 | import calendar |
2 | 2 | import datetime |
3 | 3 | import functools |
| 4 | +import typing |
4 | 5 | from base64 import b16encode |
5 | 6 | from functools import partial |
6 | 7 | from os import PathLike |
|
22 | 23 | from cryptography.hazmat.primitives.asymmetric import ( |
23 | 24 | dsa, |
24 | 25 | ec, |
25 | | - ed25519, |
26 | 26 | ed448, |
| 27 | + ed25519, |
27 | 28 | rsa, |
28 | 29 | ) |
29 | 30 |
|
30 | 31 | from OpenSSL._util import ( |
31 | 32 | UNSPECIFIED as _UNSPECIFIED, |
| 33 | +) |
| 34 | +from OpenSSL._util import ( |
32 | 35 | byte_string as _byte_string, |
| 36 | +) |
| 37 | +from OpenSSL._util import ( |
33 | 38 | exception_from_error_queue as _exception_from_error_queue, |
| 39 | +) |
| 40 | +from OpenSSL._util import ( |
34 | 41 | ffi as _ffi, |
| 42 | +) |
| 43 | +from OpenSSL._util import ( |
35 | 44 | lib as _lib, |
| 45 | +) |
| 46 | +from OpenSSL._util import ( |
36 | 47 | make_assert as _make_assert, |
| 48 | +) |
| 49 | +from OpenSSL._util import ( |
37 | 50 | path_bytes as _path_bytes, |
| 51 | +) |
| 52 | +from OpenSSL._util import ( |
38 | 53 | text_to_bytes_and_warn as _text_to_bytes_and_warn, |
39 | 54 | ) |
40 | 55 |
|
41 | | - |
42 | 56 | __all__ = [ |
43 | 57 | "FILETYPE_PEM", |
44 | 58 | "FILETYPE_ASN1", |
@@ -111,7 +125,7 @@ def _untested_error(where: str) -> NoReturn: |
111 | 125 | encountered isn't one that's exercised by the test suite so future behavior |
112 | 126 | of pyOpenSSL is now somewhat less predictable. |
113 | 127 | """ |
114 | | - raise RuntimeError("Unknown %s failure" % (where,)) |
| 128 | + raise RuntimeError(f"Unknown {where} failure") |
115 | 129 |
|
116 | 130 |
|
117 | 131 | def _new_mem_buf(buffer: Optional[bytes] = None) -> Any: |
@@ -448,7 +462,7 @@ def __ne__(self, other: Any) -> bool: |
448 | 462 | circumstance. |
449 | 463 | """ |
450 | 464 | if isinstance(other, _EllipticCurve): |
451 | | - return super(_EllipticCurve, self).__ne__(other) |
| 465 | + return super().__ne__(other) |
452 | 466 | return NotImplemented |
453 | 467 |
|
454 | 468 | @classmethod |
@@ -518,7 +532,7 @@ def __init__(self, lib: Any, nid: int, name: str) -> None: |
518 | 532 | self.name = name |
519 | 533 |
|
520 | 534 | def __repr__(self) -> str: |
521 | | - return "<Curve %r>" % (self.name,) |
| 535 | + return f"<Curve {self.name!r}>" |
522 | 536 |
|
523 | 537 | def _to_EC_KEY(self) -> Any: |
524 | 538 | """ |
@@ -602,14 +616,15 @@ def __init__(self, name: "X509Name") -> None: |
602 | 616 |
|
603 | 617 | def __setattr__(self, name: str, value: Any) -> None: |
604 | 618 | if name.startswith("_"): |
605 | | - return super(X509Name, self).__setattr__(name, value) |
| 619 | + return super().__setattr__(name, value) |
606 | 620 |
|
607 | 621 | # Note: we really do not want str subclasses here, so we do not use |
608 | 622 | # isinstance. |
609 | 623 | if type(name) is not str: # noqa: E721 |
610 | 624 | raise TypeError( |
611 | | - "attribute name must be string, not '%.200s'" |
612 | | - % (type(value).__name__,) |
| 625 | + "attribute name must be string, not '{:.200}'".format( |
| 626 | + type(value).__name__ |
| 627 | + ) |
613 | 628 | ) |
614 | 629 |
|
615 | 630 | nid = _lib.OBJ_txt2nid(_byte_string(name)) |
@@ -701,7 +716,7 @@ def __repr__(self) -> str: |
701 | 716 | ) |
702 | 717 | _openssl_assert(format_result != _ffi.NULL) |
703 | 718 |
|
704 | | - return "<X509Name object '%s'>" % ( |
| 719 | + return "<X509Name object '{}'>".format( |
705 | 720 | _ffi.string(result_buffer).decode("utf-8"), |
706 | 721 | ) |
707 | 722 |
|
@@ -839,7 +854,7 @@ def _nid(self) -> Any: |
839 | 854 | _lib.X509_EXTENSION_get_object(self._extension) |
840 | 855 | ) |
841 | 856 |
|
842 | | - _prefixes = { |
| 857 | + _prefixes: typing.ClassVar[typing.Dict[int, str]] = { |
843 | 858 | _lib.GEN_EMAIL: "email", |
844 | 859 | _lib.GEN_DNS: "DNS", |
845 | 860 | _lib.GEN_URI: "URI", |
@@ -1814,7 +1829,7 @@ class X509StoreContextError(Exception): |
1814 | 1829 | def __init__( |
1815 | 1830 | self, message: str, errors: List[Any], certificate: X509 |
1816 | 1831 | ) -> None: |
1817 | | - super(X509StoreContextError, self).__init__(message) |
| 1832 | + super().__init__(message) |
1818 | 1833 | self.errors = errors |
1819 | 1834 | self.certificate = certificate |
1820 | 1835 |
|
@@ -2166,7 +2181,7 @@ class Revoked: |
2166 | 2181 | # which differs from crl_reasons of crypto/x509v3/v3_enum.c that matches |
2167 | 2182 | # OCSP_crl_reason_str. We use the latter, just like the command line |
2168 | 2183 | # program. |
2169 | | - _crl_reasons = [ |
| 2184 | + _crl_reasons: typing.ClassVar[typing.List[bytes]] = [ |
2170 | 2185 | b"unspecified", |
2171 | 2186 | b"keyCompromise", |
2172 | 2187 | b"CACompromise", |
@@ -2667,7 +2682,7 @@ def set_friendlyname(self, name: Optional[bytes]) -> None: |
2667 | 2682 | self._friendlyname = None |
2668 | 2683 | elif not isinstance(name, bytes): |
2669 | 2684 | raise TypeError( |
2670 | | - "name must be a byte string or None (not %r)" % (name,) |
| 2685 | + f"name must be a byte string or None (not {name!r})" |
2671 | 2686 | ) |
2672 | 2687 | self._friendlyname = name |
2673 | 2688 |
|
|
0 commit comments