aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpg/function/GpgKeyImportExportor.h
blob: 455e59f8be1d936b9789cc9d1612c7ff44226bc6 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
 * This file is part of GPGFrontend.
 *
 * GPGFrontend 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 3 of the License, or
 * (at your option) any later version.
 *
 * Foobar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <https://www.gnu.org/licenses/>.
 *
 * The initial version of the source code is inherited from gpg4usb-team.
 * Their source code version also complies with GNU General Public License.
 *
 * The source code version of this software was modified and released
 * by Saturneric<[email protected]> starting on May 12, 2021.
 *
 */

#ifndef _GPGKEYIMPORTEXPORTOR_H
#define _GPGKEYIMPORTEXPORTOR_H

#include "gpg/GpgConstants.h"
#include "gpg/GpgContext.h"
#include "gpg/GpgFunctionObject.h"
#include "gpg/GpgModel.h"

namespace GpgFrontend {

class GpgImportedKey {
public:
  std::string fpr;
  int import_status;
};

typedef std::list<GpgImportedKey> GpgImportedKeyList;

class GpgImportInformation {
public:
  GpgImportInformation() = default;

  explicit GpgImportInformation(gpgme_import_result_t result) {
    if (result->unchanged)
      unchanged = result->unchanged;
    if (result->considered)
      considered = result->considered;
    if (result->no_user_id)
      no_user_id = result->no_user_id;
    if (result->imported)
      imported = result->imported;
    if (result->imported_rsa)
      imported_rsa = result->imported_rsa;
    if (result->unchanged)
      unchanged = result->unchanged;
    if (result->new_user_ids)
      new_user_ids = result->new_user_ids;
    if (result->new_sub_keys)
      new_sub_keys = result->new_sub_keys;
    if (result->new_signatures)
      new_signatures = result->new_signatures;
    if (result->new_revocations)
      new_revocations = result->new_revocations;
    if (result->secret_read)
      secret_read = result->secret_read;
    if (result->secret_imported)
      secret_imported = result->secret_imported;
    if (result->secret_unchanged)
      secret_unchanged = result->secret_unchanged;
    if (result->not_imported)
      not_imported = result->not_imported;
  }

  int considered = 0;
  int no_user_id = 0;
  int imported = 0;
  int imported_rsa = 0;
  int unchanged = 0;
  int new_user_ids = 0;
  int new_sub_keys = 0;
  int new_signatures = 0;
  int new_revocations = 0;
  int secret_read = 0;
  int secret_imported = 0;
  int secret_unchanged = 0;
  int not_imported = 0;
  GpgImportedKeyList importedKeys;
};

class GpgKeyImportExportor
    : public SingletonFunctionObject<GpgKeyImportExportor> {
public:
  GpgImportInformation ImportKey(StdBypeArrayPtr inBuffer);

  bool ExportKeys(KeyIdArgsListPtr &uid_list, BypeArrayPtr &out_buffer) const;

  bool ExportKeys(KeyArgsList &keys, BypeArrayPtr &outBuffer) const;

  bool ExportSecretKey(const GpgKey &key, BypeArrayPtr outBuffer) const;

private:
  GpgContext &ctx = GpgContext::GetInstance();
};

} // namespace GpgFrontend

#endif // _GPGKEYIMPORTEXPORTOR_H