Line data Source code
1 : /*
2 : gpgsetownertrusteditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key
3 : Copyright (C) 2007 Klarälvdalens Datakonsult AB
4 : 2016 Bundesamt für Sicherheit in der Informationstechnik
5 : Software engineering by Intevation GmbH
6 :
7 : This file is part of GPGME++.
8 :
9 : GPGME++ is free software; you can redistribute it and/or
10 : modify it under the terms of the GNU Library General Public
11 : License as published by the Free Software Foundation; either
12 : version 2 of the License, or (at your option) any later version.
13 :
14 : GPGME++ is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU Library General Public License for more details.
18 :
19 : You should have received a copy of the GNU Library General Public License
20 : along with GPGME++; see the file COPYING.LIB. If not, write to the
21 : Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 : Boston, MA 02110-1301, USA.
23 : */
24 :
25 : #ifdef HAVE_CONFIG_H
26 : #include "config.h"
27 : #endif
28 :
29 : #include "gpgsetownertrusteditinteractor.h"
30 : #include "error.h"
31 :
32 : #include <gpgme.h>
33 :
34 : #include <cstring>
35 :
36 : using std::strcmp;
37 :
38 : // avoid conflict (msvc)
39 : #ifdef ERROR
40 : # undef ERROR
41 : #endif
42 :
43 : using namespace GpgME;
44 :
45 2 : GpgSetOwnerTrustEditInteractor::GpgSetOwnerTrustEditInteractor(Key::OwnerTrust ot)
46 : : EditInteractor(),
47 2 : m_ownertrust(ot)
48 : {
49 :
50 2 : }
51 :
52 4 : GpgSetOwnerTrustEditInteractor::~GpgSetOwnerTrustEditInteractor() {}
53 :
54 : // work around --enable-final
55 : namespace GpgSetOwnerTrustEditInteractor_Private
56 : {
57 : enum {
58 : START = EditInteractor::StartState,
59 : COMMAND,
60 : VALUE,
61 : REALLY_ULTIMATE,
62 : QUIT,
63 : SAVE,
64 :
65 : ERROR = EditInteractor::ErrorState
66 : };
67 : }
68 :
69 7 : const char *GpgSetOwnerTrustEditInteractor::action(Error &err) const
70 : {
71 : static const char truststrings[][2] = { "1", "1", "2", "3", "4", "5" };
72 :
73 : using namespace GpgSetOwnerTrustEditInteractor_Private;
74 :
75 7 : switch (state()) {
76 : case COMMAND:
77 2 : return "trust";
78 : case VALUE:
79 2 : return truststrings[m_ownertrust];
80 : case REALLY_ULTIMATE:
81 1 : return "Y";
82 : case QUIT:
83 2 : return "quit";
84 : case SAVE:
85 0 : return "Y";
86 : case START:
87 : case ERROR:
88 0 : return 0;
89 : default:
90 0 : err = Error::fromCode(GPG_ERR_GENERAL);
91 0 : return 0;
92 : }
93 : }
94 :
95 18 : unsigned int GpgSetOwnerTrustEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
96 : {
97 :
98 18 : static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
99 : //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME );
100 :
101 18 : if (needsNoResponse(status)) {
102 11 : return state();
103 : }
104 :
105 : using namespace GpgSetOwnerTrustEditInteractor_Private;
106 :
107 7 : switch (state()) {
108 : case START:
109 4 : if (status == GPGME_STATUS_GET_LINE &&
110 2 : strcmp(args, "keyedit.prompt") == 0) {
111 2 : return COMMAND;
112 : }
113 0 : err = GENERAL_ERROR;
114 0 : return ERROR;
115 : case COMMAND:
116 4 : if (status == GPGME_STATUS_GET_LINE &&
117 2 : strcmp(args, "edit_ownertrust.value") == 0) {
118 2 : return VALUE;
119 : }
120 0 : err = GENERAL_ERROR;
121 0 : return ERROR;
122 : case VALUE:
123 3 : if (status == GPGME_STATUS_GET_LINE &&
124 1 : strcmp(args, "keyedit.prompt") == 0) {
125 1 : return QUIT;
126 2 : } else if (status == GPGME_STATUS_GET_BOOL &&
127 1 : strcmp(args, "edit_ownertrust.set_ultimate.okay") == 0) {
128 1 : return REALLY_ULTIMATE;
129 : }
130 0 : err = GENERAL_ERROR;
131 0 : return ERROR;
132 : case REALLY_ULTIMATE:
133 2 : if (status == GPGME_STATUS_GET_LINE &&
134 1 : strcmp(args, "keyedit.prompt") == 0) {
135 1 : return QUIT;
136 : }
137 0 : err = GENERAL_ERROR;
138 0 : return ERROR;
139 : case QUIT:
140 0 : if (status == GPGME_STATUS_GET_BOOL &&
141 0 : strcmp(args, "keyedit.save.okay") == 0) {
142 0 : return SAVE;
143 : }
144 0 : err = GENERAL_ERROR;
145 0 : return ERROR;
146 : case ERROR:
147 0 : if (status == GPGME_STATUS_GET_LINE &&
148 0 : strcmp(args, "keyedit.prompt") == 0) {
149 0 : return QUIT;
150 : }
151 0 : err = lastError();
152 0 : return ERROR;
153 : default:
154 0 : err = GENERAL_ERROR;
155 0 : return ERROR;
156 : };
157 : }
|