"Fossies" - the Fresh Open Source Software Archive

Member "gpgme-1.15.1/lang/qt/src/qgpgmesignkeyjob.cpp" (8 Jan 2021, 4642 Bytes) of package /linux/privat/gpgme-1.15.1.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "qgpgmesignkeyjob.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.15.0_vs_1.15.1.

    1 /*
    2     qgpgmesignkeyjob.cpp
    3 
    4     This file is part of qgpgme, the Qt API binding for gpgme
    5     Copyright (c) 2008 Klarälvdalens Datakonsult AB
    6     Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
    7     Software engineering by Intevation GmbH
    8 
    9     QGpgME is free software; you can redistribute it and/or
   10     modify it under the terms of the GNU General Public License as
   11     published by the Free Software Foundation; either version 2 of the
   12     License, or (at your option) any later version.
   13 
   14     QGpgME 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 GNU
   17     General Public License for more details.
   18 
   19     You should have received a copy of the GNU General Public License along
   20     with this program; if not, write to the Free Software Foundation, Inc.,
   21     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
   22 
   23     In addition, as a special exception, the copyright holders give
   24     permission to link the code of this program with any edition of
   25     the Qt library by Trolltech AS, Norway (or with modified versions
   26     of Qt that use the same license as Qt), and distribute linked
   27     combinations including the two.  You must obey the GNU General
   28     Public License in all respects for all of the code used other than
   29     Qt.  If you modify this file, you may extend this exception to
   30     your version of the file, but you are not obligated to do so.  If
   31     you do not wish to do so, delete this exception statement from
   32     your version.
   33 */
   34 
   35 #ifdef HAVE_CONFIG_H
   36  #include "config.h"
   37 #endif
   38 
   39 #include "qgpgmesignkeyjob.h"
   40 
   41 #include "dataprovider.h"
   42 
   43 #include "context.h"
   44 #include "data.h"
   45 #include "gpgsignkeyeditinteractor.h"
   46 
   47 #include <cassert>
   48 #include <memory>
   49 
   50 using namespace QGpgME;
   51 using namespace GpgME;
   52 
   53 QGpgMESignKeyJob::QGpgMESignKeyJob(Context *context)
   54     : mixin_type(context),
   55       m_userIDsToSign(),
   56       m_signingKey(),
   57       m_checkLevel(0),
   58       m_exportable(false),
   59       m_nonRevocable(false),
   60       m_started(false),
   61       m_dupeOk(false)
   62 {
   63     lateInitialization();
   64 }
   65 
   66 QGpgMESignKeyJob::~QGpgMESignKeyJob() {}
   67 
   68 static QGpgMESignKeyJob::result_type sign_key(Context *ctx, const Key &key, const std::vector<unsigned int> &uids,
   69                                               unsigned int checkLevel, const Key &signer, unsigned int opts,
   70                                               bool dupeOk, const QString &remark)
   71 {
   72     QGpgME::QByteArrayDataProvider dp;
   73     Data data(&dp);
   74 
   75     GpgSignKeyEditInteractor *skei(new GpgSignKeyEditInteractor);
   76     skei->setUserIDsToSign(uids);
   77     skei->setCheckLevel(checkLevel);
   78     skei->setSigningOptions(opts);
   79     skei->setKey(key);
   80 
   81     if (dupeOk) {
   82         ctx->setFlag("extended-edit", "1");
   83         skei->setDupeOk(true);
   84     }
   85 
   86     if (!remark.isEmpty()) {
   87         ctx->addSignatureNotation("rem@gnupg.org", remark.toUtf8().constData());
   88     }
   89 
   90     if (!signer.isNull())
   91         if (const Error err = ctx->addSigningKey(signer)) {
   92             return std::make_tuple(err, QString(), Error());
   93         }
   94     const Error err = ctx->edit(key, std::unique_ptr<EditInteractor> (skei), data);
   95     Error ae;
   96     const QString log = _detail::audit_log_as_html(ctx, ae);
   97     return std::make_tuple(err, log, ae);
   98 }
   99 
  100 Error QGpgMESignKeyJob::start(const Key &key)
  101 {
  102     unsigned int opts = 0;
  103     if (m_nonRevocable) {
  104         opts |= GpgSignKeyEditInteractor::NonRevocable;
  105     }
  106     if (m_exportable) {
  107         opts |= GpgSignKeyEditInteractor::Exportable;
  108     }
  109     run(std::bind(&sign_key, std::placeholders::_1, key, m_userIDsToSign, m_checkLevel, m_signingKey, opts,
  110                   m_dupeOk, m_remark));
  111     m_started = true;
  112     return Error();
  113 }
  114 
  115 void QGpgMESignKeyJob::setUserIDsToSign(const std::vector<unsigned int> &idsToSign)
  116 {
  117     assert(!m_started);
  118     m_userIDsToSign = idsToSign;
  119 }
  120 
  121 void QGpgMESignKeyJob::setCheckLevel(unsigned int checkLevel)
  122 {
  123     assert(!m_started);
  124     m_checkLevel = checkLevel;
  125 }
  126 
  127 void QGpgMESignKeyJob::setExportable(bool exportable)
  128 {
  129     assert(!m_started);
  130     m_exportable = exportable;
  131 }
  132 
  133 void QGpgMESignKeyJob::setSigningKey(const Key &key)
  134 {
  135     assert(!m_started);
  136     m_signingKey = key;
  137 }
  138 
  139 void QGpgMESignKeyJob::setNonRevocable(bool nonRevocable)
  140 {
  141     assert(!m_started);
  142     m_nonRevocable = nonRevocable;
  143 }
  144 
  145 void QGpgMESignKeyJob::setRemark(const QString &remark)
  146 {
  147     assert(!m_started);
  148     m_remark = remark;
  149 }
  150 
  151 void QGpgMESignKeyJob::setDupeOk(bool value)
  152 {
  153     assert(!m_started);
  154     m_dupeOk = value;
  155 }
  156 #include "qgpgmesignkeyjob.moc"