QGpgME  18.3.0.0000000
Qt API for GpgME
dataprovider.h
1 /* dataprovider.h
2  Copyright (C) 2004 Klarälvdalens Datakonsult AB
3  Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
4  Software engineering by Intevation GmbH
5 
6  This file is part of QGPGME.
7 
8  QGPGME is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Library General Public License as published
10  by the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  QGPGME is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with QGPGME; see the file COPYING.LIB. If not, write to the
20  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA. */
22 
23 // -*- c++ -*-
24 #ifndef __QGPGME_DATAPROVIDER_H__
25 #define __QGPGME_DATAPROVIDER_H__
26 
27 #include "qgpgme_export.h"
28 
29 #ifdef BUILDING_QGPGME
30 #include <interfaces/dataprovider.h>
31 #else
32 #include <gpgme++/interfaces/dataprovider.h>
33 #endif
34 
35 #include <memory>
36 
37 #include <QtCore/QByteArray>
38 
39 
40 class QIODevice;
41 
42 namespace QGpgME
43 {
44 
45 class QGPGME_EXPORT QByteArrayDataProvider : public GpgME::DataProvider
46 {
47 public:
49  explicit QByteArrayDataProvider(const QByteArray &initialData);
51 
52  const QByteArray &data() const
53  {
54  return mArray;
55  }
56 
57 private:
58  // these shall only be accessed through the dataprovider
59  // interface, where they're public:
60  bool isSupported(Operation) const override
61  {
62  return true;
63  }
64  ssize_t read(void *buffer, size_t bufSize) override;
65  ssize_t write(const void *buffer, size_t bufSize) override;
66  off_t seek(off_t offset, int whence) override;
67  void release() override;
68 
69 private:
70  QByteArray mArray;
71  off_t mOff;
72 };
73 
74 class QGPGME_EXPORT QIODeviceDataProvider : public GpgME::DataProvider
75 {
76 public:
77  explicit QIODeviceDataProvider(const std::shared_ptr<QIODevice> &initialData);
79 
80  const std::shared_ptr<QIODevice> &ioDevice() const
81  {
82  return mIO;
83  }
84 
85 private:
86  // these shall only be accessed through the dataprovider
87  // interface, where they're public:
88  bool isSupported(Operation) const override;
89  ssize_t read(void *buffer, size_t bufSize) override;
90  ssize_t write(const void *buffer, size_t bufSize) override;
91  off_t seek(off_t offset, int whence) override;
92  void release() override;
93 
94 private:
95  const std::shared_ptr<QIODevice> mIO;
96  bool mErrorOccurred : 1;
97  bool mHaveQProcess : 1;
98 };
99 
100 } // namespace QGpgME
101 
102 #endif
Definition: dataprovider.h:46
Definition: dataprovider.h:75