LCOV - code coverage report
Current view: top level - lang/cpp/src - tofuinfo.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 39 67 58.2 %
Date: 2016-11-29 15:07:43 Functions: 13 17 76.5 %

          Line data    Source code
       1             : /* tofuinfo.cpp - wraps gpgme tofu info
       2             :   Copyright (C) 2016 Intevation GmbH
       3             : 
       4             :   This file is part of GPGME++.
       5             : 
       6             :   GPGME++ is free software; you can redistribute it and/or
       7             :   modify it under the terms of the GNU Library General Public
       8             :   License as published by the Free Software Foundation; either
       9             :   version 2 of the License, or (at your option) any later version.
      10             : 
      11             :   GPGME++ is distributed in the hope that it will be useful,
      12             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :   GNU Library General Public License for more details.
      15             : 
      16             :   You should have received a copy of the GNU Library General Public License
      17             :   along with GPGME++; see the file COPYING.LIB.  If not, write to the
      18             :   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      19             :   Boston, MA 02110-1301, USA.
      20             : */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             :  #include "config.h"
      24             : #endif
      25             : 
      26             : #include "tofuinfo.h"
      27             : 
      28             : #include <istream>
      29             : #include "util.h"
      30             : 
      31             : class GpgME::TofuInfo::Private
      32             : {
      33             : public:
      34             :     Private() {}
      35          21 :     Private(gpgme_tofu_info_t info)
      36          21 :         : mInfo(info ? new _gpgme_tofu_info(*info) : nullptr)
      37             :     {
      38          21 :         if (mInfo && mInfo->description) {
      39           9 :             mInfo->description = strdup(mInfo->description);
      40             :         }
      41          21 :     }
      42             : 
      43             :     Private(const Private &other)
      44             :         : mInfo(other.mInfo)
      45             :     {
      46             :         if (mInfo && mInfo->description) {
      47             :             mInfo->description = strdup(mInfo->description);
      48             :         }
      49             :     }
      50             : 
      51          21 :     ~Private()
      52             :     {
      53          21 :         if (mInfo) {
      54          20 :             std::free(mInfo->description);
      55          20 :             mInfo->description = nullptr;
      56             : 
      57          20 :             delete mInfo;
      58             :         }
      59          21 :     }
      60             : 
      61             :     gpgme_tofu_info_t mInfo;
      62             : };
      63             : 
      64          21 : GpgME::TofuInfo::TofuInfo(gpgme_tofu_info_t info)
      65          21 :     : d(new Private(info))
      66             : {
      67          21 : }
      68             : 
      69           1 : GpgME::TofuInfo::TofuInfo() : d()
      70             : {
      71           1 : }
      72             : 
      73          66 : bool GpgME::TofuInfo::isNull() const
      74             : {
      75          66 :     return !d || !d->mInfo;
      76             : }
      77             : 
      78           6 : GpgME::TofuInfo::Validity GpgME::TofuInfo::validity() const
      79             : {
      80           6 :     if (isNull()) {
      81           1 :         return ValidityUnknown;
      82             :     }
      83           5 :     switch (d->mInfo->validity) {
      84             :         case 0:
      85           0 :             return Conflict;
      86             :         case 1:
      87           0 :             return NoHistory;
      88             :         case 2:
      89           5 :             return LittleHistory;
      90             :         case 3:
      91           0 :             return BasicHistory;
      92             :         case 4:
      93           0 :             return LargeHistory;
      94             :         default:
      95           0 :             return ValidityUnknown;
      96             :     }
      97             : }
      98             : 
      99           9 : GpgME::TofuInfo::Policy GpgME::TofuInfo::policy() const
     100             : {
     101           9 :     if (isNull()) {
     102           1 :         return PolicyUnknown;
     103             :     }
     104           8 :     switch (d->mInfo->policy) {
     105             :         case GPGME_TOFU_POLICY_NONE:
     106           0 :             return PolicyNone;
     107             :         case GPGME_TOFU_POLICY_AUTO:
     108           6 :             return PolicyAuto;
     109             :         case GPGME_TOFU_POLICY_GOOD:
     110           1 :             return PolicyGood;
     111             :         case GPGME_TOFU_POLICY_BAD:
     112           1 :             return PolicyBad;
     113             :         case GPGME_TOFU_POLICY_ASK:
     114           0 :             return PolicyAsk;
     115             :         case GPGME_TOFU_POLICY_UNKNOWN:
     116             :         default:
     117           0 :             return PolicyUnknown;
     118             :     }
     119             : }
     120             : 
     121           1 : const char *GpgME::TofuInfo::description() const
     122             : {
     123           1 :     return isNull() ? nullptr : d->mInfo->description;
     124             : }
     125             : 
     126          26 : unsigned short GpgME::TofuInfo::signCount() const
     127             : {
     128          26 :     return isNull() ? 0 : d->mInfo->signcount;
     129             : }
     130             : 
     131           0 : unsigned short GpgME::TofuInfo::encrCount() const
     132             : {
     133           0 :     return isNull() ? 0 : d->mInfo->encrcount;
     134             : }
     135             : 
     136           4 : unsigned long GpgME::TofuInfo::signFirst() const
     137             : {
     138           4 :     return isNull() ? 0 : d->mInfo->signfirst;
     139             : }
     140             : 
     141           6 : unsigned long GpgME::TofuInfo::signLast() const
     142             : {
     143           6 :     return isNull() ? 0 : d->mInfo->signlast;
     144             : }
     145             : 
     146           0 : unsigned long GpgME::TofuInfo::encrFirst() const
     147             : {
     148           0 :     return isNull() ? 0 : d->mInfo->encrfirst;
     149             : }
     150             : 
     151           0 : unsigned long GpgME::TofuInfo::encrLast() const
     152             : {
     153           0 :     return isNull() ? 0 : d->mInfo->encrlast;
     154             : }
     155             : 
     156           0 : std::ostream &GpgME::operator<<(std::ostream &os, const GpgME::TofuInfo &info)
     157             : {
     158           0 :     os << "GpgME::Signature::TofuInfo(";
     159           0 :     if (!info.isNull()) {
     160           0 :         os << "\n desc: "     << protect(info.description())
     161           0 :            << "\n validity: " << info.validity()
     162           0 :            << "\n policy: "   << info.policy()
     163           0 :            << "\n signcount: "<< info.signCount()
     164           0 :            << "\n signfirst: "<< info.signFirst()
     165           0 :            << "\n signlast: " << info.signLast()
     166           0 :            << "\n encrcount: "<< info.encrCount()
     167           0 :            << "\n encrfirst: "<< info.encrFirst()
     168           0 :            << "\n encrlast: " << info.encrLast()
     169           0 :            << '\n';
     170             :     }
     171           0 :     return os << ")";
     172          18 : }

Generated by: LCOV version 1.11