• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
  • transactions
kgpggeneraterevoke.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010,2012,2013 Rolf Eike Beer <kde@opensource.sf-tec.de>
3  */
4 
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #include "kgpggeneraterevoke.h"
15 
16 #include <KDebug>
17 #include <KLocale>
18 #include <QtCore/QFile>
19 
20 KGpgGenerateRevoke::KGpgGenerateRevoke(QObject *parent, const QString &keyID, const KUrl &revokeUrl, const int reason, const QString &description)
21  : KGpgTransaction(parent),
22  m_keyid(keyID),
23  m_revUrl(revokeUrl),
24  m_reason(reason),
25  m_description(description)
26 {
27  addArgument(QLatin1String( "--status-fd=1" ));
28  addArgument(QLatin1String( "--command-fd=0" ));
29  addArgument(QLatin1String( "--no-verbose" ));
30 
31  if (!revokeUrl.isEmpty()) {
32  addArgument(QLatin1String( "-o" ));
33  addArgument(revokeUrl.toLocalFile());
34  }
35  addArgument(QLatin1String( "--gen-revoke" ));
36  addArgument(keyID);
37 }
38 
39 KGpgGenerateRevoke::~KGpgGenerateRevoke()
40 {
41 }
42 
43 bool
44 KGpgGenerateRevoke::preStart()
45 {
46  setSuccess(TS_MSG_SEQUENCE);
47 
48  setDescription(i18n("Generating Revocation Certificate for key %1", m_keyid));
49 
50  return true;
51 }
52 
53 bool
54 KGpgGenerateRevoke::nextLine(const QString &line)
55 {
56  if (!line.startsWith(QLatin1String("[GNUPG:] "))) {
57  m_output.append(line + QLatin1Char( '\n' ));
58  return false;
59  }
60 
61  if (line.contains(QLatin1String( "NEED_PASSPHRASE" ))) {
62  setSuccess(TS_USER_ABORTED);
63  } else if (line.contains(QLatin1String( "ask_revocation_reason.code" ))) {
64  write(QByteArray::number(m_reason));
65  } else if (line.contains(QLatin1String( "ask_revocation_reason.text" ))) {
66  write(m_description.toUtf8());
67  // GnuPG stops asking if we pass an empty line
68  m_description.clear();
69  } else if (line.contains(QLatin1String( "GET_" ))) {
70  setSuccess(TS_MSG_SEQUENCE);
71  kDebug(2100) << line;
72  return true;
73  }
74 
75  return false;
76 }
77 
78 KGpgTransaction::ts_boolanswer
79 KGpgGenerateRevoke::boolQuestion(const QString& line)
80 {
81  if (line == QLatin1String("gen_revoke.okay")) {
82  return BA_YES;
83  } else if (line == QLatin1String("ask_revocation_reason.okay")) {
84  return BA_YES;
85  } else {
86  return KGpgTransaction::boolQuestion(line);
87  }
88 }
89 
90 void
91 KGpgGenerateRevoke::finish()
92 {
93  if (getSuccess() == TS_OK) {
94  if (!m_revUrl.isEmpty()) {
95  QFile of(m_revUrl.toLocalFile());
96  if (of.open(QIODevice::ReadOnly)) {
97  m_output = QLatin1String( of.readAll() );
98  of.close();
99  }
100  }
101  emit revokeCertificate(m_output);
102  }
103 }
104 
105 bool
106 KGpgGenerateRevoke::passphraseReceived()
107 {
108  setSuccess(TS_OK);
109 
110  return false;
111 }
112 
113 KGpgTransaction::ts_boolanswer
114 KGpgGenerateRevoke::confirmOverwrite(KUrl &currentFile)
115 {
116  currentFile = m_revUrl;
117  return BA_UNKNOWN;
118 }
119 
120 const QString &
121 KGpgGenerateRevoke::getOutput() const
122 {
123  return m_output;
124 }
125 
126 #include "kgpggeneraterevoke.moc"
KGpgTransaction::getSuccess
int getSuccess() const
get the success value that will be returned with the done signal
Definition: kgpgtransaction.cpp:442
QString::append
QString & append(QChar ch)
KGpgTransaction::addArgument
int addArgument(const QString &arg)
add a command line argument to gpg process
Definition: kgpgtransaction.cpp:562
KGpgTransaction::BA_YES
answer "YES"
Definition: kgpgtransaction.h:75
KGpgTransaction::TS_OK
everything went fine
Definition: kgpgtransaction.h:60
KGpgTransaction::write
void write(const QByteArray &a, const bool lf=true)
write data to standard input of gpg process
Definition: kgpgtransaction.cpp:413
KGpgGenerateRevoke::~KGpgGenerateRevoke
virtual ~KGpgGenerateRevoke()
Definition: kgpggeneraterevoke.cpp:39
QFile
KGpgGenerateRevoke::confirmOverwrite
virtual ts_boolanswer confirmOverwrite(KUrl &currentFile)
called when GnuPG asks for confirmation for overwriting a file
Definition: kgpggeneraterevoke.cpp:114
QString::clear
void clear()
QObject
QByteArray::number
QByteArray number(int n, int base)
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KGpgTransaction::boolQuestion
virtual ts_boolanswer boolQuestion(const QString &line)
Called for every boolean question GnuPG answers.
Definition: kgpgtransaction.cpp:457
KGpgGenerateRevoke::nextLine
virtual bool nextLine(const QString &line)
Called for every line the gpg process writes.
Definition: kgpggeneraterevoke.cpp:54
QString
KGpgTransaction::TS_MSG_SEQUENCE
unexpected sequence of GnuPG messages
Definition: kgpgtransaction.h:62
KGpgTransaction::BA_UNKNOWN
the question is not supported (this is an error)
Definition: kgpgtransaction.h:74
KGpgTransaction::ts_boolanswer
ts_boolanswer
result codes for GnuPG boolean questions
Definition: kgpgtransaction.h:73
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QLatin1Char
KGpgTransaction::TS_USER_ABORTED
the user aborted the transaction
Definition: kgpgtransaction.h:63
KGpgGenerateRevoke::finish
virtual void finish()
Called when the gpg process finishes.
Definition: kgpggeneraterevoke.cpp:91
QLatin1String
KGpgTransaction::setSuccess
void setSuccess(const int v)
set the success value that will be returned with the done signal
Definition: kgpgtransaction.cpp:448
KGpgGenerateRevoke::getOutput
const QString & getOutput() const
returns the revokation certificate
Definition: kgpggeneraterevoke.cpp:121
KGpgGenerateRevoke::passphraseReceived
virtual bool passphraseReceived()
called when GnuPG accepted the passphrase
Definition: kgpggeneraterevoke.cpp:106
description
static const char description[]
Definition: main.cpp:23
kgpggeneraterevoke.h
KGpgTransaction
Process one GnuPG operation.
Definition: kgpgtransaction.h:44
KGpgGenerateRevoke::boolQuestion
virtual ts_boolanswer boolQuestion(const QString &line)
Called for every boolean question GnuPG answers.
Definition: kgpggeneraterevoke.cpp:79
KGpgTransaction::setDescription
void setDescription(const QString &description)
set the description returned in getDescription()
Definition: kgpgtransaction.cpp:489
KGpgGenerateRevoke::revokeCertificate
void revokeCertificate(const QString &cert)
KGpgGenerateRevoke::preStart
virtual bool preStart()
Called before the gpg process is started.
Definition: kgpggeneraterevoke.cpp:44
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal