summaryrefslogtreecommitdiff
path: root/src/mailman_pgp/pgp/keygen.py
blob: b15dbf631bd47c7da75ca198c619dbbbab0a493c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
""""""

import threading

from mailman_pgp.config import config


class KeyGenerator(threading.Thread):
    def __init__(self, name, email, comment=None):
        super().__init__(daemon=True)
        self._name = name
        self._comment = comment
        self._email = email
        self.key_fingerprint = None

    def run(self):
        default_config = config.gpg.keypair_config
        key_config = dict(default_config)
        key_config.update(dict(name_real=self._name,
                               name_email=self._email))
        if self._comment is not None:
            key_config['name_comment'] = self._comment
        key_input = config.gpg.gen_key_input(**key_config)
        key = config.gpg.gen_key(key_input)
        self.key_fingerprint = key.fingerprint

    @property
    def has_key(self):
        return self.key_fingerprint is not None