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 "algorithm.h"
16#include "assuan.h"
17#include "hex.h"
18#include "stringutils.h"
19
20#include <libkleo_debug.h>
21
22#if __has_include(<QGpgME/Debug>)
23#include <QGpgME/Debug>
24#endif
25
26#include <gpgme++/context.h>
27
28using namespace Kleo;
29using namespace GpgME;
30
31std::vector<std::string> Kleo::SCDaemon::getReaders(Error &err)
32{
33 auto c = Context::createForEngine(AssuanEngine, &err);
34 if (err) {
35 qCDebug(LIBKLEO_LOG) << "Creating context for Assuan engine failed:" << err;
36 return {};
37 }
38
39 auto assuanContext = std::shared_ptr<Context>(c.release());
40 const std::string command = "SCD GETINFO reader_list";
41 const std::string readers = Assuan::sendDataCommand(assuanContext, command.c_str(), err);
42 if (err) {
43 return {};
44 }
45
46 std::vector<std::string_view> tmp = Kleo::split(readers, '\n');
47 // remove empty entries; in particular, the last entry
48 Kleo::erase_if(tmp, std::mem_fn(&std::string_view::empty));
49
50 return Kleo::toStrings(tmp);
51}
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 Sat Dec 21 2024 16:56:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.