33 #include <config-kleopatra.h>
43 #include <kleo/exception.h>
45 #include <KLocalizedString>
50 using namespace Kleo::Crypto;
51 using namespace boost;
53 class SignCommand::Private :
public QObject {
56 friend class ::Kleo::SignCommand;
60 :
q( qq ), controller()
66 void checkForErrors()
const;
69 void slotSignersResolved();
70 void slotMicAlgDetermined(
const QString & );
72 void slotError(
int,
const QString & );
86 void SignCommand::Private::checkForErrors()
const {
89 throw Exception( makeError( GPG_ERR_CONFLICT ),
90 i18n(
"SIGN is an email mode command, connection seems to be in filemanager mode" ) );
92 if ( !
q->recipients().empty() && !
q->informativeRecipients() )
93 throw Exception( makeError( GPG_ERR_CONFLICT ),
94 i18n(
"RECIPIENT may not be given prior to SIGN, except with --info" ) );
96 if (
q->inputs().empty() )
97 throw Exception( makeError( GPG_ERR_ASS_NO_INPUT ),
98 i18n(
"At least one INPUT must be present" ) );
100 if (
q->outputs().size() !=
q->inputs().size() )
101 throw Exception( makeError( GPG_ERR_ASS_NO_INPUT ),
102 i18n(
"INPUT/OUTPUT count mismatch" ) );
104 if ( !
q->messages().empty() )
105 throw Exception( makeError( GPG_ERR_INV_VALUE ),
106 i18n(
"MESSAGE command is not allowed before SIGN" ) );
110 if ( m && m->isSigning() ) {
112 if ( m->protocol() !=
q->checkProtocol( EMail ) )
113 throw Exception( makeError( GPG_ERR_CONFLICT ),
114 i18n(
"Protocol given conflicts with protocol determined by PREP_ENCRYPT in this session" ) );
125 if (
q->senders().empty() ||
q->informativeSenders() )
126 throw Exception( makeError( GPG_ERR_MISSING_VALUE ),
127 i18n(
"No senders given, or only with --info" ) );
134 QObject::connect( controller, SIGNAL(certificatesResolved()), d, SLOT(slotSignersResolved()) );
140 int SignCommand::doStart() {
146 if ( seec && seec->isSigning() ) {
148 d->controller = seec;
150 if ( !seec->isEncrypting() )
151 removeMemento( NewSignEncryptEMailController::mementoName() );
152 seec->setExecutionContext( shared_from_this() );
153 if ( seec->areCertificatesResolved() )
161 const QString session = sessionTitle();
163 d->controller->setSubject( session );
165 d->controller->setSigning(
true );
166 d->controller->setEncrypting(
false );
169 d->controller->startResolveCertificates( recipients(), senders() );
176 void SignCommand::Private::slotSignersResolved() {
181 const QString sessionTitle =
q->sessionTitle();
184 i->setLabel( sessionTitle );
186 cont->setDetachedSignature(
q->hasOption(
"detached" ) );
187 cont->startSigning(
q->inputs(),
q->outputs() );
191 }
catch (
const Exception & e ) {
192 q->done( e.error(), e.message() );
193 }
catch (
const std::exception & e ) {
194 q->done( makeError( GPG_ERR_UNEXPECTED ),
195 i18n(
"Caught unexpected exception in SignCommand::Private::slotRecipientsResolved: %1",
198 q->done( makeError( GPG_ERR_UNEXPECTED ),
199 i18n(
"Caught unknown exception in SignCommand::Private::slotRecipientsResolved") );
204 void SignCommand::Private::slotMicAlgDetermined(
const QString & micalg ) {
210 q->sendStatus(
"MICALG", micalg );
213 }
catch (
const Exception & e ) {
214 q->done( e.error(), e.message() );
215 }
catch (
const std::exception & e ) {
216 q->done( makeError( GPG_ERR_UNEXPECTED ),
217 i18n(
"Caught unexpected exception in SignCommand::Private::slotMicAlgDetermined: %1",
220 q->done( makeError( GPG_ERR_UNEXPECTED ),
221 i18n(
"Caught unknown exception in SignCommand::Private::slotMicAlgDetermined") );
226 void SignCommand::Private::slotDone() {
230 void SignCommand::Private::slotError(
int err,
const QString & details ) {
231 q->done( err, details );
234 void SignCommand::doCanceled() {
236 d->controller->cancel();
239 #include "signcommand.moc"
QString fromLocal8Bit(const char *str, int size)
static void connectController(const QObject *controller, const QObject *d)
#define kleo_assert(cond)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)