kgpggeneratekey.h 3.06 KB
Newer Older
1
/*
2
 * Copyright (C) 2008,2009,2012,2013,2016 Rolf Eike Beer <kde@opensource.sf-tec.de>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 */

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KGPGGENERATEKEY_H
#define KGPGGENERATEKEY_H

#include "kgpgtransaction.h"
Rolf Eike Beer's avatar
Rolf Eike Beer committed
18
19
20
21

#include "core/kgpgkey.h"

#include <QObject>
Rolf Eike Beer's avatar
Rolf Eike Beer committed
22
#include <QString>
23
#include <QStringList>
24
25

/**
26
 * @brief generate a new key pair
27
28
29
30
 */
class KGpgGenerateKey: public KGpgTransaction {
	Q_OBJECT

31
	Q_DISABLE_COPY(KGpgGenerateKey)
Rolf Eike Beer's avatar
Rolf Eike Beer committed
32
	KGpgGenerateKey() = delete;
33
public:
34
35
36
	enum ts_generatekey {
		TS_INVALID_NAME = TS_COMMON_END + 1	///< the owners name is not accepted by GnuPG
	};
37

38
	/**
39
	 * @brief KGpgGenerateKey's constructor
Rolf Eike Beer's avatar
Rolf Eike Beer committed
40
	 * @param parent parent object
41
42
43
	 * @param name the name of the key, it is also the user's name.
	 * @param email email MUST be a valid email address or an empty string.
	 * @param comment is a comment, it can be an empty string
44
	 * @param algorithm this is the type of the key, RSA or DSA & ELGAMAL (\see Kgpg::KeyAlgo ).
45
46
	 * @param size this is the length of the key (1024, 2048, ...)
	 * @param expire defines the key expiry time together with \em expireunit, 0 for unlimited key lifetime
47
	 * @param expireunit is the unit of the number given as \em expire. Valid units are 'd', 'w', 'm' and 'y'. The unit is ignored if expire is 0.
48
	 * @param capabilities capabilities for the primary key
49
50
	 */
	KGpgGenerateKey(QObject *parent, const QString &name, const QString &email, const QString &comment,
51
			 const KgpgCore::KgpgKeyAlgo &algorithm, const uint size, const unsigned int expire = 0,
Laurent Montel's avatar
Laurent Montel committed
52
                        const char expireunit = 'd', const KgpgCore::KgpgSubKeyType capabilities = {});
Laurent Montel's avatar
Laurent Montel committed
53
    ~KGpgGenerateKey() override;
54
55
56

	QString getName() const;
	QString getEmail() const;
57

58
	/**
59
	 * @brief return the fingerprint of the generated key
60
61
62
	 */
	QString getFingerprint() const;

63
64
65
66
67
68
69
70
	/**
	 * @brief get error output of GnuPG
	 * @return the messages GnuPG printed to standard error
	 *
	 * This will only return data after the done() signal has been emitted.
	 */
	QString gpgErrorMessage() const;

71
protected:
72
73
74
75
76
	bool preStart() override;
	void postStart() override;
	bool nextLine(const QString &line) override;
	void finish() override;
	void newPassphraseEntered() override;
77
78

private:
79
80
81
82
83
84
85
86
	const QString m_name;
	const QString m_email;
	const QString m_comment;
	const KgpgCore::KgpgKeyAlgo m_algorithm;
	const KgpgCore::KgpgSubKeyType m_capabilities;
	const unsigned int m_size;
	const unsigned int m_expire;
	const unsigned int m_expireunit;
87
	QString m_fingerprint;
88
	QStringList m_errorOutput;
89
90
91
};

#endif // KGPGGENERATEKEY_H