LCOV - code coverage report
Current view: top level - lang/cpp/src - tofuinfo.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 67 62.7 %
Date: 2018-11-15 08:49:49 Functions: 13 17 76.5 %

          Line data    Source code
       1             : /* tofuinfo.cpp - wraps gpgme tofu info
       2             :   Copyright (C) 2016 by Bundesamt für Sicherheit in der Informationstechnik
       3             :   Software engineering by Intevation GmbH
       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             : #ifdef HAVE_CONFIG_H
      24             :  #include "config.h"
      25             : #endif
      26             : 
      27             : #include "tofuinfo.h"
      28             : 
      29             : #include <istream>
      30             : #include "util.h"
      31             : 
      32             : class GpgME::TofuInfo::Private
      33             : {
      34             : public:
      35             :     Private() {}
      36          23 :     Private(gpgme_tofu_info_t info)
      37          23 :         : mInfo(info ? new _gpgme_tofu_info(*info) : nullptr)
      38             :     {
      39          23 :         if (mInfo && mInfo->description) {
      40          10 :             mInfo->description = strdup(mInfo->description);
      41             :         }
      42          23 :     }
      43             : 
      44             :     Private(const Private &other)
      45             :         : mInfo(other.mInfo)
      46             :     {
      47             :         if (mInfo && mInfo->description) {
      48             :             mInfo->description = strdup(mInfo->description);
      49             :         }
      50             :     }
      51             : 
      52          23 :     ~Private()
      53          23 :     {
      54          23 :         if (mInfo) {
      55          22 :             std::free(mInfo->description);
      56          22 :             mInfo->description = nullptr;
      57             : 
      58          22 :             delete mInfo;
      59             :         }
      60          23 :     }
      61             : 
      62             :     gpgme_tofu_info_t mInfo;
      63             : };
      64             : 
      65          23 : GpgME::TofuInfo::TofuInfo(gpgme_tofu_info_t info)
      66          23 :     : d(new Private(info))
      67             : {
      68          23 : }
      69             : 
      70           1 : GpgME::TofuInfo::TofuInfo() : d()
      71             : {
      72           1 : }
      73             : 
      74          78 : bool GpgME::TofuInfo::isNull() const
      75             : {
      76          78 :     return !d || !d->mInfo;
      77             : }
      78             : 
      79           8 : GpgME::TofuInfo::Validity GpgME::TofuInfo::validity() const
      80             : {
      81           8 :     if (isNull()) {
      82           1 :         return ValidityUnknown;
      83             :     }
      84           7 :     switch (d->mInfo->validity) {
      85             :         case 0:
      86           1 :             return Conflict;
      87             :         case 1:
      88           0 :             return NoHistory;
      89             :         case 2:
      90           6 :             return LittleHistory;
      91             :         case 3:
      92           0 :             return BasicHistory;
      93             :         case 4:
      94           0 :             return LargeHistory;
      95             :         default:
      96           0 :             return ValidityUnknown;
      97             :     }
      98             : }
      99             : 
     100          11 : GpgME::TofuInfo::Policy GpgME::TofuInfo::policy() const
     101             : {
     102          11 :     if (isNull()) {
     103           1 :         return PolicyUnknown;
     104             :     }
     105          10 :     switch (d->mInfo->policy) {
     106             :         case GPGME_TOFU_POLICY_NONE:
     107           0 :             return PolicyNone;
     108             :         case GPGME_TOFU_POLICY_AUTO:
     109           7 :             return PolicyAuto;
     110             :         case GPGME_TOFU_POLICY_GOOD:
     111           1 :             return PolicyGood;
     112             :         case GPGME_TOFU_POLICY_BAD:
     113           1 :             return PolicyBad;
     114             :         case GPGME_TOFU_POLICY_ASK:
     115           1 :             return PolicyAsk;
     116             :         case GPGME_TOFU_POLICY_UNKNOWN:
     117             :         default:
     118           0 :             return PolicyUnknown;
     119             :     }
     120             : }
     121             : 
     122           1 : const char *GpgME::TofuInfo::description() const
     123             : {
     124           1 :     return isNull() ? nullptr : d->mInfo->description;
     125             : }
     126             : 
     127          28 : unsigned short GpgME::TofuInfo::signCount() const
     128             : {
     129          28 :     return isNull() ? 0 : d->mInfo->signcount;
     130             : }
     131             : 
     132           0 : unsigned short GpgME::TofuInfo::encrCount() const
     133             : {
     134           0 :     return isNull() ? 0 : d->mInfo->encrcount;
     135             : }
     136             : 
     137           6 : unsigned long GpgME::TofuInfo::signFirst() const
     138             : {
     139           6 :     return isNull() ? 0 : d->mInfo->signfirst;
     140             : }
     141             : 
     142           8 : unsigned long GpgME::TofuInfo::signLast() const
     143             : {
     144           8 :     return isNull() ? 0 : d->mInfo->signlast;
     145             : }
     146             : 
     147           0 : unsigned long GpgME::TofuInfo::encrFirst() const
     148             : {
     149           0 :     return isNull() ? 0 : d->mInfo->encrfirst;
     150             : }
     151             : 
     152           0 : unsigned long GpgME::TofuInfo::encrLast() const
     153             : {
     154           0 :     return isNull() ? 0 : d->mInfo->encrlast;
     155             : }
     156             : 
     157           0 : std::ostream &GpgME::operator<<(std::ostream &os, const GpgME::TofuInfo &info)
     158             : {
     159           0 :     os << "GpgME::Signature::TofuInfo(";
     160           0 :     if (!info.isNull()) {
     161             :         os << "\n desc: "     << protect(info.description())
     162           0 :            << "\n validity: " << info.validity()
     163           0 :            << "\n policy: "   << info.policy()
     164           0 :            << "\n signcount: "<< info.signCount()
     165           0 :            << "\n signfirst: "<< info.signFirst()
     166           0 :            << "\n signlast: " << info.signLast()
     167           0 :            << "\n encrcount: "<< info.encrCount()
     168           0 :            << "\n encrfirst: "<< info.encrFirst()
     169           0 :            << "\n encrlast: " << info.encrLast()
     170           0 :            << '\n';
     171             :     }
     172           0 :     return os << ")";
     173          24 : }

Generated by: LCOV version 1.13