Philipp Hörist pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/common/cert_store.py
    ... ... @@ -12,8 +12,11 @@
    12 12
     # You should have received a copy of the GNU General Public License
    
    13 13
     # along with Gajim.  If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15
    +from __future__ import annotations
    
    15 16
     
    
    16 17
     import logging
    
    18
    +from pathlib import Path
    
    19
    +from typing import Optional
    
    17 20
     
    
    18 21
     from gi.repository import GLib
    
    19 22
     from gi.repository import Gio
    
    ... ... @@ -30,18 +33,18 @@
    30 33
     class CertificateStore:
    
    31 34
         def __init__(self):
    
    32 35
             self._path = configpaths.get('CERT_STORE')
    
    33
    -        self._certs = []
    
    36
    +        self._certs: list[Gio.TlsCertificate] = []
    
    34 37
     
    
    35 38
             self._load_certificates()
    
    36 39
     
    
    37
    -    def _get_random_path(self):
    
    40
    +    def _get_random_path(self) -> Path:
    
    38 41
             filename = get_random_string()
    
    39 42
             path = self._path / filename
    
    40 43
             if path.exists():
    
    41 44
                 return self._get_random_path()
    
    42 45
             return path
    
    43 46
     
    
    44
    -    def _load_certificates(self):
    
    47
    +    def _load_certificates(self) -> None:
    
    45 48
             for path in self._path.iterdir():
    
    46 49
                 if path.is_dir():
    
    47 50
                     continue
    
    ... ... @@ -59,7 +62,7 @@ def _load_certificates(self):
    59 62
         def get_certificates(self):
    
    60 63
             return list(self._certs)
    
    61 64
     
    
    62
    -    def add_certificate(self, certificate):
    
    65
    +    def add_certificate(self, certificate: Gio.TlsCertificate) -> None:
    
    63 66
             log.info('Add certificate to trust store')
    
    64 67
             self._certs.append(certificate)
    
    65 68
             pem = certificate.props.certificate_pem
    
    ... ... @@ -69,7 +72,10 @@ def add_certificate(self, certificate):
    69 72
                              self._on_certificate_write_finished,
    
    70 73
                              path)
    
    71 74
     
    
    72
    -    def verify(self, certificate, tls_errors):
    
    75
    +    def verify(self,
    
    76
    +               certificate: Gio.TlsCertificate,
    
    77
    +               tls_errors: set[Gio.TlsCertificateFlags]):
    
    78
    +
    
    73 79
             if Gio.TlsCertificateFlags.UNKNOWN_CA in tls_errors:
    
    74 80
                 for trusted_certificate in self._certs:
    
    75 81
                     if trusted_certificate.is_same(certificate):
    
    ... ... @@ -81,9 +87,11 @@ def verify(self, certificate, tls_errors):
    81 87
             return False
    
    82 88
     
    
    83 89
         @staticmethod
    
    84
    -    def _on_certificate_write_finished(data, error, path):
    
    85
    -        if data is None:
    
    86
    -            log.error('Can\'t store certificate: %s', error)
    
    90
    +    def _on_certificate_write_finished(_successful: bool,
    
    91
    +                                       error: Optional[GLib.Error],
    
    92
    +                                       path: Path):
    
    93
    +        if error is not None:
    
    94
    +            log.error('Can\'t store certificate: %s', error.message)
    
    87 95
                 return
    
    88 96
     
    
    89 97
             log.info('Certificate stored: %s', path)

  • gajim/common/helpers.py
    ... ... @@ -28,6 +28,7 @@
    28 28
     from __future__ import annotations
    
    29 29
     
    
    30 30
     from typing import Any
    
    31
    +from typing import Callable
    
    31 32
     from typing import Dict
    
    32 33
     from typing import Optional
    
    33 34
     from typing import List
    
    ... ... @@ -1256,7 +1257,12 @@ def notify(self, signal_name: str, *args: Any, **kwargs: Any):
    1256 1257
                 func(self, signal_name, *args, **kwargs)
    
    1257 1258
     
    
    1258 1259
     
    
    1259
    -def write_file_async(path, data, callback, user_data=None):
    
    1260
    +def write_file_async(
    
    1261
    +        path: Path,
    
    1262
    +        data: bytes,
    
    1263
    +        callback: Callable[[bool, Optional[GLib.Error], Any], Any],
    
    1264
    +        user_data: Optional[Any] = None):
    
    1265
    +
    
    1260 1266
         file = Gio.File.new_for_path(str(path))
    
    1261 1267
         file.create_async(Gio.FileCreateFlags.PRIVATE,
    
    1262 1268
                           GLib.PRIORITY_DEFAULT,
    

  • pyrightconfig.json
    ... ... @@ -11,6 +11,7 @@
    11 11
         ],
    
    12 12
         "typeCheckingMode": "strict",
    
    13 13
         "include": [
    
    14
    -        "gajim/gtk/chat_filter.py"
    
    14
    +        "gajim/gtk/chat_filter.py",
    
    15
    +        "gajim/common/cert_store.py"
    
    15 16
         ],
    
    16 17
     }