File indexing completed on 2024-05-05 04:45:05

0001 /*
0002  * Copyright (C) 2003-2008  Justin Karneges <justin@affinix.com>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Lesser General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Lesser General Public
0015  * License along with this library; if not, write to the Free Software
0016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
0017  */
0018 
0019 #pragma once
0020 
0021 #include "gpgop.h"
0022 #include "qcaprovider.h"
0023 
0024 namespace gpgQCAPlugin {
0025 
0026 class MyOpenPGPContext;
0027 
0028 class MyMessageContext : public QCA::MessageContext
0029 {
0030     Q_OBJECT
0031 public:
0032     MyOpenPGPContext *sms;
0033 
0034     QString                        signerId;
0035     QStringList                    recipIds;
0036     QCA::MessageContext::Operation op;
0037     QCA::SecureMessage::SignMode   signMode;
0038     QCA::SecureMessage::Format     format;
0039     QByteArray                     in, out, sig;
0040     int                            wrote;
0041     bool                           ok, wasSigned;
0042     GpgOp::Error                   op_err;
0043     QCA::SecureMessageSignature    signer;
0044     GpgOp                          gpg;
0045     bool                           _finished;
0046     QString                        dtext;
0047 
0048     QCA::PasswordAsker asker;
0049     QCA::TokenAsker    tokenAsker;
0050 
0051     MyMessageContext(MyOpenPGPContext *_sms, QCA::Provider *p);
0052 
0053     // reimplemented Provider::Context
0054     QCA::Provider::Context *clone() const override;
0055 
0056     // reimplemented MessageContext
0057     bool                     canSignMultiple() const override;
0058     QCA::SecureMessage::Type type() const override;
0059     void                     reset() override;
0060     void                     setupEncrypt(const QCA::SecureMessageKeyList &keys) override;
0061     void       setupSign(const QCA::SecureMessageKeyList &keys, QCA::SecureMessage::SignMode m, bool, bool) override;
0062     void       setupVerify(const QByteArray &detachedSig) override;
0063     void       start(QCA::SecureMessage::Format f, QCA::MessageContext::Operation op) override;
0064     void       update(const QByteArray &in) override;
0065     QByteArray read() override;
0066     int        written() override;
0067     void       end() override;
0068     bool       finished() const override;
0069     bool       waitForFinished(int msecs) override;
0070     bool       success() const override;
0071     QCA::SecureMessage::Error       errorCode() const override;
0072     QByteArray                      signature() const override;
0073     QString                         hashName() const override;
0074     QCA::SecureMessageSignatureList signers() const override;
0075     QString                         diagnosticText() const override;
0076 
0077     void seterror();
0078     void complete();
0079 
0080 private Q_SLOTS:
0081     void gpg_readyRead();
0082     void gpg_bytesWritten(int bytes);
0083     void gpg_finished();
0084     void gpg_needPassphrase(const QString &in_keyId);
0085     void gpg_needCard();
0086     void gpg_readyReadDiagnosticText();
0087     void asker_responseReady();
0088     void tokenAsker_responseReady();
0089 };
0090 
0091 } // end namespace gpgQCAPlugin