Libkleo

scdaemon.cpp
1/*
2 utils/scdaemon.cpp
3
4 This file is part of libkleopatra
5 SPDX-FileCopyrightText: 2021 g10 Code GmbH
6 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include <config-libkleo.h>
12
13#include "scdaemon.h"
14
15#include "assuan.h"
16#include "hex.h"
17#include "stringutils.h"
18
19#include <libkleo_debug.h>
20
21#if __has_include(<QGpgME/Debug>)
22#include <QGpgME/Debug>
23#endif
24
25#include <gpgme++/context.h>
26
27using namespace Kleo;
28using namespace GpgME;
29
30std::vector<std::string> Kleo::SCDaemon::getReaders(Error &err)
31{
32 std::vector<std::string> result;
33
34 auto c = Context::createForEngine(AssuanEngine, &err);
35 if (err) {
36 qCDebug(LIBKLEO_LOG) << "Creating context for Assuan engine failed:" << err;
37 return result;
38 }
39
40 auto assuanContext = std::shared_ptr<Context>(c.release());
41 const std::string command = "SCD GETINFO reader_list";
42 const auto readers = Assuan::sendDataCommand(assuanContext, command.c_str(), err);
43 if (err) {
44 return result;
45 }
46
47 result = split(readers, '\n');
48 // remove empty entries; in particular, the last entry
49 result.erase(std::remove_if(std::begin(result), std::end(result), std::mem_fn(&std::string::empty)), std::end(result));
50
51 return result;
52}
KLEO_EXPORT std::string sendDataCommand(std::shared_ptr< GpgME::Context > assuanContext, const std::string &command, GpgME::Error &err)
Sends the Assuan command using a default Assuan transaction and the assuanContext to the GnuPG agent ...
KLEO_EXPORT std::vector< std::string > getReaders(GpgME::Error &err)
Returns the list of available smart card readers.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.