LCOV - code coverage report
Current view: top level - lang/cpp/src - data.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 12 50.0 %
Date: 2018-11-15 08:49:49 Functions: 4 6 66.7 %

          Line data    Source code
       1             : /*
       2             :   data.h - wraps a gpgme data object
       3             :   Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB
       4             : 
       5             :   This file is part of GPGME++.
       6             : 
       7             :   GPGME++ is free software; you can redistribute it and/or
       8             :   modify it under the terms of the GNU Library General Public
       9             :   License as published by the Free Software Foundation; either
      10             :   version 2 of the License, or (at your option) any later version.
      11             : 
      12             :   GPGME++ is distributed in the hope that it will be useful,
      13             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :   GNU Library General Public License for more details.
      16             : 
      17             :   You should have received a copy of the GNU Library General Public License
      18             :   along with GPGME++; see the file COPYING.LIB.  If not, write to the
      19             :   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      20             :   Boston, MA 02110-1301, USA.
      21             : */
      22             : 
      23             : #ifndef __GPGMEPP_DATA_H__
      24             : #define __GPGMEPP_DATA_H__
      25             : 
      26             : #include "global.h"
      27             : #include "key.h"
      28             : 
      29             : #include <sys/types.h> // for size_t, off_t
      30             : #include <cstdio> // FILE
      31             : #include <algorithm>
      32             : #include <memory>
      33             : 
      34             : namespace GpgME
      35             : {
      36             : 
      37             : class DataProvider;
      38             : class Error;
      39             : 
      40         149 : class GPGMEPP_EXPORT Data
      41             : {
      42             :     struct Null {
      43           8 :                 Null() {}
      44             :         };
      45             : public:
      46             :     /* implicit */ Data(const Null &);
      47             :     Data();
      48             :     explicit Data(gpgme_data_t data);
      49             : 
      50             :     // Memory-Based Data Buffers:
      51             :     Data(const char *buffer, size_t size, bool copy = true);
      52             :     explicit Data(const char *filename);
      53             :     Data(const char *filename, off_t offset, size_t length);
      54             :     Data(std::FILE *fp, off_t offset, size_t length);
      55             :     // File-Based Data Buffers:
      56             :     explicit Data(std::FILE *fp);
      57             :     explicit Data(int fd);
      58             :     // Callback-Based Data Buffers:
      59             :     explicit Data(DataProvider *provider);
      60             : 
      61             :     static const Null null;
      62             : 
      63           0 :     const Data &operator=(Data other)
      64             :     {
      65           0 :         swap(other);
      66           0 :         return *this;
      67             :     }
      68             : 
      69           0 :     void swap(Data &other)
      70             :     {
      71             :         using std::swap;
      72           0 :         swap(this->d, other.d);
      73           0 :     }
      74             : 
      75             :     bool isNull() const;
      76             : 
      77             :     enum Encoding {
      78             :         AutoEncoding,
      79             :         BinaryEncoding,
      80             :         Base64Encoding,
      81             :         ArmorEncoding,
      82             :         MimeEncoding,
      83             :         UrlEncoding,
      84             :         UrlEscEncoding,
      85             :         Url0Encoding,
      86             :     };
      87             :     Encoding encoding() const;
      88             :     Error setEncoding(Encoding encoding);
      89             : 
      90             :     enum Type {
      91             :         Invalid,
      92             :         Unknown,
      93             :         PGPSigned,
      94             :         PGPOther,
      95             :         PGPKey,
      96             :         CMSSigned,
      97             :         CMSEncrypted,
      98             :         CMSOther,
      99             :         X509Cert,
     100             :         PKCS12,
     101             :         PGPEncrypted,
     102             :         PGPSignature,
     103             :     };
     104             :     Type type() const;
     105             : 
     106             :     char *fileName() const;
     107             :     Error setFileName(const char *name);
     108             : 
     109             :     ssize_t read(void *buffer, size_t length);
     110             :     ssize_t write(const void *buffer, size_t length);
     111             :     off_t seek(off_t offset, int whence);
     112             : 
     113             :     /* Convenience function to do a seek (0, SEEK_SET).  */
     114             :     Error rewind();
     115             : 
     116             :     /** Try to parse the data to a key object using the
     117             :      * Protocol proto. Returns an empty list on error.*/
     118             :     std::vector<Key> toKeys(const Protocol proto = Protocol::OpenPGP) const;
     119             : 
     120             :     /** Return a copy of the data as std::string. Sets seek pos to 0 */
     121             :     std::string toString();
     122             : 
     123             :     class Private;
     124          58 :     Private *impl()
     125             :     {
     126          58 :         return d.get();
     127             :     }
     128          28 :     const Private *impl() const
     129             :     {
     130          28 :         return d.get();
     131             :     }
     132             : private:
     133             :     std::shared_ptr<Private> d;
     134             : };
     135             : 
     136             : }
     137             : 
     138             : GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Data)
     139             : 
     140             : #endif // __GPGMEPP_DATA_H__

Generated by: LCOV version 1.13