LCOV - code coverage report
Current view: top level - lang/cpp/tests - run-getkey.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 67 0.0 %
Date: 2018-11-15 08:49:49 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             :     run-getkey.cpp
       3             : 
       4             :     This file is part of GpgMEpp's test suite.
       5             :     Copyright (c) 2018 Intevation GmbH
       6             : 
       7             :     QGpgME is free software; you can redistribute it and/or
       8             :     modify it under the terms of the GNU General Public License,
       9             :     version 2, as published by the Free Software Foundation.
      10             : 
      11             :     QGpgME 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 GNU
      14             :     General Public License for more details.
      15             : 
      16             :     You should have received a copy of the GNU General Public License
      17             :     along with this program; if not, write to the Free Software
      18             :     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      19             : 
      20             :     In addition, as a special exception, the copyright holders give
      21             :     permission to link the code of this program with any edition of
      22             :     the Qt library by Trolltech AS, Norway (or with modified versions
      23             :     of Qt that use the same license as Qt), and distribute linked
      24             :     combinations including the two.  You must obey the GNU General
      25             :     Public License in all respects for all of the code used other than
      26             :     Qt.  If you modify this file, you may extend this exception to
      27             :     your version of the file, but you are not obligated to do so.  If
      28             :     you do not wish to do so, delete this exception statement from
      29             :     your version.
      30             : */
      31             : 
      32             : #ifdef HAVE_CONFIG_H
      33             :  #include "config.h"
      34             : #endif
      35             : 
      36             : #include "context.h"
      37             : #include "key.h"
      38             : 
      39             : #include <memory>
      40             : #include <sstream>
      41             : #include <iostream>
      42             : 
      43             : using namespace GpgME;
      44             : 
      45             : static int
      46           0 : show_usage (int ex)
      47             : {
      48             :   fputs ("usage: run-getkey [options] [keyIdOrFingerprint]\n\n"
      49             :          "Options:\n"
      50             :          "  --verbose        run in verbose mode\n"
      51             :          "  --openpgp        use the OpenPGP protocol (default)\n"
      52             :          "  --cms            use the CMS protocol\n"
      53             :          "  --secret         list only secret keys\n"
      54             :          "  --with-secret    list pubkeys with secret info filled\n"
      55             :          "  --local          use GPGME_KEYLIST_MODE_LOCAL\n"
      56             :          "  --extern         use GPGME_KEYLIST_MODE_EXTERN\n"
      57             :          "  --sigs           use GPGME_KEYLIST_MODE_SIGS\n"
      58             :          "  --tofu           use GPGME_KEYLIST_MODE_TOFU\n"
      59             :          "  --sig-notations  use GPGME_KEYLIST_MODE_SIG_NOTATIONS\n"
      60             :          "  --ephemeral      use GPGME_KEYLIST_MODE_EPHEMERAL\n"
      61             :          "  --validate       use GPGME_KEYLIST_MODE_VALIDATE\n"
      62             :          "  --locate         use GPGME_KEYLIST_MODE_LOCATE\n"
      63           0 :          , stderr);
      64           0 :   exit (ex);
      65             : }
      66             : 
      67             : int
      68           0 : main (int argc, char **argv)
      69             : {
      70           0 :     int last_argc = -1;
      71           0 :     Protocol protocol = OpenPGP;
      72           0 :     unsigned int mode = 0;
      73           0 :     bool only_secret = false;
      74             : 
      75           0 :     if (argc) {
      76           0 :         argc--; argv++;
      77             :     }
      78             : 
      79           0 :     while (argc && last_argc != argc ) {
      80           0 :         last_argc = argc;
      81           0 :         if (!strcmp (*argv, "--")) {
      82           0 :             argc--; argv++;
      83           0 :             break;
      84           0 :         } else if (!strcmp (*argv, "--help")) {
      85           0 :             show_usage (0);
      86           0 :         } else if (!strcmp (*argv, "--openpgp")) {
      87           0 :             protocol = OpenPGP;
      88           0 :             argc--; argv++;
      89           0 :         } else if (!strcmp (*argv, "--cms")) {
      90           0 :             protocol = CMS;
      91           0 :             argc--; argv++;
      92           0 :         } else if (!strcmp (*argv, "--secret")) {
      93           0 :             only_secret = true;
      94           0 :             argc--; argv++;
      95           0 :         } else if (!strcmp (*argv, "--local")) {
      96           0 :             mode |= KeyListMode::Local;
      97           0 :             argc--; argv++;
      98           0 :         } else if (!strcmp (*argv, "--extern")) {
      99           0 :             mode |= KeyListMode::Extern;
     100           0 :             argc--; argv++;
     101           0 :         }else if (!strcmp (*argv, "--tofu")) {
     102           0 :             mode |= KeyListMode::WithTofu;
     103           0 :             argc--; argv++;
     104           0 :         } else if (!strcmp (*argv, "--sigs")) {
     105           0 :             mode |= KeyListMode::Signatures;
     106           0 :             argc--; argv++;
     107           0 :         } else if (!strcmp (*argv, "--sig-notations")) {
     108           0 :             mode |= KeyListMode::SignatureNotations;
     109           0 :             argc--; argv++;
     110           0 :         } else if (!strcmp (*argv, "--ephemeral")) {
     111           0 :             mode |= KeyListMode::Ephemeral;
     112           0 :             argc--; argv++;
     113           0 :         } else if (!strcmp (*argv, "--validate")) {
     114           0 :             mode |= KeyListMode::Validate;
     115           0 :             argc--; argv++;
     116           0 :         } else if (!strcmp (*argv, "--locate")) {
     117           0 :             argc--; argv++;
     118           0 :             mode |= KeyListMode::Locate;
     119           0 :         } else if (!strncmp (*argv, "--", 2)) {
     120           0 :             show_usage (1);
     121             :         }
     122             :     }
     123             : 
     124           0 :     if (argc != 1) {
     125           0 :         show_usage (1);
     126             :     }
     127             : 
     128           0 :     GpgME::initializeLibrary();
     129           0 :     auto ctx = std::unique_ptr<Context> (Context::createForProtocol(protocol));
     130           0 :     if (!ctx) {
     131           0 :         std::cerr << "Failed to get Context";
     132           0 :         return -1;
     133             :     }
     134           0 :     ctx->setKeyListMode (mode);
     135           0 :     Error err;
     136           0 :     const GpgME::Key key = ctx->key (*argv, err, only_secret);
     137           0 :     std::stringstream ss;
     138             : 
     139           0 :     ss << "Key " << key << " Err: " << err.asString() << "\n";
     140             : 
     141           0 :     std::cout << ss.str();
     142             : 
     143           0 :     return 0;
     144           0 : }

Generated by: LCOV version 1.13