├── .gitattributes ├── tests ├── README ├── CMakeLists.txt └── t-utils.cpp ├── .gitignore ├── src ├── gpgmepp.pc.in ├── GpgmeppConfig.cmake.in ├── context_vanilla.cpp ├── interfaces │ ├── statusconsumer.h │ ├── progressprovider.h │ ├── passphraseprovider.h │ ├── assuantransaction.h │ └── dataprovider.h ├── data_p.h ├── result_p.h ├── callbacks.h ├── gpgsetexpirytimeeditinteractor.h ├── gpgsetownertrusteditinteractor.h ├── statusconsumerassuantransaction.h ├── result.h ├── statusconsumerassuantransaction.cpp ├── exception.cpp ├── util.cpp ├── exception.h ├── gpgadduserideditinteractor.h ├── editinteractor.h ├── randomresults.h ├── gpgaddexistingsubkeyeditinteractor.h ├── defaultassuantransaction.h ├── vfsmountresult.h ├── gpgrevokekeyeditinteractor.h ├── keygenerationresult.h ├── keylistresult.h ├── notation.h ├── engineinfo.cpp ├── gpgagentgetinfoassuantransaction.h ├── gpgsignkeyeditinteractor.h ├── gpgmefw.h ├── keygenerationresult.cpp ├── scdgetinfoassuantransaction.h ├── vfsmountresult.cpp ├── defaultassuantransaction.cpp ├── context_p.h ├── error.h ├── gpggencardkeyinteractor.h ├── keylistresult.cpp ├── gpgagentgetinfoassuantransaction.cpp ├── encryptionresult.h ├── error.cpp ├── decryptionresult.h ├── tofuinfo.h ├── swdbresult.h ├── gpgsetexpirytimeeditinteractor.cpp ├── importresult.h ├── scdgetinfoassuantransaction.cpp ├── data.h ├── gpgsetownertrusteditinteractor.cpp ├── signingresult.h ├── tofuinfo.cpp └── encryptionresult.cpp ├── cmake └── modules │ ├── ECMVersionHeader.h.in │ ├── g10_generate_swdb.sh.in │ ├── g10_release.sh.in │ ├── g10_dist.sh.in │ ├── g10_sign-release.sh.in │ ├── ecm_uninstall.cmake.in │ ├── g10_generate_ChangeLog.cmake.in │ ├── g10_distcheck.sh.in │ ├── ECMUninstallTarget.cmake │ ├── G10CMakeSettings.cmake │ ├── G10AddGenChangeLogTarget.cmake │ ├── FindGpgme.cmake │ ├── G10GitHooks.cmake │ └── FindLibGpgError.cmake ├── doc └── DCO ├── AUTHORS ├── INSTALL.md ├── NEWS ├── README └── CMakeLists.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # we add a generated ChangeLog to the tarball 2 | /ChangeLog export-ignore 3 | -------------------------------------------------------------------------------- /tests/README: -------------------------------------------------------------------------------- 1 | Tests for the C++ bindings. 2 | 3 | Most autotests for the C++ bindings use the QTest framework 4 | and live in gpgmeqt. 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # GnuPG exclusions 2 | /aclocal.m4 3 | /autom4te.cache 4 | /config.h.in 5 | /configure 6 | /VERSION 7 | Makefile.in 8 | 9 | # Hidden files 10 | *~ 11 | -------------------------------------------------------------------------------- /src/gpgmepp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 4 | libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ 5 | @pkgconfig_host_line@ 6 | Name: gpgmepp 7 | Description: GnuPG Made Easy (C++ binding) 8 | Requires.private: gpg-error, gpgme 9 | Version: @G10_FULL_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lgpgmepp 12 | URL: https://www.gnupg.org/software/gpgme/index.html 13 | -------------------------------------------------------------------------------- /cmake/modules/ECMVersionHeader.h.in: -------------------------------------------------------------------------------- 1 | // This file was generated by ecm_setup_version(): DO NOT EDIT! 2 | 3 | #ifndef @HEADER_PREFIX@_VERSION_H 4 | #define @HEADER_PREFIX@_VERSION_H 5 | 6 | #define @HEADER_PREFIX@_VERSION_STRING "@HEADER_VERSION@" 7 | #define @HEADER_PREFIX@_VERSION_MAJOR @HEADER_VERSION_MAJOR@ 8 | #define @HEADER_PREFIX@_VERSION_MINOR @HEADER_VERSION_MINOR@ 9 | #define @HEADER_PREFIX@_VERSION_PATCH @HEADER_VERSION_PATCH@ 10 | #define @HEADER_PREFIX@_VERSION ((@HEADER_VERSION_MAJOR@<<16)|(@HEADER_VERSION_MINOR@<<8)|(@HEADER_VERSION_PATCH@)) 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/GpgmeppConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # CMake Config file for GPGME++ 2 | # Copyright 2025 g10 Code GmbH 3 | # Software engineering by Ingo Klöcker 4 | # 5 | # This file is part of GPGME++. 6 | # 7 | # GPGME++ is free software; you can redistribute it and/or modify it 8 | # under the terms of the GNU Lesser General Public License as 9 | # published by the Free Software Foundation; either version 2.1 of the 10 | # License, or (at your option) any later version. 11 | # 12 | # GPGME++ is distributed in the hope that it will be useful, but WITHOUT 13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 15 | # Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with this program; if not, see . 19 | # SPDX-License-Identifier: LGPL-2.1-or-later 20 | 21 | @PACKAGE_INIT@ 22 | 23 | include(CMakeFindDependencyMacro) 24 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") 25 | find_dependency(LibGpgError "@GPG_ERROR_REQUIRED_VERSION@") 26 | find_dependency(Gpgme "@GPGME_REQUIRED_VERSION@") 27 | 28 | include("${CMAKE_CURRENT_LIST_DIR}/GpgmeppTargets.cmake") 29 | -------------------------------------------------------------------------------- /doc/DCO: -------------------------------------------------------------------------------- 1 | GPGME++ Developer's Certificate of Origin. Version 1.0 2 | ======================================================= 3 | 4 | By making a contribution to the GPGME++ project, I certify that: 5 | 6 | (a) The contribution was created in whole or in part by me and I 7 | have the right to submit it under the free software license 8 | indicated in the file; or 9 | 10 | (b) The contribution is based upon previous work that, to the 11 | best of my knowledge, is covered under an appropriate free 12 | software license and I have the right under that license to 13 | submit that work with modifications, whether created in whole 14 | or in part by me, under the same free software license 15 | (unless I am permitted to submit under a different license), 16 | as indicated in the file; or 17 | 18 | (c) The contribution was provided directly to me by some other 19 | person who certified (a), (b) or (c) and I have not modified 20 | it. 21 | 22 | (d) I understand and agree that this project and the contribution 23 | are public and that a record of the contribution (including 24 | all personal information I submit with it, including my 25 | sign-off) is maintained indefinitely and may be redistributed 26 | consistent with this project or the free software license(s) 27 | involved. 28 | 29 | Signed-off-by: [Your name and mail address] 30 | -------------------------------------------------------------------------------- /src/context_vanilla.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | context_vanilla.cpp - wraps a gpgme key context, gpgme (vanilla)-specific functions 3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include 30 | 31 | GIOChannel *GpgME::getGIOChannel(int) 32 | { 33 | return nullptr; 34 | } 35 | 36 | QIODevice *GpgME::getQIODevice(int) 37 | { 38 | return nullptr; 39 | } 40 | -------------------------------------------------------------------------------- /src/interfaces/statusconsumer.h: -------------------------------------------------------------------------------- 1 | /* 2 | statusconsumer.h - Interface for status callbacks 3 | Copyright (c) 2020 g10 Code GmbH 4 | Software engineering by Ingo Klöcker 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifndef __GPGMEPP_INTERFACES_STATUSCONSUMER_H__ 25 | #define __GPGMEPP_INTERFACES_STATUSCONSUMER_H__ 26 | 27 | #include 28 | 29 | namespace GpgME 30 | { 31 | 32 | class GPGMEPP_EXPORT StatusConsumer 33 | { 34 | public: 35 | virtual ~StatusConsumer() {} 36 | 37 | virtual void status(const char *status, const char *details) = 0; 38 | }; 39 | 40 | } // namespace GpgME 41 | 42 | #endif // __GPGMEPP_INTERFACES_STATUSCONSUMER_H__ 43 | -------------------------------------------------------------------------------- /src/data_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | data_p.h - wraps a gpgme data object, private part -*- c++ -*- 3 | Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_DATA_P_H__ 26 | #define __GPGMEPP_DATA_P_H__ 27 | 28 | #include 29 | #include "callbacks.h" 30 | 31 | class GpgME::Data::Private 32 | { 33 | public: 34 | explicit Private(gpgme_data_t d = nullptr) 35 | : data(d), cbs(data_provider_callbacks) {} 36 | ~Private(); 37 | 38 | gpgme_data_t data; 39 | gpgme_data_cbs cbs; 40 | }; 41 | 42 | #endif // __GPGMEPP_DATA_P_H__ 43 | -------------------------------------------------------------------------------- /cmake/modules/g10_generate_swdb.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2025 g10 Code GmbH 4 | # Software engineering by Ingo Klöcker 5 | # 6 | # This file is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This file 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 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, see . 18 | # 19 | # SPDX-License-Identifier: GPL-3.0-or-later 20 | 21 | set -e 22 | 23 | archive_filename="@release_name@.@archive_format@" 24 | 25 | if [ ! -e "${archive_filename}" ]; then 26 | echo "Error: '${archive_filename}' does not exist." >&2 27 | exit 1 28 | fi 29 | 30 | ( 31 | pref="#+macro: @swdb_prefix@_" 32 | reldate="$(date -u +%Y-%m-%d)" 33 | echo "${pref}ver @version@" 34 | echo "${pref}date ${reldate}" 35 | echo "${pref}size $(wc -c <"${archive_filename}" | awk '{print int($1/1024)}')k" 36 | echo "${pref}sha1 $(sha1sum <"${archive_filename}" | cut -d' ' -f1)" 37 | echo "${pref}sha2 $(sha256sum <"${archive_filename}" | cut -d' ' -f1)" 38 | ) | tee @release_name@.swdb 39 | -------------------------------------------------------------------------------- /src/interfaces/progressprovider.h: -------------------------------------------------------------------------------- 1 | /* 2 | interface/progressprovider.h - Interface for progress reports 3 | Copyright (C) 2003 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_INTERFACES_PROGRESSPROVIDER_H__ 26 | #define __GPGMEPP_INTERFACES_PROGRESSPROVIDER_H__ 27 | 28 | namespace GpgME 29 | { 30 | 31 | class ProgressProvider 32 | { 33 | public: 34 | virtual ~ProgressProvider() {} 35 | 36 | virtual void showProgress(const char *what, int type, 37 | int current, int total) = 0; 38 | }; 39 | 40 | } // namespace GpgME 41 | 42 | #endif // __GPGMEPP_INTERFACES_PROGRESSPROVIDER_H__ 43 | -------------------------------------------------------------------------------- /src/interfaces/passphraseprovider.h: -------------------------------------------------------------------------------- 1 | /* 2 | interface/passphraseprovider.h - Interface for passphrase callbacks 3 | Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_INTERFACES_PASSPHRASEPROVIDER_H__ 26 | #define __GPGMEPP_INTERFACES_PASSPHRASEPROVIDER_H__ 27 | 28 | namespace GpgME 29 | { 30 | 31 | class PassphraseProvider 32 | { 33 | public: 34 | virtual ~PassphraseProvider() {} 35 | 36 | virtual char *getPassphrase(const char *useridHint, const char *description, 37 | bool previousWasBad, bool &canceled) = 0; 38 | }; 39 | 40 | } // namespace GpgME 41 | 42 | #endif // __GPGMEPP_INTERFACES_PASSPHRASEPROVIDER_H__ 43 | -------------------------------------------------------------------------------- /src/result_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | result.h - base class for results 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_RESULT_P_H__ 26 | #define __GPGMEPP_RESULT_P_H__ 27 | 28 | #define make_default_ctor(x) \ 29 | GpgME::x::x() : GpgME::Result(), d() {} 30 | 31 | #define make_error_ctor(x) \ 32 | GpgME::x::x( const Error & error ) \ 33 | : GpgME::Result( error ), d() \ 34 | { \ 35 | \ 36 | } 37 | 38 | #define make_isNull(x) bool GpgME::x::isNull() const { return !d && !bool(error()); } 39 | 40 | #define make_standard_stuff(x) \ 41 | make_default_ctor(x) \ 42 | make_error_ctor(x) \ 43 | make_isNull(x) 44 | 45 | #endif // __GPGMEPP_RESULT_P_H__ 46 | -------------------------------------------------------------------------------- /cmake/modules/g10_release.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2025 g10 Code GmbH 4 | # Software engineering by Ingo Klöcker 5 | # 6 | # This file is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This file 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 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, see . 18 | # 19 | # SPDX-License-Identifier: GPL-3.0-or-later 20 | 21 | ( 22 | set -e 23 | 24 | if [ "@CMAKE_BINARY_DIR@" = "@CMAKE_SOURCE_DIR@" ]; then 25 | echo "error: build directory must not be the source directory" >&2 26 | exit 2 27 | fi 28 | 29 | echo "/* Build started at $(date -uIseconds) */" 30 | 31 | cd @CMAKE_BINARY_DIR@ 32 | if [ -d "dist/@release_name@" ]; then 33 | find "dist/@release_name@" -type d ! -perm -700 -exec chmod u+rwx {} ';' 34 | fi 35 | rm -rf dist 36 | mkdir dist 37 | cd dist 38 | @CMAKE_COMMAND@ @CMAKE_SOURCE_DIR@/CMakeLists.txt 39 | 40 | @CMAKE_COMMAND@ --build . --verbose -t distcheck 41 | @CMAKE_COMMAND@ --build . -t gen-swdb 42 | 43 | echo "/* Build finished at $(date -uIseconds) */" 44 | echo "/*" 45 | echo " * Please run the final step interactively:" 46 | echo " * make sign-release" 47 | echo " */" 48 | ) 2>&1 | tee "@release_name@.buildlog" 49 | -------------------------------------------------------------------------------- /src/callbacks.h: -------------------------------------------------------------------------------- 1 | /* 2 | callbacks.h - callback targets for internal use: 3 | Copyright (C) 2003 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | This is an internal header file, subject to change without 10 | notice. DO NOT USE. 11 | 12 | GPGME++ is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Library General Public 14 | License as published by the Free Software Foundation; either 15 | version 2 of the License, or (at your option) any later version. 16 | 17 | GPGME++ is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU Library General Public License for more details. 21 | 22 | You should have received a copy of the GNU Library General Public License 23 | along with GPGME++; see the file COPYING.LIB. If not, write to the 24 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 25 | Boston, MA 02110-1301, USA. 26 | */ 27 | 28 | #ifndef __GPGMEPP_CALLBACKS_H__ 29 | #define __GPGMEPP_CALLBACKS_H__ 30 | 31 | #include 32 | 33 | extern "C" { 34 | 35 | void progress_callback(void *opaque, const char *what, 36 | int type, int current, int total); 37 | gpgme_error_t passphrase_callback(void *opaque, const char *uid_hint, 38 | const char *desc, int prev_was_bad, int fd); 39 | } 40 | 41 | namespace GpgME 42 | { 43 | extern const gpgme_data_cbs data_provider_callbacks; 44 | extern const gpgme_edit_cb_t edit_interactor_callback; 45 | } 46 | 47 | #endif // __GPGME_CALLBACKS_H__ 48 | -------------------------------------------------------------------------------- /src/interfaces/assuantransaction.h: -------------------------------------------------------------------------------- 1 | /* 2 | assuantransaction.h - Interface for ASSUAN transactions 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | Author: Marc Mutz 7 | 8 | This file is part of GPGME++. 9 | 10 | GPGME++ is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Library General Public 12 | License as published by the Free Software Foundation; either 13 | version 2 of the License, or (at your option) any later version. 14 | 15 | GPGME++ is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU Library General Public License for more details. 19 | 20 | You should have received a copy of the GNU Library General Public License 21 | along with GPGME++; see the file COPYING.LIB. If not, write to the 22 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 | Boston, MA 02110-1301, USA. 24 | */ 25 | 26 | #ifndef __GPGMEPP_INTERFACES_ASSUANTRANSACTION_H__ 27 | #define __GPGMEPP_INTERFACES_ASSUANTRANSACTION_H__ 28 | 29 | #include 30 | 31 | #include 32 | 33 | namespace GpgME 34 | { 35 | 36 | class Error; 37 | class Data; 38 | 39 | class GPGMEPP_EXPORT AssuanTransaction 40 | { 41 | public: 42 | virtual ~AssuanTransaction() {} 43 | 44 | virtual Error data(const char *data, size_t datalen) = 0; 45 | virtual Data inquire(const char *name, const char *args, Error &err) = 0; 46 | virtual Error status(const char *status, const char *args) = 0; 47 | }; 48 | 49 | } // namespace GpgME 50 | 51 | #endif // __GPGMEPP_INTERFACES_ASSUANTRANSACTION_H__ 52 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeLists.txt for GpgME++ tests 2 | # Copyright 2025 g10 Code GmbH 3 | # Software engineering by Ingo Klöcker 4 | # 5 | # This file is part of GPGME++. 6 | # 7 | # GPGME++ is free software; you can redistribute it and/or modify it 8 | # under the terms of the GNU Lesser General Public License as 9 | # published by the Free Software Foundation; either version 2.1 of the 10 | # License, or (at your option) any later version. 11 | # 12 | # GPGME++ is distributed in the hope that it will be useful, but WITHOUT 13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 15 | # Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with this program; if not, see . 19 | # SPDX-License-Identifier: LGPL-2.1-or-later 20 | 21 | macro(_g10_add_testprogram _source) 22 | get_filename_component(_name ${_source} NAME_WE) 23 | add_executable(${_name} ${_source}) 24 | target_link_libraries(${_name} Gpgmepp) 25 | set_target_properties(${_name} PROPERTIES 26 | WIN32_EXECUTABLE FALSE # don't build as GUI app on Windows 27 | MACOSX_BUNDLE FALSE # don't build as GUI app on macOS 28 | ) 29 | endmacro() 30 | 31 | macro(_g10_add_test _source) 32 | _g10_add_testprogram(${_source}) 33 | get_filename_component(_name ${_source} NAME_WE) 34 | add_test(NAME ${_name} COMMAND ${_name}) 35 | endmacro() 36 | 37 | _g10_add_test(t-flags.cpp) 38 | _g10_add_test(t-utils.cpp) 39 | 40 | _g10_add_testprogram(run-createkey.cpp) 41 | _g10_add_testprogram(run-genrandom.cpp) 42 | _g10_add_testprogram(run-getkey.cpp) 43 | _g10_add_testprogram(run-keylist.cpp) 44 | _g10_add_testprogram(run-verify.cpp) 45 | _g10_add_testprogram(run-wkdlookup.cpp) 46 | -------------------------------------------------------------------------------- /src/gpgsetexpirytimeeditinteractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpgsetexpirytimeeditinteractor.h - Edit Interactor to change the expiry time of an OpenPGP key 3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H__ 26 | #define __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H__ 27 | 28 | #include "editinteractor.h" 29 | 30 | #include 31 | 32 | namespace GpgME 33 | { 34 | 35 | class GPGMEPP_EXPORT GpgSetExpiryTimeEditInteractor : public EditInteractor 36 | { 37 | public: 38 | explicit GpgSetExpiryTimeEditInteractor(const std::string &timeString = "0"); 39 | ~GpgSetExpiryTimeEditInteractor(); 40 | 41 | private: 42 | const char *action(Error &err) const override; 43 | unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; 44 | 45 | private: 46 | const std::string m_strtime; 47 | }; 48 | 49 | } // namespace GpgME 50 | 51 | #endif // __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H___ 52 | -------------------------------------------------------------------------------- /src/gpgsetownertrusteditinteractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpgsetownertrusteditinteractor.h - Edit Interactor to change the owner trust of an OpenPGP key 3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__ 26 | #define __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__ 27 | 28 | #include "editinteractor.h" 29 | #include "key.h" 30 | 31 | #include 32 | 33 | namespace GpgME 34 | { 35 | 36 | class GPGMEPP_EXPORT GpgSetOwnerTrustEditInteractor : public EditInteractor 37 | { 38 | public: 39 | explicit GpgSetOwnerTrustEditInteractor(Key::OwnerTrust ownertrust); 40 | ~GpgSetOwnerTrustEditInteractor(); 41 | 42 | private: 43 | const char *action(Error &err) const override; 44 | unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; 45 | 46 | private: 47 | const Key::OwnerTrust m_ownertrust; 48 | }; 49 | 50 | } // namespace GpgME 51 | 52 | #endif // __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__ 53 | -------------------------------------------------------------------------------- /src/statusconsumerassuantransaction.h: -------------------------------------------------------------------------------- 1 | /* 2 | statusconsumerassuantransaction.h - Assuan transaction that forwards status lines to a consumer 3 | Copyright (c) 2020 g10 Code GmbH 4 | Software engineering by Ingo Klöcker 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifndef __GPGMEPP_STATUSCONSUMERASSUANTRANSACTION_H__ 25 | #define __GPGMEPP_STATUSCONSUMERASSUANTRANSACTION_H__ 26 | 27 | #include "interfaces/assuantransaction.h" 28 | 29 | namespace GpgME 30 | { 31 | 32 | class StatusConsumer; 33 | 34 | class GPGMEPP_EXPORT StatusConsumerAssuanTransaction: public AssuanTransaction 35 | { 36 | public: 37 | explicit StatusConsumerAssuanTransaction(StatusConsumer *statusConsumer); 38 | ~StatusConsumerAssuanTransaction(); 39 | 40 | private: 41 | Error data(const char *data, size_t datalen) override; 42 | Data inquire(const char *name, const char *args, Error &err) override; 43 | Error status(const char *status, const char *args) override; 44 | 45 | private: 46 | StatusConsumer *m_consumer; 47 | }; 48 | 49 | } // namespace GpgME 50 | 51 | #endif // __GPGMEPP_STATUSCONSUMERASSUANTRANSACTION_H__ 52 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Package: gpgmepp 2 | Homepage: https://gnupg.org/software/gpgme/ 3 | Download: https://gnupg.org/ftp/gcrypt/gpgme/ 4 | Repository: git://git.gnupg.org/gpgmepp.git 5 | Maintainer: Werner Koch 6 | Bug reports: https://bugs.gnupg.org 7 | Security related bug reports: security@gnupg.org 8 | License (software): LGPL-2.0-or-later 9 | License (tests): GPL-2.0-only, GPL-2.0-or-later 10 | 11 | 12 | GpgME++ is free software. See the files COPYING.LIB, COPYING.LESSER, 13 | and COPYING for copying conditions. License copyright years may be 14 | listed using range notation, e.g., 2000-2013, indicating that every 15 | year in the range, inclusive, is a copyrightable year that would 16 | otherwise be listed individually. 17 | 18 | 19 | List of Copyright holders 20 | ========================= 21 | 22 | Copyright (C) 1992-2022 Free Software Foundation, Inc. 23 | Copyright (C) 2000 Werner Koch 24 | Copyright (C) 2001-2024 g10 Code GmbH 25 | Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010 26 | Klarälvdalens Datakonsult AB 27 | Copyright (C) 2004-2016 several members of the KDE community 28 | (see git log of gpgmepp repository in KDE's git) 29 | Copyright (C) 2016, 2017 30 | Bundesamt für Sicherheit in der Informationstechnik 31 | Copyright (C) 2016, 2018 Intevation GmbH 32 | 33 | 34 | Authors with a DCO 35 | ================== 36 | 37 | Daniel Kahn Gillmor 38 | 2014-09-24:878ul9w4j8.fsf@alice.fifthhorseman.net: 39 | 40 | 41 | Copyright 2001, 2002, 2012, 2013 g10 Code GmbH 42 | 43 | This file is free software; as a special exception the author gives 44 | unlimited permission to copy and/or distribute it, with or without 45 | modifications, as long as this notice is preserved. 46 | 47 | This file is distributed in the hope that it will be useful, but 48 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 49 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 50 | -------------------------------------------------------------------------------- /cmake/modules/g10_dist.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2025 g10 Code GmbH 4 | # Software engineering by Ingo Klöcker 5 | # 6 | # This file is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This file 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 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, see . 18 | # 19 | # SPDX-License-Identifier: GPL-3.0-or-later 20 | 21 | set -e 22 | 23 | tarball_name="@g10_dist_archive_name@" 24 | tarball_format="@g10_dist_archive_format@" 25 | tarball_filename="${tarball_name}.${tarball_format}" 26 | 27 | if ! git --version >/dev/null 2>&1; then 28 | echo "Error: Could not find git." >&2 29 | exit 1 30 | fi 31 | if [ ! -e "@CMAKE_SOURCE_DIR@/.git" ]; then 32 | echo "Error: Source folder @CMAKE_SOURCE_DIR@ is not a git repository." >&2 33 | exit 1 34 | fi 35 | 36 | cd "@CMAKE_SOURCE_DIR@" 37 | 38 | # check if the requested archive format is supported by git 39 | if ! ( git archive -l | grep -q "^${tarball_format}$" ); then 40 | echo "Warning: git archive doesn't seem to support the format ${tarball_format}." 41 | echo " You can tell git how to create an archive of this format with something like this:" 42 | echo " git config --global tar.${tarball_format}.command 'fooz -c'" 43 | fi 44 | 45 | git archive --format "${tarball_format}" \ 46 | --prefix "${tarball_name}/" \ 47 | --output "@CMAKE_BINARY_DIR@/${tarball_filename}" \ 48 | @g10_dist_git_archive_extra_arguments@ \ 49 | HEAD 50 | -------------------------------------------------------------------------------- /src/result.h: -------------------------------------------------------------------------------- 1 | /* 2 | result.h - base class for results 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_RESULT_H__ 26 | #define __GPGMEPP_RESULT_H__ 27 | 28 | #include "gpgmefw.h" 29 | #include "error.h" 30 | 31 | #include // std::swap 32 | 33 | namespace GpgME 34 | { 35 | 36 | class GPGMEPP_EXPORT Result 37 | { 38 | protected: 39 | explicit Result() : mError() {} 40 | explicit Result(int err) : mError(err) {} 41 | explicit Result(const Error &err) : mError(err) {} 42 | 43 | void swap(Result &other) 44 | { 45 | std::swap(other.mError, mError); 46 | } 47 | 48 | public: 49 | const Error &error() const 50 | { 51 | return mError; 52 | } 53 | /** 54 | * Replaces the error set during construction with \p error. 55 | * Use with care, e.g. to set a more suitable error. 56 | */ 57 | void setError(const Error &error) 58 | { 59 | mError = error; 60 | } 61 | 62 | protected: 63 | Error mError; 64 | }; 65 | 66 | } 67 | 68 | #endif // __GPGMEPP_RESULT_H__ 69 | -------------------------------------------------------------------------------- /src/statusconsumerassuantransaction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | statusconsumerassuantransaction.cpp 3 | Copyright (c) 2020 g10 Code GmbH 4 | Software engineering by Ingo Klöcker 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include "config.h" 26 | #endif 27 | 28 | #include "statusconsumerassuantransaction.h" 29 | 30 | #include "data.h" 31 | #include "error.h" 32 | 33 | #include "interfaces/statusconsumer.h" 34 | 35 | using namespace GpgME; 36 | 37 | StatusConsumerAssuanTransaction::StatusConsumerAssuanTransaction(StatusConsumer *statusConsumer) 38 | : AssuanTransaction() 39 | , m_consumer(statusConsumer) 40 | { 41 | } 42 | 43 | StatusConsumerAssuanTransaction::~StatusConsumerAssuanTransaction() 44 | { 45 | } 46 | 47 | Error StatusConsumerAssuanTransaction::data(const char *data, size_t datalen) 48 | { 49 | (void) data; 50 | (void) datalen; 51 | return Error(); 52 | } 53 | 54 | Data StatusConsumerAssuanTransaction::inquire(const char *name, const char *args, Error &err) 55 | { 56 | (void)name; 57 | (void)args; 58 | (void)err; 59 | return Data::null; 60 | } 61 | 62 | Error StatusConsumerAssuanTransaction::status(const char *status, const char *args) 63 | { 64 | m_consumer->status(status, args); 65 | 66 | return Error(); 67 | } 68 | -------------------------------------------------------------------------------- /src/interfaces/dataprovider.h: -------------------------------------------------------------------------------- 1 | /* 2 | interface/dataprovider.h - Interface for data sources 3 | Copyright (C) 2003 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_INTERFACES_DATAPROVIDER_H__ 26 | #define __GPGMEPP_INTERFACES_DATAPROVIDER_H__ 27 | 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | 34 | namespace GpgME 35 | { 36 | 37 | class GPGMEPP_EXPORT DataProvider 38 | { 39 | public: 40 | virtual ~DataProvider() {} 41 | 42 | enum Operation { 43 | Read, Write, Seek, Release 44 | }; 45 | virtual bool isSupported(Operation op) const = 0; 46 | 47 | #ifdef _WIN32 48 | virtual gpgme_ssize_t read(void *buffer, size_t bufSize) = 0; 49 | virtual gpgme_ssize_t write(const void *buffer, size_t bufSize) = 0; 50 | virtual gpgme_off_t seek(gpgme_off_t offset, int whence) = 0; 51 | #else 52 | virtual ssize_t read(void *buffer, size_t bufSize) = 0; 53 | virtual ssize_t write(const void *buffer, size_t bufSize) = 0; 54 | virtual off_t seek(off_t offset, int whence) = 0; 55 | #endif 56 | virtual void release() = 0; 57 | }; 58 | 59 | } // namespace GpgME 60 | 61 | #endif // __GPGMEPP_INTERFACES_DATAPROVIDER_H__ 62 | -------------------------------------------------------------------------------- /cmake/modules/g10_sign-release.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2025 g10 Code GmbH 4 | # Software engineering by Ingo Klöcker 5 | # 6 | # This file is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This file 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 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, see . 18 | # 19 | # SPDX-License-Identifier: GPL-3.0-or-later 20 | 21 | set -e 22 | 23 | test $(pwd | sed 's,.*/,,') = dist || cd dist 24 | x=$(grep '^RELEASE_ARCHIVE=' $HOME/.gnupg-autogen.rc|cut -d= -f2) 25 | if [ -z "$x" ]; then 26 | echo "error: RELEASE_ARCHIVE missing in ~/.gnupg-autogen.rc">&2 27 | exit 2 28 | fi 29 | myarchive="$x/@release_archive_suffix@" 30 | x=$(grep '^RELEASE_SIGNKEY=' $HOME/.gnupg-autogen.rc|cut -d= -f2) 31 | if [ -z "$x" ]; then 32 | echo "error: RELEASE_SIGNKEY missing in ~/.gnupg-autogen.rc">&2 33 | exit 2 34 | fi 35 | mysignkey="$x" 36 | files1= 37 | suffix= 38 | for suf in xz bz2 gz; do 39 | if [ -f "@release_name@.tar.$suf" ]; then 40 | files1="@release_name@.tar.$suf" 41 | files2="@release_name@.tar.$suf.sig" 42 | suffix=$suf 43 | break 44 | fi 45 | done 46 | files2="$files2 47 | @release_name@.swdb 48 | @release_name@.buildlog" 49 | echo "/* Signing the source tarball ..." 50 | gpg -sbu $mysignkey @release_name@.tar.$suffix 51 | cat @release_name@.swdb >swdb.snippet 52 | echo >>swdb.snippet 53 | sha1sum ${files1} >>swdb.snippet 54 | cat "../@release_name@.buildlog" swdb.snippet \ 55 | | gzip >@release_name@.buildlog 56 | echo "Copying to local archive ..." 57 | scp -p ${files1} ${files2} $myarchive/ || true 58 | echo '/*' 59 | echo ' * All done; for checksums see dist/swdb.snippet' 60 | echo ' */' 61 | -------------------------------------------------------------------------------- /src/exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | exception.cpp - exception wrapping a gpgme error 3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | // -*- c++ -*- 26 | #ifdef HAVE_CONFIG_H 27 | #include "config.h" 28 | #endif 29 | 30 | #include "exception.h" 31 | 32 | #include 33 | 34 | #include 35 | 36 | using namespace GpgME; 37 | using namespace std; // only safe b/c it's so small a file! 38 | 39 | Exception::~Exception() throw() {} 40 | 41 | // static 42 | string Exception::make_message(const Error &err, const string &msg) 43 | { 44 | return make_message(err, msg, NoOptions); 45 | } 46 | 47 | // static 48 | string Exception::make_message(const Error &err, const string &msg, Options opt) 49 | { 50 | if (opt & MessageOnly) { 51 | return msg; 52 | } 53 | char error_string[128]; 54 | error_string[0] = '\0'; 55 | gpgme_strerror_r(err.encodedError(), error_string, sizeof error_string); 56 | error_string[sizeof error_string - 1] = '\0'; 57 | stringstream ss; 58 | ss << gpgme_strsource(err.encodedError()) << ": "; 59 | if (!msg.empty()) { 60 | ss << msg << ": "; 61 | } 62 | ss << error_string << " (" << static_cast(err.encodedError()) << ')'; 63 | return ss.str(); 64 | } 65 | -------------------------------------------------------------------------------- /src/util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | util.cpp - some internal helpers 3 | Copyright (c) 2022 g10 Code GmbH 4 | Software engineering by Ingo Klöcker 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include "config.h" 26 | #endif 27 | 28 | #include "util.h" 29 | 30 | #include 31 | 32 | #include 33 | 34 | std::vector _gpgmepp::split_into_string_views(const char *s, char delimiter) 35 | { 36 | std::vector result; 37 | if (!s) { 38 | return result; 39 | } 40 | while (const char *segment_end = std::strchr(s, delimiter)) { 41 | if (const auto segment_size = segment_end - s) { 42 | result.emplace_back(s, segment_size); 43 | } 44 | s = segment_end + 1; 45 | }; 46 | if (const auto segment_size = std::strlen(s)) { 47 | result.emplace_back(s, segment_size); 48 | } 49 | return result; 50 | } 51 | 52 | StringsToCStrings::StringsToCStrings(const std::vector& v) 53 | : m_strings{v} 54 | { 55 | } 56 | 57 | const char **StringsToCStrings::c_strs() const 58 | { 59 | if (m_cstrings.empty()) { 60 | m_cstrings.reserve(m_strings.size() + 1); 61 | std::transform(std::begin(m_strings), std::end(m_strings), 62 | std::back_inserter(m_cstrings), 63 | std::mem_fn(&std::string::c_str)); 64 | m_cstrings.push_back(nullptr); 65 | } 66 | return m_cstrings.data(); 67 | } 68 | -------------------------------------------------------------------------------- /src/exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | exception.h - exception wrapping a gpgme error 3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | // -*- c++ -*- 26 | #ifndef __GPGMEPP_EXCEPTION_H__ 27 | #define __GPGMEPP_EXCEPTION_H__ 28 | 29 | #include "error.h" 30 | 31 | #include 32 | #include 33 | 34 | namespace GpgME 35 | { 36 | 37 | class GPGMEPP_EXPORT Exception : public std::runtime_error 38 | { 39 | public: 40 | enum Options { 41 | NoOptions = 0x0, 42 | MessageOnly = 0x1, 43 | 44 | AllOptions = MessageOnly 45 | }; 46 | 47 | explicit Exception(const GpgME::Error &err, const std::string &msg = std::string(), Options opt = NoOptions) 48 | : std::runtime_error(make_message(err, msg, opt)), m_error(err), m_message(msg) {} 49 | 50 | ~Exception() throw(); 51 | 52 | Error error() const 53 | { 54 | return m_error; 55 | } 56 | const std::string &message() const 57 | { 58 | return m_message; 59 | } 60 | private: 61 | static std::string make_message(const GpgME::Error &err, const std::string &msg); 62 | static std::string make_message(const GpgME::Error &err, const std::string &msg, Options opt); 63 | private: 64 | const GpgME::Error m_error; 65 | const std::string m_message; 66 | }; 67 | 68 | } // namespace GpgME 69 | 70 | #endif /* __GPGMEPP_EXCEPTION_H__ */ 71 | -------------------------------------------------------------------------------- /src/gpgadduserideditinteractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpgadduserideditinteractor.h - Edit Interactor to add a new UID to an OpenPGP key 3 | Copyright (C) 2008 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_GPGADDUSERIDEDITINTERACTOR_H__ 26 | #define __GPGMEPP_GPGADDUSERIDEDITINTERACTOR_H__ 27 | 28 | #include "editinteractor.h" 29 | 30 | #include 31 | 32 | namespace GpgME 33 | { 34 | 35 | class GPGMEPP_EXPORT GpgAddUserIDEditInteractor : public EditInteractor 36 | { 37 | public: 38 | explicit GpgAddUserIDEditInteractor(); 39 | ~GpgAddUserIDEditInteractor(); 40 | 41 | void setNameUtf8(const std::string &name); 42 | const std::string &nameUtf8() const 43 | { 44 | return m_name; 45 | } 46 | 47 | void setEmailUtf8(const std::string &email); 48 | const std::string &emailUtf8() const 49 | { 50 | return m_email; 51 | } 52 | 53 | void setCommentUtf8(const std::string &comment); 54 | const std::string &commentUtf8() const 55 | { 56 | return m_comment; 57 | } 58 | 59 | private: 60 | const char *action(Error &err) const override; 61 | unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; 62 | 63 | private: 64 | std::string m_name, m_email, m_comment; 65 | }; 66 | 67 | } // namespace GpgME 68 | 69 | #endif // __GPGMEPP_GPGADDUSERIDEDITINTERACTOR_H__ 70 | -------------------------------------------------------------------------------- /src/editinteractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | editinteractor.h - Interface for edit interactors 3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_EDITINTERACTOR_H__ 26 | #define __GPGMEPP_EDITINTERACTOR_H__ 27 | 28 | #include "gpgmepp_export.h" 29 | 30 | #include 31 | 32 | namespace GpgME 33 | { 34 | 35 | class Error; 36 | class Context; 37 | class CallbackHelper; 38 | 39 | class GPGMEPP_EXPORT EditInteractor 40 | { 41 | friend class ::GpgME::Context; 42 | friend class ::GpgME::CallbackHelper; 43 | EditInteractor(const EditInteractor &); 44 | EditInteractor &operator=(const EditInteractor &); 45 | public: 46 | EditInteractor(); 47 | virtual ~EditInteractor(); 48 | 49 | enum { 50 | StartState = 0, 51 | ErrorState = 0xFFFFFFFF 52 | }; 53 | 54 | virtual const char *action(Error &err) const = 0; 55 | virtual unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const = 0; 56 | 57 | unsigned int state() const; 58 | Error lastError() const; 59 | bool needsNoResponse(unsigned int statusCode) const; 60 | 61 | void setDebugChannel(std::FILE *file); 62 | 63 | protected: 64 | Error parseStatusError(const char *args); 65 | 66 | private: 67 | class Private; 68 | Private *const d; 69 | }; 70 | 71 | } // namespace GpgME 72 | 73 | #endif // __GPGMEPP_EDITINTERACTOR_H__ 74 | -------------------------------------------------------------------------------- /src/randomresults.h: -------------------------------------------------------------------------------- 1 | /* 2 | randomresults.h - wrappers of the gpgme random results 3 | Copyright (C) 2025 g10 Code GmbH 4 | Software engineering by Ingo Klöcker 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with this program; if not, see . 20 | SPDX-License-Identifier: LGPL-2.0-or-later 21 | */ 22 | 23 | #ifndef __GPGMEPP_RANDOMRESULTS_H__ 24 | #define __GPGMEPP_RANDOMRESULTS_H__ 25 | 26 | #include "result.h" 27 | 28 | #include 29 | 30 | namespace GpgME 31 | { 32 | 33 | class GPGMEPP_EXPORT RandomBytesResult : public Result 34 | { 35 | public: 36 | using value_type = std::vector; 37 | RandomBytesResult() 38 | : Result{GPG_ERR_NO_VALUE} 39 | { 40 | } 41 | explicit RandomBytesResult(const value_type &value) 42 | : mValue{value} 43 | { 44 | } 45 | explicit RandomBytesResult(const Error &err) 46 | : Result{err} 47 | { 48 | } 49 | 50 | const value_type &value() const 51 | { 52 | return mValue; 53 | } 54 | 55 | private: 56 | value_type mValue; 57 | }; 58 | 59 | class GPGMEPP_EXPORT RandomValueResult : public Result 60 | { 61 | public: 62 | RandomValueResult() 63 | : Result{GPG_ERR_NO_VALUE} 64 | { 65 | } 66 | explicit RandomValueResult(unsigned int value) 67 | : mValue{value} 68 | { 69 | } 70 | explicit RandomValueResult(const Error &err) 71 | : Result{err} 72 | { 73 | } 74 | 75 | unsigned int value() const 76 | { 77 | return mValue; 78 | } 79 | 80 | private: 81 | unsigned int mValue = 0; 82 | }; 83 | 84 | } // namespace GpgME 85 | 86 | #endif /* __GPGMEPP_RANDOMRESULTS_H__ */ 87 | -------------------------------------------------------------------------------- /src/gpgaddexistingsubkeyeditinteractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpgaddexistingsubkeyeditinteractor.h - Edit Interactor to add an existing subkey to an OpenPGP key 3 | Copyright (c) 2022 g10 Code GmbH 4 | Software engineering by Ingo Klöcker 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifndef __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__ 25 | #define __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__ 26 | 27 | #include "editinteractor.h" 28 | 29 | #include 30 | #include 31 | 32 | namespace GpgME 33 | { 34 | 35 | class GPGMEPP_EXPORT GpgAddExistingSubkeyEditInteractor : public EditInteractor 36 | { 37 | public: 38 | /** Edit interactor to add the existing subkey with keygrip \a keygrip 39 | * to the key a key edit operation is working on. 40 | **/ 41 | explicit GpgAddExistingSubkeyEditInteractor(const std::string &keygrip); 42 | ~GpgAddExistingSubkeyEditInteractor() override; 43 | 44 | /** Sets the validity period of the added subkey. Use "0" for no expiration 45 | * or a simplified ISO date string ("yyyymmddThhmmss") for setting an 46 | * expiration date. */ 47 | void setExpiry(const std::string &timeString); 48 | 49 | private: 50 | const char *action(Error &err) const override; 51 | unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; 52 | 53 | private: 54 | class Private; 55 | const std::unique_ptr d; 56 | }; 57 | 58 | } // namespace GpgME 59 | 60 | #endif // __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__ 61 | -------------------------------------------------------------------------------- /src/defaultassuantransaction.h: -------------------------------------------------------------------------------- 1 | /* 2 | defaultassuantransaction.h - default Assuan Transaction that just stores data and status lines 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_DEFAULTASSUANTRANSACTION_H__ 26 | #define __GPGMEPP_DEFAULTASSUANTRANSACTION_H__ 27 | 28 | #include "interfaces/assuantransaction.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | namespace GpgME 35 | { 36 | 37 | class GPGMEPP_EXPORT DefaultAssuanTransaction : public AssuanTransaction 38 | { 39 | public: 40 | explicit DefaultAssuanTransaction(); 41 | ~DefaultAssuanTransaction(); 42 | 43 | const std::vector< std::pair > &statusLines() const 44 | { 45 | return m_status; 46 | } 47 | std::vector statusLine(const char *tag) const; 48 | std::string firstStatusLine(const char *tag) const; 49 | 50 | const std::string &data() const 51 | { 52 | return m_data; 53 | } 54 | 55 | private: 56 | Error data(const char *data, size_t datalen) override; 57 | Data inquire(const char *name, const char *args, Error &err) override; 58 | Error status(const char *status, const char *args) override; 59 | 60 | private: 61 | std::vector< std::pair > m_status; 62 | std::string m_data; 63 | }; 64 | 65 | } // namespace GpgME 66 | 67 | #endif // __GPGMEPP_DEFAULTASSUANTRANSACTION_H__ 68 | -------------------------------------------------------------------------------- /src/vfsmountresult.h: -------------------------------------------------------------------------------- 1 | /* 2 | vfsmountresult.h - wraps a gpgme vfs mount result 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | Author: Marc Mutz , Volker Krause 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifndef __GPGMEPP_VFSMOUNTRESULT_H__ 25 | #define __GPGMEPP_VFSMOUNTRESULT_H__ 26 | 27 | #include "gpgmefw.h" 28 | #include "result.h" 29 | #include "gpgmepp_export.h" 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | namespace GpgME 37 | { 38 | 39 | class Error; 40 | 41 | class GPGMEPP_EXPORT VfsMountResult : public Result 42 | { 43 | public: 44 | VfsMountResult(); 45 | VfsMountResult(gpgme_ctx_t ctx, const Error &error, const Error &opError); 46 | explicit VfsMountResult(const Error &err); 47 | 48 | VfsMountResult(const VfsMountResult &other) = default; 49 | const VfsMountResult &operator=(VfsMountResult other) 50 | { 51 | swap(other); 52 | return *this; 53 | } 54 | 55 | void swap(VfsMountResult &other) 56 | { 57 | Result::swap(other); 58 | using std::swap; 59 | swap(this->d, other.d); 60 | } 61 | 62 | bool isNull() const; 63 | const char *mountDir() const; 64 | 65 | class Private; 66 | private: 67 | void init(gpgme_ctx_t ctx); 68 | std::shared_ptr d; 69 | }; 70 | 71 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const VfsMountResult &result); 72 | 73 | } 74 | 75 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(VfsMountResult) 76 | 77 | #endif // __GPGMEPP_VFSMOUNTRESULT_H__ 78 | -------------------------------------------------------------------------------- /src/gpgrevokekeyeditinteractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpgrevokekeyeditinteractor.h - Edit Interactor to revoke own OpenPGP keys 3 | Copyright (c) 2022 g10 Code GmbH 4 | Software engineering by Ingo Klöcker 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifndef __GPGMEPP_GPGREVOKEKEYEDITINTERACTOR_H__ 25 | #define __GPGMEPP_GPGREVOKEKEYEDITINTERACTOR_H__ 26 | 27 | #include "editinteractor.h" 28 | #include "global.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | namespace GpgME 35 | { 36 | 37 | /** Edit interactor to revoke the key a key edit operation is working on. 38 | * Supports revocation of own keys only. */ 39 | class GPGMEPP_EXPORT GpgRevokeKeyEditInteractor : public EditInteractor 40 | { 41 | public: 42 | GpgRevokeKeyEditInteractor(); 43 | ~GpgRevokeKeyEditInteractor() override; 44 | 45 | /** Sets the reason for the revocation. The reason defaults to \c Unspecified. 46 | * \a description can be used for adding a comment for the revocation. The 47 | * individual elements of \a description must be non-empty strings and they 48 | * must not contain any endline characters. 49 | */ 50 | void setReason(RevocationReason reason, const std::vector &description = {}); 51 | 52 | private: 53 | const char *action(Error &err) const override; 54 | unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; 55 | 56 | private: 57 | class GPGMEPP_NO_EXPORT Private; 58 | const std::unique_ptr d; 59 | }; 60 | 61 | } // namespace GpgME 62 | 63 | #endif // __GPGMEPP_GPGREVOKEKEYEDITINTERACTOR_H__ 64 | -------------------------------------------------------------------------------- /src/keygenerationresult.h: -------------------------------------------------------------------------------- 1 | /* 2 | keygenerationresult.h - wraps a gpgme keygen result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_KEYGENERATIONRESULT_H__ 26 | #define __GPGMEPP_KEYGENERATIONRESULT_H__ 27 | 28 | #include "gpgmefw.h" 29 | #include "result.h" 30 | #include "gpgmepp_export.h" 31 | 32 | #include 33 | 34 | namespace GpgME 35 | { 36 | 37 | class Error; 38 | 39 | class GPGMEPP_EXPORT KeyGenerationResult : public Result 40 | { 41 | public: 42 | KeyGenerationResult(); 43 | KeyGenerationResult(gpgme_ctx_t ctx, int error); 44 | KeyGenerationResult(gpgme_ctx_t ctx, const Error &error); 45 | explicit KeyGenerationResult(const Error &err); 46 | 47 | KeyGenerationResult(const KeyGenerationResult &other) = default; 48 | const KeyGenerationResult &operator=(KeyGenerationResult other) 49 | { 50 | swap(other); 51 | return *this; 52 | } 53 | 54 | void swap(KeyGenerationResult &other) 55 | { 56 | Result::swap(other); 57 | using std::swap; 58 | swap(this->d, other.d); 59 | } 60 | 61 | bool isNull() const; 62 | 63 | bool isPrimaryKeyGenerated() const; 64 | bool isSubkeyGenerated() const; 65 | const char *fingerprint() const; 66 | 67 | private: 68 | class Private; 69 | void init(gpgme_ctx_t ctx); 70 | std::shared_ptr d; 71 | }; 72 | 73 | } 74 | 75 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(KeyGenerationResult) 76 | 77 | #endif // __GPGMEPP_KEYGENERATIONRESULT_H__ 78 | -------------------------------------------------------------------------------- /cmake/modules/ecm_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Alex Merry 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | # 7 | # 1. Redistributions of source code must retain the copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | # 3. The name of the author may not be used to endorse or promote products 13 | # derived from this software without specific prior written permission. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | # SPDX-License-Identifier: BSD-3-Clause 27 | 28 | if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 29 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") 30 | endif() 31 | 32 | file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) 33 | string(REGEX REPLACE "\n" ";" files "${files}") 34 | foreach(file ${files}) 35 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 36 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 37 | execute_process( 38 | COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}" 39 | RESULT_VARIABLE rm_retval 40 | ) 41 | if(NOT "${rm_retval}" STREQUAL 0) 42 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 43 | endif() 44 | else() 45 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 46 | endif() 47 | endforeach() 48 | -------------------------------------------------------------------------------- /cmake/modules/g10_generate_ChangeLog.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright 2025 g10 Code GmbH 2 | # Software engineering by Ingo Klöcker 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions 6 | # are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | # 25 | # SPDX-License-Identifier: BSD-2-Clause 26 | 27 | find_package(Git QUIET REQUIRED) 28 | if(NOT EXISTS "@CMAKE_SOURCE_DIR@/.git") 29 | message(FATAL_ERROR "Cannot generate ChangeLog without git repo.") 30 | endif() 31 | 32 | find_program(GITLOG_TO_CHANGELOG gitlog-to-changelog) 33 | if(GITLOG_TO_CHANGELOG STREQUAL "GITLOG_TO_CHANGELOG-NOTFOUND") 34 | message(FATAL_ERROR "Could not find gitlog-to-changelog. A suitable gitlog-to-changelog script can be found in GnuPG master.") 35 | endif() 36 | 37 | if(NOT "@changelog_footer@" STREQUAL "") 38 | file(READ @changelog_footer@ footer) 39 | endif() 40 | if(NOT "@changelog_since@" STREQUAL "") 41 | set(since_args --since "@changelog_since@") 42 | endif() 43 | execute_process( 44 | COMMAND "${GITLOG_TO_CHANGELOG}" --append-dot --tear-off ${since_args} 45 | OUTPUT_FILE @CMAKE_BINARY_DIR@/ChangeLog 46 | WORKING_DIRECTORY "@CMAKE_SOURCE_DIR@" 47 | COMMAND_ERROR_IS_FATAL ANY 48 | ) 49 | if(footer) 50 | file(APPEND @CMAKE_BINARY_DIR@/ChangeLog "${footer}") 51 | endif() 52 | -------------------------------------------------------------------------------- /src/keylistresult.h: -------------------------------------------------------------------------------- 1 | /* 2 | keylistresult.h - wraps a gpgme keylist result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_KEYLISTRESULT_H__ 26 | #define __GPGMEPP_KEYLISTRESULT_H__ 27 | 28 | #include "gpgmefw.h" 29 | #include "result.h" 30 | #include "gpgmepp_export.h" 31 | 32 | #include 33 | 34 | namespace GpgME 35 | { 36 | 37 | class Error; 38 | 39 | class GPGMEPP_EXPORT KeyListResult : public Result 40 | { 41 | public: 42 | KeyListResult(); 43 | KeyListResult(gpgme_ctx_t ctx, int error); 44 | KeyListResult(gpgme_ctx_t ctx, const Error &error); 45 | explicit KeyListResult(const Error &err); 46 | KeyListResult(const Error &err, const _gpgme_op_keylist_result &res); 47 | 48 | KeyListResult(const KeyListResult &other) = default; 49 | const KeyListResult &operator=(KeyListResult other) 50 | { 51 | swap(other); 52 | return *this; 53 | } 54 | void swap(KeyListResult &other) 55 | { 56 | Result::swap(other); 57 | using std::swap; 58 | swap(this->d, other.d); 59 | } 60 | 61 | const KeyListResult &operator+=(const KeyListResult &other) 62 | { 63 | mergeWith(other); 64 | return *this; 65 | } 66 | 67 | void mergeWith(const KeyListResult &other); 68 | 69 | bool isNull() const; 70 | 71 | bool isTruncated() const; 72 | 73 | private: 74 | void detach(); 75 | void init(gpgme_ctx_t ctx); 76 | class Private; 77 | std::shared_ptr d; 78 | }; 79 | 80 | } 81 | 82 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(KeyListResult) 83 | 84 | #endif // __GPGMEPP_KEYLISTRESULT_H__ 85 | -------------------------------------------------------------------------------- /src/notation.h: -------------------------------------------------------------------------------- 1 | /* 2 | notation.h - wraps a gpgme verify result 3 | Copyright (C) 2004, 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_NOTATION_H__ 26 | #define __GPGMEPP_NOTATION_H__ 27 | 28 | #include "gpgmefw.h" 29 | #include "verificationresult.h" 30 | #include "gpgmepp_export.h" 31 | 32 | #include 33 | 34 | #include 35 | 36 | namespace GpgME 37 | { 38 | 39 | class GPGMEPP_EXPORT Notation 40 | { 41 | friend class ::GpgME::Signature; 42 | Notation(const std::shared_ptr &parent, unsigned int sindex, unsigned int nindex); 43 | public: 44 | Notation(); 45 | explicit Notation(gpgme_sig_notation_t nota); 46 | 47 | Notation(const Notation &other) = default; 48 | const Notation &operator=(Notation other) 49 | { 50 | swap(other); 51 | return *this; 52 | } 53 | 54 | void swap(Notation &other) 55 | { 56 | using std::swap; 57 | swap(this->d, other.d); 58 | } 59 | 60 | bool isNull() const; 61 | 62 | const char *name() const; 63 | const char *value() const; 64 | 65 | enum Flags { 66 | NoFlags = 0, 67 | HumanReadable = 1, 68 | Critical = 2 69 | }; 70 | Flags flags() const; 71 | 72 | bool isHumanReadable() const; 73 | bool isCritical() const; 74 | 75 | private: 76 | class Private; 77 | std::shared_ptr d; 78 | }; 79 | 80 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Notation ¬a); 81 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Notation::Flags flags); 82 | 83 | } 84 | 85 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Notation) 86 | 87 | #endif // __GPGMEPP_NOTATION_H__ 88 | -------------------------------------------------------------------------------- /src/engineinfo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | engineinfo.h 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include "engineinfo.h" 30 | 31 | #include 32 | 33 | class GpgME::EngineInfo::Private 34 | { 35 | public: 36 | Private(gpgme_engine_info_t engine = nullptr) : info(engine) {} 37 | ~Private() 38 | { 39 | info = nullptr; 40 | } 41 | 42 | gpgme_engine_info_t info; 43 | }; 44 | 45 | GpgME::EngineInfo::EngineInfo() : d() {} 46 | 47 | GpgME::EngineInfo::EngineInfo(gpgme_engine_info_t engine) 48 | : d(new Private(engine)) 49 | { 50 | 51 | } 52 | 53 | bool GpgME::EngineInfo::isNull() const 54 | { 55 | return !d || !d->info; 56 | } 57 | 58 | GpgME::Protocol GpgME::EngineInfo::protocol() const 59 | { 60 | if (isNull()) { 61 | return UnknownProtocol; 62 | } 63 | switch (d->info->protocol) { 64 | case GPGME_PROTOCOL_OpenPGP: return OpenPGP; 65 | case GPGME_PROTOCOL_CMS: return CMS; 66 | default: 67 | return UnknownProtocol; 68 | } 69 | } 70 | 71 | const char *GpgME::EngineInfo::fileName() const 72 | { 73 | return isNull() ? nullptr : d->info->file_name; 74 | } 75 | 76 | const char *GpgME::EngineInfo::version() const 77 | { 78 | return isNull() ? nullptr : d->info->version; 79 | } 80 | 81 | GpgME::EngineInfo::Version GpgME::EngineInfo::engineVersion() const 82 | { 83 | return Version(version()); 84 | } 85 | 86 | const char *GpgME::EngineInfo::requiredVersion() const 87 | { 88 | return isNull() ? nullptr : d->info->req_version; 89 | } 90 | 91 | const char *GpgME::EngineInfo::homeDirectory() const 92 | { 93 | return isNull() ? nullptr : d->info->home_dir; 94 | } 95 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # Installation Instructions 2 | 3 | Copyright 2025 g10 Code GmbH 4 | 5 | This file is free software; as a special exception the author gives 6 | unlimited permission to copy and/or distribute it, with or without 7 | modifications, as long as this notice is preserved. 8 | 9 | This file is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 11 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 | PURPOSE. 13 | 14 | ## Installation 15 | 16 | We recommend to make an out-of-source build, i.e. do something like 17 | 18 | ``` 19 | mkdir build 20 | cd build 21 | cmake .. 22 | make 23 | make install 24 | ``` 25 | 26 | to configure, build, and install the project. 27 | 28 | ## Configuration 29 | 30 | A few useful project-specific options to pass to cmake are: 31 | 32 | `-DBUILD_TESTING=OFF` 33 | Disables the build of the tests/examples in the tests folder. 34 | The default is `ON`. 35 | 36 | `-DENABLE_SHARED=OFF` 37 | Disables building the library as shared library. 38 | The default is `ON`. 39 | 40 | `-DENABLE_STATIC=ON` 41 | Enables building the library as static library. 42 | The default is `OFF`. 43 | 44 | Some useful general cmake options are: 45 | 46 | `-DCMAKE_BUILD_TYPE=RelWithDebInfo` 47 | Changes the build type to `RelWithDebInfo`. 48 | 49 | `-DCMAKE_INSTALL_PREFIX=/some/path` 50 | Changes the install directory to `/some/path`. 51 | 52 | See the documentation of cmake (https://cmake.org/cmake/help/latest/) 53 | for details. 54 | 55 | ## Packaging 56 | 57 | Run 58 | ``` 59 | make dist 60 | ``` 61 | to create a tarball of the sources. This uses `git archive`, i.e. it 62 | works on a git clone only. The current HEAD is packaged so that you 63 | can run it safely on a dirty working copy. Additionally, to the sources 64 | a VERSION file and a generated ChangeLog file are added to the tarball. 65 | 66 | The following common GnuPG make targets are also supported: 67 | 68 | `make distcheck` 69 | Creates a tarball and runs similar checks as the autotools target 70 | with the same name. 71 | 72 | `make release` 73 | Essentially this runs `make distcheck` to create a release tarball 74 | and generates the data for GnuPG's SWDB. All output is written to a 75 | *.buildlog file. 76 | 77 | `make sign-release` 78 | Signs the release tarball and uploads everything. The necessary 79 | information is read from `~/.gnupg-autogen.rc`. 80 | 81 | `make gen-ChangeLog` 82 | Used implicitly by `make dist` to generate a ChangeLog from the 83 | git history. 84 | 85 | `make gen-swdb` 86 | Used by `make release` to generate the data for GnuPG's SWDB. 87 | -------------------------------------------------------------------------------- /src/gpgagentgetinfoassuantransaction.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpgagentgetinfoassuantransaction.h - Assuan Transaction to get information from gpg-agent 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_GPGAGENTGETINFOASSUANTRANSACTION_H__ 26 | #define __GPGMEPP_GPGAGENTGETINFOASSUANTRANSACTION_H__ 27 | 28 | #include "interfaces/assuantransaction.h" 29 | 30 | #include 31 | #include 32 | 33 | namespace GpgME 34 | { 35 | 36 | class GPGMEPP_EXPORT GpgAgentGetInfoAssuanTransaction : public AssuanTransaction 37 | { 38 | public: 39 | enum InfoItem { 40 | Version, // string 41 | Pid, // unsigned long 42 | SocketName, // string (path) 43 | SshSocketName, // string (path) 44 | ScdRunning, // (none, returns GPG_ERR_GENERAL when scdaemon isn't running) 45 | //CommandHasOption, // not supported 46 | 47 | LastInfoItem 48 | }; 49 | 50 | explicit GpgAgentGetInfoAssuanTransaction(InfoItem item); 51 | ~GpgAgentGetInfoAssuanTransaction(); 52 | 53 | std::string version() const; 54 | unsigned int pid() const; 55 | std::string socketName() const; 56 | std::string sshSocketName() const; 57 | 58 | private: 59 | const char *command() const; 60 | Error data(const char *data, size_t datalen) override; 61 | Data inquire(const char *name, const char *args, Error &err) override; 62 | Error status(const char *status, const char *args) override; 63 | 64 | private: 65 | void makeCommand() const; 66 | 67 | private: 68 | InfoItem m_item; 69 | mutable std::string m_command; 70 | std::string m_data; 71 | }; 72 | 73 | } // namespace GpgME 74 | 75 | #endif // __GPGMEPP_GPGAGENTGETINFOASSUANTRANSACTION_H__ 76 | -------------------------------------------------------------------------------- /src/gpgsignkeyeditinteractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpgsignkeyeditinteractor.h - Edit Interactor to change the owner trust of an OpenPGP key 3 | Copyright (C) 2008 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_GPGSIGNKEYEDITINTERACTOR_H__ 26 | #define __GPGMEPP_GPGSIGNKEYEDITINTERACTOR_H__ 27 | 28 | #include "editinteractor.h" 29 | 30 | #include 31 | #include 32 | 33 | namespace GpgME 34 | { 35 | 36 | class Key; 37 | class UserID; 38 | enum class TrustSignatureTrust : char; 39 | 40 | class GPGMEPP_EXPORT GpgSignKeyEditInteractor : public EditInteractor 41 | { 42 | public: 43 | enum SignOption { 44 | Exportable = 0x1, 45 | NonRevocable = 0x2, 46 | Trust = 0x4 47 | }; 48 | 49 | GpgSignKeyEditInteractor(); 50 | ~GpgSignKeyEditInteractor(); 51 | 52 | void setCheckLevel(unsigned int checkLevel); 53 | void setUserIDsToSign(const std::vector &userIDsToSign); 54 | void setKey(const Key &key); 55 | void setSigningOptions(int options); 56 | 57 | /* Set this if it is ok to overwrite an existing signature. In that 58 | * case the context has to have the flag "extended-edit" set to 1 through 59 | * Context::setFlag before calling edit.*/ 60 | void setDupeOk(bool value); 61 | 62 | void setTrustSignatureTrust(TrustSignatureTrust trust); 63 | void setTrustSignatureDepth(unsigned short depth); 64 | void setTrustSignatureScope(const std::string &scope); 65 | 66 | private: 67 | const char *action(Error &err) const override; 68 | unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; 69 | 70 | private: 71 | class Private; 72 | Private *const d; 73 | }; 74 | 75 | } // namespace GpgME 76 | 77 | #endif // __GPGMEPP_GPGSIGNKEYEDITINTERACTOR_H__ 78 | -------------------------------------------------------------------------------- /src/gpgmefw.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpgmefw.h - Forwards declarations for gpgme (0.3 and 0.4) 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_GPGMEFW_H__ 26 | #define __GPGMEPP_GPGMEFW_H__ 27 | 28 | struct gpgme_context; 29 | typedef gpgme_context *gpgme_ctx_t; 30 | 31 | struct gpgme_data; 32 | typedef gpgme_data *gpgme_data_t; 33 | 34 | struct gpgme_io_cbs; 35 | 36 | struct _gpgme_key; 37 | typedef struct _gpgme_key *gpgme_key_t; 38 | 39 | struct _gpgme_trust_item; 40 | typedef struct _gpgme_trust_item *gpgme_trust_item_t; 41 | 42 | struct _gpgme_subkey; 43 | typedef struct _gpgme_subkey *gpgme_sub_key_t; 44 | 45 | struct _gpgme_user_id; 46 | typedef struct _gpgme_user_id *gpgme_user_id_t; 47 | 48 | struct _gpgme_key_sig; 49 | typedef struct _gpgme_key_sig *gpgme_key_sig_t; 50 | 51 | struct _gpgme_sig_notation; 52 | typedef struct _gpgme_sig_notation *gpgme_sig_notation_t; 53 | 54 | struct _gpgme_engine_info; 55 | typedef struct _gpgme_engine_info *gpgme_engine_info_t; 56 | 57 | struct _gpgme_op_keylist_result; 58 | typedef struct _gpgme_op_keylist_result *gpgme_keylist_result_t; 59 | 60 | struct _gpgme_recipient; 61 | typedef struct _gpgme_recipient *gpgme_recipient_t; 62 | 63 | struct gpgme_conf_opt; 64 | typedef struct gpgme_conf_opt *gpgme_conf_opt_t; 65 | 66 | struct gpgme_conf_comp; 67 | typedef struct gpgme_conf_comp *gpgme_conf_comp_t; 68 | 69 | struct gpgme_conf_arg; 70 | typedef struct gpgme_conf_arg *gpgme_conf_arg_t; 71 | 72 | struct _gpgme_tofu_info; 73 | typedef struct _gpgme_tofu_info *gpgme_tofu_info_t; 74 | 75 | struct _gpgme_op_query_swdb_result; 76 | typedef struct _gpgme_op_query_swdb_result *gpgme_query_swdb_result_t; 77 | 78 | struct _gpgme_revocation_key; 79 | typedef struct _gpgme_revocation_key *gpgme_revocation_key_t; 80 | 81 | #endif // __GPGMEPP_GPGMEFW_H__ 82 | -------------------------------------------------------------------------------- /src/keygenerationresult.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | keygenerationresult.cpp - wraps a gpgme keygen result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include 30 | #include "result_p.h" 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | class GpgME::KeyGenerationResult::Private 40 | { 41 | public: 42 | Private(const _gpgme_op_genkey_result &r) : res(r) 43 | { 44 | if (res.fpr) { 45 | res.fpr = strdup(res.fpr); 46 | } 47 | } 48 | ~Private() 49 | { 50 | if (res.fpr) { 51 | std::free(res.fpr); 52 | } 53 | res.fpr = nullptr; 54 | } 55 | 56 | _gpgme_op_genkey_result res; 57 | }; 58 | 59 | GpgME::KeyGenerationResult::KeyGenerationResult(gpgme_ctx_t ctx, int error) 60 | : GpgME::Result(error), d() 61 | { 62 | init(ctx); 63 | } 64 | 65 | GpgME::KeyGenerationResult::KeyGenerationResult(gpgme_ctx_t ctx, const Error &error) 66 | : GpgME::Result(error), d() 67 | { 68 | init(ctx); 69 | } 70 | 71 | void GpgME::KeyGenerationResult::init(gpgme_ctx_t ctx) 72 | { 73 | if (!ctx) { 74 | return; 75 | } 76 | gpgme_genkey_result_t res = gpgme_op_genkey_result(ctx); 77 | if (!res) { 78 | return; 79 | } 80 | d.reset(new Private(*res)); 81 | } 82 | 83 | make_standard_stuff(KeyGenerationResult) 84 | 85 | bool GpgME::KeyGenerationResult::isPrimaryKeyGenerated() const 86 | { 87 | return d && d->res.primary; 88 | } 89 | 90 | bool GpgME::KeyGenerationResult::isSubkeyGenerated() const 91 | { 92 | return d && d->res.sub; 93 | } 94 | 95 | const char *GpgME::KeyGenerationResult::fingerprint() const 96 | { 97 | return d ? d->res.fpr : nullptr ; 98 | } 99 | -------------------------------------------------------------------------------- /src/scdgetinfoassuantransaction.h: -------------------------------------------------------------------------------- 1 | /* 2 | scdgetinfoassuantransaction.h - Assuan Transaction to get information from scdaemon 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_SCDGETINFOASSUANTRANSACTION_H__ 26 | #define __GPGMEPP_SCDGETINFOASSUANTRANSACTION_H__ 27 | 28 | #include "interfaces/assuantransaction.h" 29 | 30 | #include 31 | #include 32 | 33 | namespace GpgME 34 | { 35 | 36 | class GPGMEPP_EXPORT ScdGetInfoAssuanTransaction : public AssuanTransaction 37 | { 38 | public: 39 | enum InfoItem { 40 | Version, // string 41 | Pid, // unsigned long 42 | SocketName, // string (path) 43 | Status, // char (status) 44 | ReaderList, // string list 45 | DenyAdmin, // (none, returns GPG_ERR_GENERAL when admin commands are allowed) 46 | ApplicationList, // string list 47 | 48 | LastInfoItem 49 | }; 50 | 51 | explicit ScdGetInfoAssuanTransaction(InfoItem item); 52 | ~ScdGetInfoAssuanTransaction(); 53 | 54 | std::string version() const; 55 | unsigned int pid() const; 56 | std::string socketName() const; 57 | char status() const; 58 | std::vector readerList() const; 59 | std::vector applicationList() const; 60 | 61 | private: 62 | const char *command() const; 63 | Error data(const char *data, size_t datalen) override; 64 | Data inquire(const char *name, const char *args, Error &err) override; 65 | Error status(const char *status, const char *args) override; 66 | 67 | private: 68 | void makeCommand() const; 69 | 70 | private: 71 | InfoItem m_item; 72 | mutable std::string m_command; 73 | std::string m_data; 74 | }; 75 | 76 | } // namespace GpgME 77 | 78 | #endif // __GPGMEPP_SCDGETINFOASSUANTRANSACTION_H__ 79 | -------------------------------------------------------------------------------- /src/vfsmountresult.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | vfsmountresult.cpp - wraps a gpgme vfs mount result 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | Author: Marc Mutz , Volker Krause 7 | 8 | This file is part of GPGME++. 9 | 10 | GPGME++ is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Library General Public 12 | License as published by the Free Software Foundation; either 13 | version 2 of the License, or (at your option) any later version. 14 | 15 | GPGME++ is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU Library General Public License for more details. 19 | 20 | You should have received a copy of the GNU Library General Public License 21 | along with GPGME++; see the file COPYING.LIB. If not, write to the 22 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 | Boston, MA 02110-1301, USA. 24 | */ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | #include "config.h" 28 | #endif 29 | 30 | #include 31 | #include "result_p.h" 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | using namespace GpgME; 39 | 40 | class VfsMountResult::Private 41 | { 42 | public: 43 | explicit Private(const gpgme_vfs_mount_result_t r) : mountDir(nullptr) 44 | { 45 | if (r && r->mount_dir) { 46 | mountDir = strdup(r->mount_dir); 47 | } 48 | } 49 | 50 | ~Private() 51 | { 52 | std::free(mountDir); 53 | } 54 | 55 | char *mountDir; 56 | }; 57 | 58 | VfsMountResult::VfsMountResult(gpgme_ctx_t ctx, const Error &error, const Error &opError) 59 | : Result(error ? error : opError), d() 60 | { 61 | init(ctx); 62 | } 63 | 64 | void VfsMountResult::init(gpgme_ctx_t ctx) 65 | { 66 | (void)ctx; 67 | if (!ctx) { 68 | return; 69 | } 70 | gpgme_vfs_mount_result_t res = gpgme_op_vfs_mount_result(ctx); 71 | if (!res) { 72 | return; 73 | } 74 | d.reset(new Private(res)); 75 | } 76 | 77 | make_standard_stuff(VfsMountResult) 78 | 79 | const char *VfsMountResult::mountDir() const 80 | { 81 | if (d) { 82 | return d->mountDir; 83 | } 84 | return nullptr; 85 | } 86 | 87 | std::ostream &GpgME::operator<<(std::ostream &os, const VfsMountResult &result) 88 | { 89 | os << "GpgME::VfsMountResult("; 90 | if (!result.isNull()) { 91 | os << "\n error: " << result.error() 92 | << "\n mount dir: " << result.mountDir() 93 | << "\n"; 94 | } 95 | return os << ')'; 96 | } 97 | -------------------------------------------------------------------------------- /src/defaultassuantransaction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | defaultassuantransaction.cpp - default Assuan Transaction that just stores data and status lines 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include "defaultassuantransaction.h" 30 | #include "error.h" 31 | #include "data.h" 32 | 33 | using namespace GpgME; 34 | 35 | DefaultAssuanTransaction::DefaultAssuanTransaction() 36 | : AssuanTransaction(), 37 | m_status(), 38 | m_data() 39 | { 40 | 41 | } 42 | 43 | DefaultAssuanTransaction::~DefaultAssuanTransaction() {} 44 | 45 | Error DefaultAssuanTransaction::data(const char *data, size_t len) 46 | { 47 | m_data.append(data, len); 48 | return Error(); 49 | } 50 | 51 | Data DefaultAssuanTransaction::inquire(const char *name, const char *args, Error &err) 52 | { 53 | (void)name; (void)args; (void)err; 54 | return Data::null; 55 | } 56 | 57 | Error DefaultAssuanTransaction::status(const char *status, const char *args) 58 | { 59 | m_status.push_back(std::pair(status, args)); 60 | return Error(); 61 | } 62 | 63 | std::vector DefaultAssuanTransaction::statusLine(const char *tag) const 64 | { 65 | std::vector result; 66 | for (std::vector< std::pair >::const_iterator it = m_status.begin(), end = m_status.end() ; it != end ; ++it) { 67 | if (it->first == tag) { 68 | result.push_back(it->second); 69 | } 70 | } 71 | return result; 72 | } 73 | 74 | std::string DefaultAssuanTransaction::firstStatusLine(const char *tag) const 75 | { 76 | for (std::vector< std::pair >::const_iterator it = m_status.begin(), end = m_status.end() ; it != end ; ++it) { 77 | if (it->first == tag) { 78 | return it->second; 79 | } 80 | } 81 | return std::string(); 82 | } 83 | -------------------------------------------------------------------------------- /src/context_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | context_p.h - wraps a gpgme context (private part) 3 | Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | // -*- c++ -*- 26 | #ifndef __GPGMEPP_CONTEXT_P_H__ 27 | #define __GPGMEPP_CONTEXT_P_H__ 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | namespace GpgME 35 | { 36 | 37 | class Context::Private 38 | { 39 | public: 40 | enum Operation { 41 | None = 0, 42 | 43 | Encrypt = 0x001, 44 | Decrypt = 0x002, 45 | Sign = 0x004, 46 | Verify = 0x008, 47 | DecryptAndVerify = Decrypt | Verify, 48 | SignAndEncrypt = Sign | Encrypt, 49 | 50 | Import = 0x010, 51 | Export = 0x020, // no gpgme_export_result_t, but nevertheless... 52 | Delete = 0x040, // no gpgme_delete_result_t, but nevertheless... 53 | 54 | KeyGen = 0x080, 55 | KeyList = 0x100, 56 | KeyListWithImport = KeyList | Import, // gpgme_keylist_result_t and gpgme_import_result_t 57 | // unused = 0x200, 58 | 59 | Edit = 0x400, // no gpgme_edit_result_t, but nevertheless... 60 | CardEdit = 0x800, // no gpgme_card_edit_result_t, but nevertheless... 61 | 62 | GetAuditLog = 0x1000, // no gpgme_getauditlog_result_t, but nevertheless... 63 | 64 | AssuanTransact = 0x2000, 65 | Passwd = 0x4000, // no gpgme_passwd_result_t, but nevertheless... 66 | 67 | CreateVFS = 0x4000, 68 | MountVFS = 0x8000, 69 | 70 | EndMarker 71 | }; 72 | 73 | Private(gpgme_ctx_t c = nullptr); 74 | ~Private(); 75 | 76 | gpgme_ctx_t ctx; 77 | gpgme_io_cbs *iocbs; 78 | Operation lastop; 79 | gpgme_error_t lasterr; 80 | Data lastAssuanInquireData; 81 | std::unique_ptr lastAssuanTransaction; 82 | std::unique_ptr lastEditInteractor, lastCardEditInteractor; 83 | DecryptionFlags decryptFlags; 84 | }; 85 | 86 | } // namespace GpgME 87 | 88 | #endif // __GPGMEPP_CONTEXT_P_H__ 89 | -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | error.h - wraps a gpgme error 3 | Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | // -*- c++ -*- 26 | #ifndef __GPGMEPP_ERROR_H__ 27 | #define __GPGMEPP_ERROR_H__ 28 | 29 | #include "global.h" 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | #ifndef GPGMEPP_ERR_SOURCE_DEFAULT 37 | # define GPGMEPP_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1 38 | #endif 39 | 40 | namespace GpgME 41 | { 42 | 43 | class GPGMEPP_EXPORT Error 44 | { 45 | public: 46 | Error() : mErr(0), mMessage() {} 47 | explicit Error(unsigned int e) : mErr(e), mMessage() {} 48 | 49 | const char *source() const; 50 | /* This function is deprecated. Use asStdString() instead. asString() may 51 | * return wrongly encoded (i.e. not UTF-8) results on Windows for the main 52 | * thread if the function was first called from a secondary thread. */ 53 | GPGMEPP_DEPRECATED const char *asString() const; 54 | std::string asStdString() const; 55 | 56 | int code() const; 57 | int sourceID() const; 58 | 59 | /** Returns true if the error code indicates success. */ 60 | bool isSuccess() const; 61 | /** Returns true if the error code indicates that the user canceled an operation. */ 62 | bool isCanceled() const; 63 | /** Returns true if the error code indicates that an error occurred. */ 64 | bool isError() const; 65 | 66 | unsigned int encodedError() const 67 | { 68 | return mErr; 69 | } 70 | int toErrno() const; 71 | 72 | static bool hasSystemError(); 73 | static Error fromSystemError(unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT); 74 | static void setSystemError(gpg_err_code_t err); 75 | static void setErrno(int err); 76 | static Error fromErrno(int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT); 77 | static Error fromCode(unsigned int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT); 78 | 79 | explicit operator bool() const 80 | { 81 | return isError(); 82 | } 83 | private: 84 | unsigned int mErr; 85 | mutable std::string mMessage; 86 | }; 87 | 88 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Error &err); 89 | 90 | } // namespace GpgME 91 | 92 | #endif /* __GPGMEPP_ERROR_H__ */ 93 | -------------------------------------------------------------------------------- /src/gpggencardkeyinteractor.h: -------------------------------------------------------------------------------- 1 | /* 2 | gpggencardkeyinteractor.h - Edit Interactor to generate a key on a card 3 | Copyright (C) 2017 by Bundesamt für Sicherheit in der Informationstechnik 4 | Software engineering by Intevation GmbH 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifndef __GPGMEPP_GPGGENCARDKEYEDITINTERACTOR_H__ 25 | #define __GPGMEPP_GPGGENCARDKEYEDITINTERACTOR_H__ 26 | 27 | #include "editinteractor.h" 28 | 29 | #include 30 | #include 31 | 32 | namespace GpgME 33 | { 34 | 35 | class GPGMEPP_EXPORT GpgGenCardKeyInteractor: public EditInteractor 36 | { 37 | public: 38 | /** Edit interactor to generate a key on a smartcard. 39 | * 40 | * The \a serialnumber argument is intended to safeguard 41 | * against accidentally working on the wrong smartcard. 42 | * 43 | * The edit interactor will fail if the card did not match. 44 | * 45 | * @param serialnumber: Serialnumber of the intended card. 46 | **/ 47 | explicit GpgGenCardKeyInteractor(const std::string &serialnumber); 48 | ~GpgGenCardKeyInteractor(); 49 | 50 | /** Set the key sizes for the subkeys (default 2048) */ 51 | void setKeySize(int size); 52 | 53 | void setNameUtf8(const std::string &name); 54 | void setEmailUtf8(const std::string &email); 55 | 56 | void setDoBackup(bool value); 57 | void setExpiry(const std::string &timeString); 58 | 59 | enum Algo { 60 | RSA = 1, 61 | ECC = 2, 62 | }; 63 | void setAlgo(Algo algo); 64 | 65 | // the enum values minus 1 have to match the indexes of the curves used by 66 | // ask_curve() in gnupg's g10/keygen.c 67 | enum Curve { 68 | DefaultCurve = 0, // currently Curve25519 69 | Curve25519 = 1, 70 | Curve448, 71 | NISTP256, 72 | NISTP384, 73 | NISTP521, 74 | BrainpoolP256, 75 | BrainpoolP384, 76 | BrainpoolP512, 77 | Secp256k1, 78 | LastCurve = Secp256k1, 79 | }; 80 | void setCurve(Curve curve); 81 | 82 | std::string backupFileName() const; 83 | 84 | private: 85 | const char *action(Error &err) const override; 86 | unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; 87 | 88 | private: 89 | class Private; 90 | std::shared_ptr d; 91 | }; 92 | 93 | } // namespace GpgME 94 | 95 | #endif // __GPGMEPP_GPGGENCARDKEYEDITINTERACTOR_H__ 96 | -------------------------------------------------------------------------------- /cmake/modules/g10_distcheck.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2025 g10 Code GmbH 4 | # Software engineering by Ingo Klöcker 5 | # 6 | # This file is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This file 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 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, see . 18 | # 19 | # SPDX-License-Identifier: GPL-3.0-or-later 20 | 21 | set -e 22 | 23 | tarball_name="@g10_distcheck_archive_name@" 24 | tarball_format="@g10_distcheck_archive_format@" 25 | tarball_filename="${tarball_name}.${tarball_format}" 26 | 27 | cd "@CMAKE_BINARY_DIR@" 28 | 29 | # extract the tarball replacing an already existing folder 30 | if [ -d "${tarball_name}" ]; then 31 | find "${tarball_name}" -type d ! -perm -700 -exec chmod u+rwx {} ';' 32 | rm -rf "${tarball_name}" 33 | fi 34 | case "${tarball_format}" in 35 | tar.gz) 36 | gzip -dc "${tarball_filename}" | tar xf - 37 | ;; 38 | tar.bz2) 39 | bzip2 -dc "${tarball_filename}" | tar xf - 40 | ;; 41 | tar.xz) 42 | xz -dc "${tarball_filename}" | tar xf - 43 | ;; 44 | *) 45 | echo "Error: Only tar.gz, tar.bz2, and tar.xz are supported." >&2 46 | exit 1 47 | ;; 48 | esac 49 | 50 | # make the sources read-only 51 | chmod -R a-w "${tarball_name}" 52 | # create subfolders for building and installing 53 | chmod u+w "${tarball_name}" 54 | mkdir "${tarball_name}/_build" "${tarball_name}/_build/sub" "${tarball_name}/_inst" 55 | chmod a-w "${tarball_name}" 56 | 57 | dc_install_base=`cd "${tarball_name}/_inst" && pwd` 58 | dc_destdir=`mktemp -d --tmpdir "distcheck-${tarball_name}.XXXXXXXXXX"` 59 | # TODO: support distcheck-hook 60 | dc_cwd=`pwd` 61 | 62 | cd "${tarball_name}/_build/sub" 63 | @CMAKE_COMMAND@ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="${dc_install_base}" ../.. 64 | @CMAKE_COMMAND@ --build . 65 | @CMAKE_CTEST_COMMAND@ --output-on-failure 66 | @CMAKE_COMMAND@ --install . 67 | # TODO: installcheck 68 | @CMAKE_COMMAND@ --build . -t uninstall 69 | # TODO: distuninstallcheck 70 | chmod -R a-w "${dc_install_base}" 71 | ( \ 72 | { \ 73 | DESTDIR="${dc_destdir}" @CMAKE_COMMAND@ --install . \ 74 | && DESTDIR="${dc_destdir}" @CMAKE_COMMAND@ --build . -t uninstall; \ 75 | } || { \ 76 | rm -rf "${dc_destdir}"; \ 77 | exit 1; \ 78 | } \ 79 | ) 80 | rm -rf "${dc_destdir}" 81 | 82 | cd "${dc_cwd}" 83 | 84 | if [ -d "${tarball_name}" ]; then 85 | find "${tarball_name}" -type d ! -perm -700 -exec chmod u+rwx {} ';' 86 | rm -rf "${tarball_name}" 87 | fi 88 | 89 | # print tarballs within "===..." separator lines 90 | ( \ 91 | echo "${tarball_name} archives ready for distribution: "; \ 92 | echo "${tarball_filename}" \ 93 | ) | sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$p' -e '$x' 94 | -------------------------------------------------------------------------------- /cmake/modules/ECMUninstallTarget.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Alex Merry 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | # 7 | # 1. Redistributions of source code must retain the copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | # 3. The name of the author may not be used to endorse or promote products 13 | # derived from this software without specific prior written permission. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | # SPDX-License-Identifier: BSD-3-Clause 27 | 28 | #[=======================================================================[.rst: 29 | ECMUninstallTarget 30 | ------------------ 31 | 32 | Add an ``uninstall`` target. 33 | 34 | By including this module, an ``uninstall`` target will be added to your CMake 35 | project. This will remove all files installed (or updated) by a previous 36 | invocation of the ``install`` target. It will not remove files created or 37 | modified by an ``install(SCRIPT)`` or ``install(CODE)`` command; you should 38 | create a custom uninstallation target for these and use ``add_dependency`` to 39 | make the ``uninstall`` target depend on it: 40 | 41 | .. code-block:: cmake 42 | 43 | include(ECMUninstallTarget) 44 | install(SCRIPT install-foo.cmake) 45 | add_custom_target(uninstall_foo COMMAND ${CMAKE_COMMAND} -P uninstall-foo.cmake) 46 | add_dependency(uninstall uninstall_foo) 47 | 48 | The target will fail if the ``install`` target has not yet been run (so it is 49 | not possible to run CMake on the project and then immediately run the 50 | ``uninstall`` target). 51 | 52 | .. warning:: 53 | 54 | CMake deliberately does not provide an ``uninstall`` target by default on 55 | the basis that such a target has the potential to remove important files 56 | from a user's computer. Use with caution. 57 | 58 | Since 1.7.0. 59 | #]=======================================================================] 60 | 61 | if (NOT TARGET uninstall) 62 | configure_file( 63 | "${CMAKE_CURRENT_LIST_DIR}/ecm_uninstall.cmake.in" 64 | "${CMAKE_BINARY_DIR}/ecm_uninstall.cmake" 65 | IMMEDIATE 66 | @ONLY 67 | ) 68 | 69 | add_custom_target(uninstall 70 | COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/ecm_uninstall.cmake" 71 | WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" 72 | ) 73 | endif() 74 | -------------------------------------------------------------------------------- /src/keylistresult.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | keylistresult.cpp - wraps a gpgme keylist result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include 30 | #include "result_p.h" 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | class GpgME::KeyListResult::Private 38 | { 39 | public: 40 | Private(const _gpgme_op_keylist_result &r) : res(r) {} 41 | Private(const Private &other) : res(other.res) {} 42 | 43 | _gpgme_op_keylist_result res; 44 | }; 45 | 46 | GpgME::KeyListResult::KeyListResult(gpgme_ctx_t ctx, int error) 47 | : GpgME::Result(error), d() 48 | { 49 | init(ctx); 50 | } 51 | 52 | GpgME::KeyListResult::KeyListResult(gpgme_ctx_t ctx, const Error &error) 53 | : GpgME::Result(error), d() 54 | { 55 | init(ctx); 56 | } 57 | 58 | void GpgME::KeyListResult::init(gpgme_ctx_t ctx) 59 | { 60 | if (!ctx) { 61 | return; 62 | } 63 | gpgme_keylist_result_t res = gpgme_op_keylist_result(ctx); 64 | if (!res) { 65 | return; 66 | } 67 | d.reset(new Private(*res)); 68 | } 69 | 70 | GpgME::KeyListResult::KeyListResult(const Error &error, const _gpgme_op_keylist_result &res) 71 | : GpgME::Result(error), d(new Private(res)) 72 | { 73 | 74 | } 75 | 76 | make_standard_stuff(KeyListResult) 77 | 78 | void GpgME::KeyListResult::detach() 79 | { 80 | if (!d || d.unique()) { 81 | return; 82 | } 83 | d.reset(new Private(*d)); 84 | } 85 | 86 | void GpgME::KeyListResult::mergeWith(const KeyListResult &other) 87 | { 88 | if (other.isNull()) { 89 | return; 90 | } 91 | if (isNull()) { // just assign 92 | operator=(other); 93 | return; 94 | } 95 | // merge the truncated flag (try to keep detaching to a minimum): 96 | if (other.isTruncated() && !this->isTruncated()) { 97 | assert(other.d); 98 | detach(); 99 | if (!d) { 100 | d.reset(new Private(*other.d)); 101 | } else { 102 | d->res.truncated = true; 103 | } 104 | } 105 | if (! bool(error())) { // only merge the error when there was none yet. 106 | Result::operator=(other); 107 | } 108 | } 109 | 110 | bool GpgME::KeyListResult::isTruncated() const 111 | { 112 | return d && d->res.truncated; 113 | } 114 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Noteworthy changes in version 2.0.1 (unreleased) [C7/A0/R)] 2 | ------------------------------------------------ 3 | 4 | * New function Subkey::keyGrips to get the list of keygrips for 5 | a subkey using combined algorithms. 6 | 7 | * Interface changes relative to the 2.0.0 release: 8 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 | 10 | Subkey::keyGrips NEW. 11 | 12 | Noteworthy changes in version 2.0.0 (2025-06-03) [C7/A0/R0] 13 | ------------------------------------------------ 14 | 15 | * First separate release of GpgME++. 16 | 17 | * build: The build system was changed from autotools to cmake. 18 | 19 | * The gpgme++ folder containing the header files is no longer exported 20 | as include directory. All headers have to be included with the prefix 21 | gpgme++/ now. 22 | 23 | * New function Context::generateRandomBytes to get cryptographically 24 | strong random bytes from gpg. [T6694] 25 | 26 | * New function Context::generateRandomValue to get a cryptographically 27 | strong unsigned integer random value. [T6694] 28 | 29 | * New flag to re-encrypt OpenPGP data (requires GnuPG 2.5.1). [D607] 30 | 31 | * New decrypt flag to skip the actual decryption so that information 32 | about the recipients can be retrieved. 33 | 34 | * Removed the TrustItem listing functionality which used GpgME's trustlist 35 | feature which worked only for a short period in 2003. [T4834] 36 | 37 | * Interface changes relative to the 1.24 branch of gpgme: 38 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 39 | Context::RandomMode NEW. 40 | Context::generateRandomBytes NEW. 41 | Context::generateRandomValue NEW. 42 | Context::DecryptionFlags::DecryptListOnly NEW. 43 | Context::EncryptionFlags::AddRecipient NEW. 44 | Context::EncryptionFlags::ChangeRecipient NEW. 45 | Context::CreationFlags NEW. 46 | Context::createKey CHANGED: New overload; deprecated old. 47 | Context::startCreateKey CHANGED: New overload; deprecated old. 48 | Context::createSubkey CHANGED: New overload; deprecated old. 49 | Context::startCreateSubkey CHANGED: New overload; deprecated old. 50 | Error::isError NEW. 51 | Error::isSuccess NEW. 52 | RandomBytesResult NEW. 53 | RandomValueResult NEW. 54 | Context::createKeyEx DEPRECATED. 55 | Context::startTrustItemListing REMOVED. 56 | Context::nextTrustItem REMOVED. 57 | Context::endTrustItemListing REMOVED. 58 | EventLoopInteractor::nextTrustItemEvent REMOVED. 59 | GPGMEPP_MAKE_SAFE_BOOL_OPERATOR REMOVED. 60 | TrustItem REMOVED. 61 | 62 | 63 | Noteworthy changes in earlier versions can be found in the NEWS file of 64 | gpgme. 65 | 66 | 67 | Copyright 2024 g10 Code GmbH 68 | 69 | This file is free software; as a special exception the author gives 70 | unlimited permission to copy and/or distribute it, with or without 71 | modifications, as long as this notice is preserved. 72 | 73 | This file is distributed in the hope that it will be useful, but 74 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 75 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 76 | -------------------------------------------------------------------------------- /cmake/modules/G10CMakeSettings.cmake: -------------------------------------------------------------------------------- 1 | # Common CMake settings for g10 Code; based on KDECMakeSettings.cmake 2 | # 3 | # Copyright 2014 Alex Merry 4 | # Copyright 2013 Aleix Pol 5 | # Copyright 2012-2013 Stephen Kelly 6 | # Copyright 2007 Matthias Kretz 7 | # Copyright 2006-2007 Laurent Montel 8 | # Copyright 2006-2013 Alex Neundorf 9 | # Copyright 2025 g10 Code GmbH 10 | # 11 | # Redistribution and use in source and binary forms, with or without 12 | # modification, are permitted provided that the following conditions 13 | # are met: 14 | # 15 | # 1. Redistributions of source code must retain the copyright 16 | # notice, this list of conditions and the following disclaimer. 17 | # 2. Redistributions in binary form must reproduce the copyright 18 | # notice, this list of conditions and the following disclaimer in the 19 | # documentation and/or other materials provided with the distribution. 20 | # 3. The name of the author may not be used to endorse or promote products 21 | # derived from this software without specific prior written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | # SPDX-License-Identifier: BSD-3-Clause 35 | 36 | ################# RPATH handling ################################## 37 | 38 | if (UNIX) 39 | # Append the linker search paths to the RPATH for installed targets 40 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 41 | endif (UNIX) 42 | 43 | ################ Testing setup #################################### 44 | 45 | option(BUILD_TESTING "Build the testing tree" ON) 46 | if(BUILD_TESTING) 47 | enable_testing() 48 | endif() 49 | 50 | 51 | 52 | ################ Build-related settings ########################### 53 | 54 | # Always include srcdir and builddir in include path 55 | # This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} in about every subdir 56 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 57 | 58 | # put the include dirs which are in the source or build tree 59 | # before all other include dirs, so the headers in the sources 60 | # are preferred over the already installed ones 61 | set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) 62 | 63 | # Add the src and build dir to the BUILD_INTERFACE include directories 64 | # of all targets. Similar to CMAKE_INCLUDE_CURRENT_DIR, but transitive. 65 | set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) 66 | 67 | # When a shared library changes, but its includes do not, don't relink 68 | # all dependencies. It is not needed. 69 | set(CMAKE_LINK_DEPENDS_NO_SHARED ON) 70 | 71 | # Add the SOVERSION target property to the filename of generated DLL filenames 72 | if (WIN32 AND NOT MSVC) 73 | # Official variable for enabling versioned DLL filenames; since cmake 3.27 74 | set(CMAKE_DLL_NAME_WITH_SOVERSION ON) 75 | # Undocumented variable which has the same effect (used internally for Cygwin) 76 | set(CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION ON) 77 | endif() 78 | -------------------------------------------------------------------------------- /src/gpgagentgetinfoassuantransaction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | gpgagentgetinfoassuantransaction.cpp - Assuan Transaction to get information from gpg-agent 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include "gpgagentgetinfoassuantransaction.h" 30 | #include "error.h" 31 | #include "data.h" 32 | #include "util.h" 33 | 34 | #include 35 | 36 | using namespace GpgME; 37 | 38 | GpgAgentGetInfoAssuanTransaction::GpgAgentGetInfoAssuanTransaction(InfoItem item) 39 | : AssuanTransaction(), 40 | m_item(item), 41 | m_command(), 42 | m_data() 43 | { 44 | 45 | } 46 | 47 | GpgAgentGetInfoAssuanTransaction::~GpgAgentGetInfoAssuanTransaction() {} 48 | 49 | std::string GpgAgentGetInfoAssuanTransaction::version() const 50 | { 51 | if (m_item == Version) { 52 | return m_data; 53 | } else { 54 | return std::string(); 55 | } 56 | } 57 | 58 | unsigned int GpgAgentGetInfoAssuanTransaction::pid() const 59 | { 60 | if (m_item == Pid) { 61 | return to_pid(m_data); 62 | } else { 63 | return 0U; 64 | } 65 | } 66 | 67 | std::string GpgAgentGetInfoAssuanTransaction::socketName() const 68 | { 69 | if (m_item == SocketName) { 70 | return m_data; 71 | } else { 72 | return std::string(); 73 | } 74 | } 75 | 76 | std::string GpgAgentGetInfoAssuanTransaction::sshSocketName() const 77 | { 78 | if (m_item == SshSocketName) { 79 | return m_data; 80 | } else { 81 | return std::string(); 82 | } 83 | } 84 | 85 | static const char *const gpgagent_getinfo_tokens[] = { 86 | "version", 87 | "pid", 88 | "socket_name", 89 | "ssh_socket_name", 90 | "scd_running", 91 | }; 92 | 93 | void GpgAgentGetInfoAssuanTransaction::makeCommand() const 94 | { 95 | assert(m_item >= 0); 96 | assert(m_item < LastInfoItem); 97 | m_command = "GETINFO "; 98 | m_command += gpgagent_getinfo_tokens[m_item]; 99 | } 100 | 101 | const char *GpgAgentGetInfoAssuanTransaction::command() const 102 | { 103 | makeCommand(); 104 | return m_command.c_str(); 105 | } 106 | 107 | Error GpgAgentGetInfoAssuanTransaction::data(const char *data, size_t len) 108 | { 109 | m_data.append(data, len); 110 | return Error(); 111 | } 112 | 113 | Data GpgAgentGetInfoAssuanTransaction::inquire(const char *name, const char *args, Error &err) 114 | { 115 | (void)name; (void)args; (void)err; 116 | return Data::null; 117 | } 118 | 119 | Error GpgAgentGetInfoAssuanTransaction::status(const char *status, const char *args) 120 | { 121 | (void)status; (void)args; 122 | return Error(); 123 | } 124 | -------------------------------------------------------------------------------- /src/encryptionresult.h: -------------------------------------------------------------------------------- 1 | /* 2 | encryptionresult.h - wraps a gpgme sign result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_ENCRYPTIONRESULT_H__ 26 | #define __GPGMEPP_ENCRYPTIONRESULT_H__ 27 | 28 | #include "gpgmefw.h" 29 | #include "result.h" 30 | #include "gpgmepp_export.h" 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | namespace GpgME 38 | { 39 | 40 | class Error; 41 | class InvalidRecipient; 42 | 43 | class GPGMEPP_EXPORT EncryptionResult : public Result 44 | { 45 | public: 46 | EncryptionResult(); 47 | EncryptionResult(gpgme_ctx_t ctx, int error); 48 | EncryptionResult(gpgme_ctx_t ctx, const Error &error); 49 | EncryptionResult(const Error &err); 50 | 51 | EncryptionResult(const EncryptionResult &other) = default; 52 | const EncryptionResult &operator=(EncryptionResult other) 53 | { 54 | swap(other); 55 | return *this; 56 | } 57 | 58 | void swap(EncryptionResult &other) 59 | { 60 | Result::swap(other); 61 | using std::swap; 62 | swap(this->d, other.d); 63 | } 64 | 65 | bool isNull() const; 66 | 67 | unsigned int numInvalidRecipients() const; 68 | 69 | InvalidRecipient invalidEncryptionKey(unsigned int index) const; 70 | std::vector invalidEncryptionKeys() const; 71 | 72 | class Private; 73 | private: 74 | void init(gpgme_ctx_t ctx); 75 | std::shared_ptr d; 76 | }; 77 | 78 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const EncryptionResult &result); 79 | 80 | class GPGMEPP_EXPORT InvalidRecipient 81 | { 82 | friend class ::GpgME::EncryptionResult; 83 | InvalidRecipient(const std::shared_ptr &parent, unsigned int index); 84 | public: 85 | InvalidRecipient(); 86 | 87 | InvalidRecipient(const InvalidRecipient &other) = default; 88 | const InvalidRecipient &operator=(InvalidRecipient other) 89 | { 90 | swap(other); 91 | return *this; 92 | } 93 | 94 | void swap(InvalidRecipient &other) 95 | { 96 | using std::swap; 97 | swap(this->d, other.d); 98 | } 99 | 100 | bool isNull() const; 101 | 102 | const char *fingerprint() const; 103 | Error reason() const; 104 | 105 | private: 106 | std::shared_ptr d; 107 | unsigned int idx; 108 | }; 109 | 110 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const InvalidRecipient &recipient); 111 | 112 | } 113 | 114 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(EncryptionResult) 115 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(InvalidRecipient) 116 | 117 | #endif // __GPGMEPP_ENCRYPTIONRESULT_H__ 118 | -------------------------------------------------------------------------------- /tests/t-utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | t-utils.cpp 3 | 4 | This file is part of GPGME++'s test suite. 5 | Copyright (c) 2025 g10 Code GmbH 6 | Software engineering by Ingo Klöcker 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include "config.h" 26 | #endif 27 | 28 | #include "global.h" 29 | #include "util.h" 30 | 31 | #include 32 | 33 | using namespace _gpgmepp; 34 | 35 | static void 36 | print_error_and_exit(std::string_view message, std::string_view file, int line) 37 | { 38 | std::cerr << file << ':' << line << ": " << message << std::endl; 39 | exit(1); 40 | } 41 | 42 | static void 43 | test_split_into_string_views() 44 | { 45 | { 46 | const auto result = split_into_string_views(nullptr, ','); 47 | if (!result.empty()) { 48 | print_error_and_exit("result not empty", __FILE__, __LINE__); 49 | } 50 | } 51 | { 52 | const auto result = split_into_string_views("", ','); 53 | if (!result.empty()) { 54 | print_error_and_exit("result not empty", __FILE__, __LINE__); 55 | } 56 | } 57 | { 58 | const auto result = split_into_string_views("abc", ','); 59 | if ((result.size() != 1) || (result[0] != "abc")) { 60 | print_error_and_exit("unexpected result", __FILE__, __LINE__); 61 | } 62 | } 63 | { 64 | const auto result = split_into_string_views("abc,def", ','); 65 | if ((result.size() != 2) || (result[0] != "abc") || (result[1] != "def")) { 66 | print_error_and_exit("unexpected result", __FILE__, __LINE__); 67 | } 68 | } 69 | { 70 | const auto result = split_into_string_views(",abc", ','); 71 | if ((result.size() != 1) || (result[0] != "abc")) { 72 | print_error_and_exit("unexpected result", __FILE__, __LINE__); 73 | } 74 | } 75 | { 76 | const auto result = split_into_string_views("abc,", ','); 77 | if ((result.size() != 1) || (result[0] != "abc")) { 78 | print_error_and_exit("unexpected result", __FILE__, __LINE__); 79 | } 80 | } 81 | { 82 | const auto result = split_into_string_views("abc,,def", ','); 83 | if ((result.size() != 2) || (result[0] != "abc") || (result[1] != "def")) { 84 | print_error_and_exit("unexpected result", __FILE__, __LINE__); 85 | } 86 | } 87 | { 88 | const auto result = split_into_string_views(",", ','); 89 | if (!result.empty()) { 90 | print_error_and_exit("result not empty", __FILE__, __LINE__); 91 | } 92 | } 93 | } 94 | 95 | int 96 | main (int argc, char **argv) 97 | { 98 | (void)argc; 99 | (void)argv; 100 | 101 | GpgME::initializeLibrary(); 102 | 103 | test_split_into_string_views(); 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /src/error.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | error.cpp - wraps a gpgme error 3 | Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB 4 | 2017, 2018 Intevation GmbH 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #include "error.h" 25 | 26 | #include 27 | 28 | #include 29 | 30 | using namespace GpgME; 31 | 32 | static void format_error(gpgme_error_t err, std::string &str) 33 | { 34 | char buffer[ 1024 ]; 35 | gpgme_strerror_r(err, buffer, sizeof buffer); 36 | buffer[ sizeof buffer - 1 ] = '\0'; 37 | str = buffer; 38 | } 39 | 40 | const char *Error::source() const 41 | { 42 | return gpgme_strsource((gpgme_error_t)mErr); 43 | } 44 | 45 | const char *Error::asString() const 46 | { 47 | if (mMessage.empty()) { 48 | format_error(static_cast(mErr), mMessage); 49 | } 50 | return mMessage.c_str(); 51 | } 52 | 53 | std::string Error::asStdString() const 54 | { 55 | std::string message; 56 | format_error(static_cast(mErr), message); 57 | return message; 58 | } 59 | 60 | int Error::code() const 61 | { 62 | return gpgme_err_code(mErr); 63 | } 64 | 65 | int Error::sourceID() const 66 | { 67 | return gpgme_err_source(mErr); 68 | } 69 | 70 | bool Error::isSuccess() const 71 | { 72 | return code() == GPG_ERR_NO_ERROR; 73 | } 74 | 75 | bool Error::isCanceled() const 76 | { 77 | return code() == GPG_ERR_CANCELED || code() == GPG_ERR_FULLY_CANCELED; 78 | } 79 | 80 | bool Error::isError() const 81 | { 82 | return !isSuccess() && !isCanceled(); 83 | } 84 | 85 | int Error::toErrno() const 86 | { 87 | return gpgme_err_code_to_errno(static_cast(code())); 88 | } 89 | 90 | // static 91 | bool Error::hasSystemError() 92 | { 93 | return gpgme_err_code_from_syserror() != GPG_ERR_MISSING_ERRNO ; 94 | } 95 | 96 | // static 97 | void Error::setSystemError(gpg_err_code_t err) 98 | { 99 | setErrno(gpgme_err_code_to_errno(err)); 100 | } 101 | 102 | // static 103 | void Error::setErrno(int err) 104 | { 105 | gpgme_err_set_errno(err); 106 | } 107 | 108 | // static 109 | Error Error::fromSystemError(unsigned int src) 110 | { 111 | return Error(gpgme_err_make(static_cast(src), gpgme_err_code_from_syserror())); 112 | } 113 | 114 | // static 115 | Error Error::fromErrno(int err, unsigned int src) 116 | { 117 | return Error(gpgme_err_make(static_cast(src), gpgme_err_code_from_errno(err))); 118 | } 119 | 120 | // static 121 | Error Error::fromCode(unsigned int err, unsigned int src) 122 | { 123 | return Error(gpgme_err_make(static_cast(src), static_cast(err))); 124 | } 125 | 126 | namespace GpgME { 127 | 128 | std::ostream &operator<<(std::ostream &os, const Error &err) 129 | { 130 | return os << "GpgME::Error(" << err.encodedError() << " (" << err.asStdString() << "))"; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /cmake/modules/G10AddGenChangeLogTarget.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2025 g10 Code GmbH 2 | # Software engineering by Ingo Klöcker 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions 6 | # are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | # 25 | # SPDX-License-Identifier: BSD-2-Clause 26 | 27 | #[=======================================================================[.rst: 28 | G10AddGenChangeLogTarget 29 | ------------------------ 30 | 31 | Add custom target ``gen-ChangeLog`` for generating a ChangeLog file. 32 | 33 | :: 34 | 35 | g10_add_gen_changelog_target( 36 | .. [SINCE ] 37 | .. [FOOTER ] 38 | ) 39 | 40 | # This function adds a custom target named ``gen-ChangeLog`` to the project 41 | # which can be used to generate a ChangeLog file from the commit log messages. 42 | # ``gitlog-to-changelog`` is used for generating the ChangeLog. It can be 43 | # found in the gnupg repository. 44 | # 45 | # If ``SINCE`` is given then its value is passed to ``git log`` to start the 46 | # ChangeLog at this date. 47 | # 48 | # If ``FOOTER`` is given then the content of the given file is appended to 49 | # the generated ChangeLog. 50 | #]=======================================================================] 51 | 52 | # save the location of the header template while CMAKE_CURRENT_LIST_DIR 53 | # has the value we want 54 | set(_G10_GENERATE_CHANGELOG_TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/g10_generate_ChangeLog.cmake.in") 55 | 56 | function(G10_ADD_GEN_CHANGELOG_TARGET) 57 | if(TARGET gen-ChangeLog) 58 | # gen-ChangeLog target is already defined 59 | return() 60 | endif() 61 | 62 | set(options) 63 | set(one_value_keywords SINCE FOOTER) 64 | set(multi_value_keywords) 65 | 66 | cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${one_value_keywords}" "${multi_value_keywords}") 67 | 68 | if(arg_UNPARSED_ARGUMENTS) 69 | message(FATAL_ERROR "Unknown keywords given to G10_ADD_GEN_CHANGELOG_TARGET(): \"${arg_UNPARSED_ARGUMENTS}\"") 70 | endif() 71 | 72 | if(arg_SINCE) 73 | set(changelog_since ${arg_SINCE}) 74 | endif() 75 | if(arg_FOOTER) 76 | set(changelog_footer ${arg_FOOTER}) 77 | endif() 78 | 79 | configure_file( 80 | "${_G10_GENERATE_CHANGELOG_TEMPLATE}" 81 | "${CMAKE_BINARY_DIR}/g10_generate_ChangeLog.cmake" 82 | IMMEDIATE 83 | @ONLY 84 | ) 85 | 86 | add_custom_target(gen-ChangeLog 87 | COMMENT "Generating ChangeLog..." 88 | COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/g10_generate_ChangeLog.cmake" 89 | WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" 90 | ) 91 | endfunction() 92 | -------------------------------------------------------------------------------- /src/decryptionresult.h: -------------------------------------------------------------------------------- 1 | /* 2 | decryptionresult.h - wraps a gpgme keygen result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_DECRYPTIONRESULT_H__ 26 | #define __GPGMEPP_DECRYPTIONRESULT_H__ 27 | 28 | #include "gpgmefw.h" 29 | #include "result.h" 30 | #include "gpgmepp_export.h" 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace GpgME 38 | { 39 | 40 | class Error; 41 | 42 | class GPGMEPP_EXPORT DecryptionResult : public Result 43 | { 44 | public: 45 | DecryptionResult(); 46 | DecryptionResult(gpgme_ctx_t ctx, int error); 47 | DecryptionResult(gpgme_ctx_t ctx, const Error &err); 48 | explicit DecryptionResult(const Error &err); 49 | 50 | DecryptionResult(const DecryptionResult &other) = default; 51 | const DecryptionResult &operator=(DecryptionResult other) 52 | { 53 | swap(other); 54 | return *this; 55 | } 56 | 57 | void swap(DecryptionResult &other) 58 | { 59 | Result::swap(other); 60 | using std::swap; 61 | swap(this->d, other.d); 62 | } 63 | 64 | bool isNull() const; 65 | 66 | const char *unsupportedAlgorithm() const; 67 | 68 | bool isWrongKeyUsage() const; 69 | bool isDeVs() const; 70 | bool isBetaCompliance() const; 71 | bool isMime() const; 72 | 73 | const char *fileName() const; 74 | 75 | const char *sessionKey() const; 76 | 77 | const char *symkeyAlgo() const; 78 | 79 | class Recipient; 80 | 81 | unsigned int numRecipients() const; 82 | Recipient recipient(unsigned int idx) const; 83 | std::vector recipients() const; 84 | 85 | bool isLegacyCipherNoMDC() const; 86 | 87 | private: 88 | class Private; 89 | void init(gpgme_ctx_t ctx); 90 | std::shared_ptr d; 91 | }; 92 | 93 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const DecryptionResult &result); 94 | 95 | class GPGMEPP_EXPORT DecryptionResult::Recipient 96 | { 97 | public: 98 | Recipient(); 99 | explicit Recipient(gpgme_recipient_t reci); 100 | 101 | Recipient(const Recipient &other) = default; 102 | const Recipient &operator=(Recipient other) 103 | { 104 | swap(other); 105 | return *this; 106 | } 107 | 108 | void swap(Recipient &other) 109 | { 110 | using std::swap; 111 | swap(this->d, other.d); 112 | } 113 | 114 | bool isNull() const; 115 | 116 | const char *keyID() const; 117 | const char *shortKeyID() const; 118 | 119 | unsigned int publicKeyAlgorithm() const; 120 | const char *publicKeyAlgorithmAsString() const; 121 | 122 | Error status() const; 123 | 124 | private: 125 | class Private; 126 | std::shared_ptr d; 127 | }; 128 | 129 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const DecryptionResult::Recipient &reci); 130 | 131 | } 132 | 133 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(DecryptionResult) 134 | 135 | #endif // __GPGMEPP_DECRYPTIONRESULT_H__ 136 | -------------------------------------------------------------------------------- /src/tofuinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | tofuinfo.h - wraps gpgme tofu info 3 | Copyright (C) 2016 by Bundesamt für Sicherheit in der Informationstechnik 4 | Software engineering by Intevation GmbH 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | 24 | #ifndef __GPGMEPP_TOFUINFO_H__ 25 | #define __GPGMEPP_TOFUINFO_H__ 26 | 27 | #include "gpgmepp_export.h" 28 | 29 | #include "global.h" 30 | 31 | #include 32 | 33 | namespace GpgME 34 | { 35 | 36 | class GPGMEPP_EXPORT TofuInfo 37 | { 38 | public: 39 | TofuInfo(); 40 | explicit TofuInfo(gpgme_tofu_info_t info); 41 | 42 | TofuInfo(const TofuInfo &other) = default; 43 | const TofuInfo &operator=(TofuInfo other) 44 | { 45 | swap(other); 46 | return *this; 47 | } 48 | 49 | void swap(TofuInfo &other) 50 | { 51 | using std::swap; 52 | swap(this->d, other.d); 53 | } 54 | 55 | bool isNull() const; 56 | 57 | /* @enum Validity 58 | * @brief The TOFU Validity. */ 59 | enum Validity : unsigned int { 60 | /*! Unknown (uninitialized).*/ 61 | ValidityUnknown, 62 | /*! TOFU Conflict.*/ 63 | Conflict, 64 | /*! Key without history.*/ 65 | NoHistory, 66 | /*! Key with too little history.*/ 67 | LittleHistory, 68 | /*! Key with enough history for basic trust.*/ 69 | BasicHistory, 70 | /*! Key with a lot of history.*/ 71 | LargeHistory, 72 | }; 73 | Validity validity() const; 74 | 75 | /* @enum Policy 76 | * @brief The TOFU Validity. */ 77 | enum Policy : unsigned int { 78 | /*! GPGME_TOFU_POLICY_NONE */ 79 | PolicyNone, 80 | /*! GPGME_TOFU_POLICY_AUTO */ 81 | PolicyAuto, 82 | /*! GPGME_TOFU_POLICY_GOOD */ 83 | PolicyGood, 84 | /*! GPGME_TOFU_POLICY_UNKNOWN */ 85 | PolicyUnknown, 86 | /*! GPGME_TOFU_POLICY_BAD */ 87 | PolicyBad, 88 | /*! GPGME_TOFU_POLICY_ASK */ 89 | PolicyAsk, 90 | }; 91 | Policy policy() const; 92 | 93 | /* Number of signatures seen for this binding. Capped at USHRT_MAX. */ 94 | unsigned short signCount() const; 95 | 96 | /* Number of encryption done to this binding. Capped at USHRT_MAX. */ 97 | unsigned short encrCount() const; 98 | 99 | /** Number of seconds since epoch when the first message was verified */ 100 | unsigned long signFirst() const; 101 | 102 | /** Number of seconds since epoch when the last message was verified */ 103 | unsigned long signLast() const; 104 | 105 | /** Number of seconds since epoch when the first message was encrypted */ 106 | unsigned long encrFirst() const; 107 | 108 | /** Number of seconds since epoch when the last message was encrypted */ 109 | unsigned long encrLast() const; 110 | 111 | /* If non-NULL a human readable string summarizing the TOFU data. */ 112 | const char *description() const; 113 | 114 | private: 115 | class Private; 116 | std::shared_ptr d; 117 | }; 118 | 119 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const TofuInfo &info); 120 | 121 | } // namespace GpgME 122 | 123 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(TofuInfo) 124 | #endif // __GPGMEPP_TOFUINFO_H__ 125 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | GPGME++ - C++ bindings/wrapper for GPGME 2 | ---------------------------------------- 3 | Based on KF5gpgmepp 4 | 5 | Overview 6 | -------- 7 | 8 | GPGME++ is a C++ wrapper (or C++ bindings) for the GnuPG project's 9 | GPGME (GnuPG Made Easy) library, version 0.4.4 and later. 10 | 11 | It is fairly complete, with some minor things still missing. 12 | 13 | The design principles of this library are as follows: 14 | 15 | 1. A value-based interface (most classes are implicitly shared) 16 | 2. Callbacks are replaced by C++ interfaces (classes with only 17 | abstract methods). 18 | 3. No exceptions are thrown 19 | 4. There is (as yet) no explicit support for multi-threaded use 20 | (other than what GPGME itself provides; most notably the 21 | refcounting for implicit sharing is not thread-safe) 22 | 5. To avoid binary incompatible interface changes, we make 23 | extensive use of the d-pointer pattern and avoid virtual 24 | methods; any polymorphism present is already provided by GPGME 25 | itself, anyway (see e.g. Data). A notable exception of the 26 | no-virtuals rule is the use of abstract classes to cover 27 | C-callbacks. 28 | 6. Use of STL containers for improved memory management and 29 | dealing with lists. 30 | 7. Complete abstraction of the C-API so "gpgme.h" should not 31 | be needed in your project using GPGME++. 32 | 8. Abstraction of GnuPG's edit-key interface by prepared 33 | EditInteractor classes. 34 | 35 | GPGME++ was originally developed as part of the KDEPIM community. 36 | 37 | Usage 38 | ----- 39 | 40 | The usage pattern of GPGME++ closely follows GPGMEs core usage 41 | pattern so the documentation for GPGME itself provides a good 42 | way to start. 43 | 44 | The context structure in GPGME is mapped to a Context object in 45 | GPGME++. Additional convenience code provides Data objects and 46 | a Dataprovider interface that can be used to implement GPGME's 47 | data with any subclass by implementing the right callbacks. 48 | 49 | EditInteractor subclasses provide ready to use classes for 50 | common --edit-key tasks. You can implement your own editinteractor 51 | classes by implementing the EditInteractor interface and using 52 | your subclass as an interactor in the edit function. 53 | 54 | Example to set the ownertrust of a key: 55 | 56 | /* Create an edit interactor */ 57 | EditInteractor *ei = new GpgSetOwnerTrustEditInteractor(Key::Ultimate); 58 | /* Obtain a Context */ 59 | Context *ctx = Context::createForProtocol(Protocol::OpenPGP); 60 | /* Create an in memory data object */ 61 | Data data; 62 | /* Start the edit on some key previously obtained. */ 63 | Error e = ctx->edit(key, std::unique_ptr(ei), data); 64 | /* Errors provide boolean comparison */ 65 | if (!e) 66 | ... 67 | /* Delete the context */ 68 | delete ctx; 69 | 70 | Examples / Tests 71 | ---------------- 72 | 73 | GPGME++ is tested through the Qt API. You can refer to the 74 | tests in QGpgME for examples of usage or refer to 75 | the actual QGpgME*Job.cpp implementations which rely 76 | on GPGME++ and should cover most use cases. 77 | 78 | A few examples for using the GPGME++ API directly can be found 79 | in the tests folder. 80 | 81 | Hacking 82 | ------- 83 | 84 | GPGME++ follows KDE Coding styles. See: 85 | https://community.kde.org/Policies/Frameworks_Coding_Style 86 | for more info. 87 | 88 | License 89 | ------- 90 | GPGME++ is free software; you can redistribute it and/or 91 | modify it under the terms of the GNU Library General Public 92 | License as published by the Free Software Foundation; either 93 | version 2 of the License, or (at your option) any later version. 94 | 95 | GPGME++ is distributed in the hope that it will be useful, 96 | but WITHOUT ANY WARRANTY; without even the implied warranty of 97 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 98 | GNU Library General Public License for more details. 99 | 100 | You should have received a copy of the GNU Library General Public License 101 | along with GPGME++; see the file COPYING.LIB. If not, write to the 102 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 103 | Boston, MA 02110-1301, USA. 104 | -------------------------------------------------------------------------------- /src/swdbresult.h: -------------------------------------------------------------------------------- 1 | /* 2 | swdbresult.h - wraps a gpgme swdb query / rsult 3 | Copyright (C) 2016 by Bundesamt für Sicherheit in der Informationstechnik 4 | Software engineering by Intevation GmbH 5 | 6 | This file is part of GPGME++. 7 | 8 | GPGME++ is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Library General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | GPGME++ is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Library General Public License for more details. 17 | 18 | You should have received a copy of the GNU Library General Public License 19 | along with GPGME++; see the file COPYING.LIB. If not, write to the 20 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 | Boston, MA 02110-1301, USA. 22 | */ 23 | #ifndef __GPGMEPP_SWDB_H__ 24 | #define __GPGMEPP_SWDB_H__ 25 | 26 | #include "gpgmepp_export.h" 27 | 28 | #include "global.h" 29 | #include "engineinfo.h" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace GpgME 37 | { 38 | 39 | class GPGMEPP_EXPORT SwdbResult 40 | { 41 | public: 42 | /* Obtain swdb results through query() */ 43 | SwdbResult(); 44 | explicit SwdbResult(gpgme_query_swdb_result_t result); 45 | 46 | /** Query the swdb to get information about updates. 47 | * 48 | * Runs gpgconf --query-swdb through gpgme and 49 | * returns a list of results. 50 | * If iversion is given as NULL a check is only done if GPGME 51 | * can figure out the version by itself (for example when using 52 | * "gpgme" or "gnupg"). 53 | * 54 | * If NULL is used for name the current gpgme version is 55 | * checked. 56 | * 57 | * @param name: Name of the component to query. 58 | * @param iversion: Optionally the installed version. 59 | * @param err: Optional error. 60 | */ 61 | static std::vector query(const char *name, 62 | const char *iversion = NULL, 63 | Error *err = NULL); 64 | 65 | SwdbResult(const SwdbResult &other) = default; 66 | const SwdbResult &operator=(SwdbResult other) 67 | { 68 | swap(other); 69 | return *this; 70 | } 71 | 72 | void swap(SwdbResult &other) 73 | { 74 | using std::swap; 75 | swap(this->d, other.d); 76 | } 77 | bool isNull() const; 78 | 79 | /* The name of the package (e.g. "gpgme", "gnupg") */ 80 | std::string name() const; 81 | 82 | /* The version of the installed version. */ 83 | EngineInfo::Version installedVersion() const; 84 | 85 | /* The time the online info was created. */ 86 | unsigned long created() const; 87 | 88 | /* The time the online info was retrieved. */ 89 | unsigned long retrieved() const; 90 | 91 | /* This bit is set if an error occurred or some of the information 92 | * in this structure may not be set. */ 93 | bool warning() const; 94 | 95 | /* An update is available. */ 96 | bool update() const; 97 | 98 | /* The update is important. */ 99 | bool urgent() const; 100 | 101 | /* No information at all available. */ 102 | bool noinfo() const; 103 | 104 | /* The package name is not known. */ 105 | bool unknown() const; 106 | 107 | /* The information here is too old. */ 108 | bool tooOld() const; 109 | 110 | /* Other error. */ 111 | bool error() const; 112 | 113 | /* The version of the latest released version. */ 114 | EngineInfo::Version version() const; 115 | 116 | /* The release date of that version. */ 117 | unsigned long releaseDate() const; 118 | 119 | private: 120 | class Private; 121 | std::shared_ptr d; 122 | }; 123 | 124 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const SwdbResult &info); 125 | 126 | } // namespace GpgME 127 | 128 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(SwdbResult) 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /src/gpgsetexpirytimeeditinteractor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | gpgsetexpirytimeeditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key 3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include "gpgsetexpirytimeeditinteractor.h" 30 | #include "error.h" 31 | 32 | #include 33 | 34 | #include 35 | 36 | using std::strcmp; 37 | 38 | // avoid conflict (msvc) 39 | #ifdef ERROR 40 | # undef ERROR 41 | #endif 42 | 43 | using namespace GpgME; 44 | 45 | GpgSetExpiryTimeEditInteractor::GpgSetExpiryTimeEditInteractor(const std::string &t) 46 | : EditInteractor(), 47 | m_strtime(t) 48 | { 49 | 50 | } 51 | 52 | GpgSetExpiryTimeEditInteractor::~GpgSetExpiryTimeEditInteractor() {} 53 | 54 | // work around --enable-final 55 | namespace GpgSetExpiryTimeEditInteractor_Private 56 | { 57 | enum { 58 | START = EditInteractor::StartState, 59 | COMMAND, 60 | DATE, 61 | QUIT, 62 | SAVE, 63 | 64 | ERROR = EditInteractor::ErrorState 65 | }; 66 | } 67 | 68 | const char *GpgSetExpiryTimeEditInteractor::action(Error &err) const 69 | { 70 | 71 | using namespace GpgSetExpiryTimeEditInteractor_Private; 72 | 73 | switch (state()) { 74 | case COMMAND: 75 | return "expire"; 76 | case DATE: 77 | return m_strtime.c_str(); 78 | case QUIT: 79 | return "quit"; 80 | case SAVE: 81 | return "Y"; 82 | case START: 83 | case ERROR: 84 | return nullptr; 85 | default: 86 | err = Error::fromCode(GPG_ERR_GENERAL); 87 | return nullptr; 88 | } 89 | } 90 | 91 | unsigned int GpgSetExpiryTimeEditInteractor::nextState(unsigned int status, const char *args, Error &err) const 92 | { 93 | 94 | static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); 95 | static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME); 96 | 97 | using namespace GpgSetExpiryTimeEditInteractor_Private; 98 | 99 | switch (state()) { 100 | case START: 101 | if (status == GPGME_STATUS_GET_LINE && 102 | strcmp(args, "keyedit.prompt") == 0) { 103 | return COMMAND; 104 | } 105 | err = GENERAL_ERROR; 106 | return ERROR; 107 | case COMMAND: 108 | if (status == GPGME_STATUS_GET_LINE && 109 | strcmp(args, "keygen.valid") == 0) { 110 | return DATE; 111 | } 112 | err = GENERAL_ERROR; 113 | return ERROR; 114 | case DATE: 115 | if (status == GPGME_STATUS_GET_LINE && 116 | strcmp(args, "keyedit.prompt") == 0) { 117 | return QUIT; 118 | } else if (status == GPGME_STATUS_GET_LINE && 119 | strcmp(args, "keygen.valid")) { 120 | err = INV_TIME_ERROR; 121 | return ERROR; 122 | } 123 | err = GENERAL_ERROR; 124 | return ERROR; 125 | case QUIT: 126 | if (status == GPGME_STATUS_GET_BOOL && 127 | strcmp(args, "keyedit.save.okay") == 0) { 128 | return SAVE; 129 | } 130 | err = GENERAL_ERROR; 131 | return ERROR; 132 | case ERROR: 133 | if (status == GPGME_STATUS_GET_LINE && 134 | strcmp(args, "keyedit.prompt") == 0) { 135 | return QUIT; 136 | } 137 | err = lastError(); 138 | return ERROR; 139 | default: 140 | err = GENERAL_ERROR; 141 | return ERROR; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/importresult.h: -------------------------------------------------------------------------------- 1 | /* 2 | importresult.h - wraps a gpgme import result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_IMPORTRESULT_H__ 26 | #define __GPGMEPP_IMPORTRESULT_H__ 27 | 28 | #include "gpgmefw.h" 29 | #include "result.h" 30 | #include "gpgmepp_export.h" 31 | 32 | #include 33 | 34 | #include 35 | 36 | namespace GpgME 37 | { 38 | 39 | class Error; 40 | class Import; 41 | 42 | class GPGMEPP_EXPORT ImportResult : public Result 43 | { 44 | public: 45 | ImportResult(); 46 | ImportResult(gpgme_ctx_t ctx, int error); 47 | ImportResult(gpgme_ctx_t ctx, const Error &error); 48 | explicit ImportResult(const Error &error); 49 | 50 | ImportResult(const ImportResult &other) = default; 51 | const ImportResult &operator=(ImportResult other) 52 | { 53 | swap(other); 54 | return *this; 55 | } 56 | 57 | void swap(ImportResult &other) 58 | { 59 | Result::swap(other); 60 | using std::swap; 61 | swap(this->d, other.d); 62 | } 63 | 64 | /** 65 | * Merges the result @p other into this result (and all of its copies). 66 | * 67 | * @note The merge algorithm assumes that @p other is the result of an 68 | * import that was performed after the import of this result. 69 | * @note Some numbers cannot be consolidated reliably, e.g. the number of 70 | * keys without user ID. 71 | */ 72 | void mergeWith(const ImportResult &other); 73 | 74 | bool isNull() const; 75 | 76 | int numConsidered() const; 77 | int numKeysWithoutUserID() const; 78 | int numImported() const; 79 | int numRSAImported() const; 80 | int numUnchanged() const; 81 | 82 | int newUserIDs() const; 83 | int newSubkeys() const; 84 | int newSignatures() const; 85 | int newRevocations() const; 86 | 87 | int numSecretKeysConsidered() const; 88 | int numSecretKeysImported() const; 89 | int numSecretKeysUnchanged() const; 90 | 91 | int notImported() const; 92 | int numV3KeysSkipped() const; 93 | 94 | Import import(unsigned int idx) const; 95 | std::vector imports() const; 96 | 97 | class Private; 98 | private: 99 | void init(gpgme_ctx_t ctx); 100 | std::shared_ptr d; 101 | }; 102 | 103 | class GPGMEPP_EXPORT Import 104 | { 105 | friend class ::GpgME::ImportResult; 106 | Import(const std::shared_ptr &parent, unsigned int idx); 107 | public: 108 | Import(); 109 | 110 | Import(const Import &other) = default; 111 | const Import &operator=(Import other) 112 | { 113 | swap(other); 114 | return *this; 115 | } 116 | 117 | void swap(Import &other) 118 | { 119 | using std::swap; 120 | swap(this->d, other.d); 121 | swap(this->idx, other.idx); 122 | } 123 | 124 | bool isNull() const; 125 | 126 | const char *fingerprint() const; 127 | Error error() const; 128 | 129 | enum Status { 130 | Unknown = 0x0, 131 | NewKey = 0x1, 132 | NewUserIDs = 0x2, 133 | NewSignatures = 0x4, 134 | NewSubkeys = 0x8, 135 | ContainedSecretKey = 0x10 136 | }; 137 | Status status() const; 138 | 139 | private: 140 | std::shared_ptr d; 141 | unsigned int idx; 142 | }; 143 | 144 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const ImportResult &irs); 145 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Import &imp); 146 | 147 | } // namespace GpgME 148 | 149 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(ImportResult) 150 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Import) 151 | 152 | #endif // __GPGMEPP_IMPORTRESULT_H__ 153 | -------------------------------------------------------------------------------- /src/scdgetinfoassuantransaction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | scdgetinfoassuantransaction.cpp - Assuan Transaction to get information from scdaemon 3 | Copyright (C) 2009 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include "scdgetinfoassuantransaction.h" 30 | #include "error.h" 31 | #include "data.h" 32 | #include "util.h" 33 | 34 | #include 35 | 36 | using namespace GpgME; 37 | 38 | ScdGetInfoAssuanTransaction::ScdGetInfoAssuanTransaction(InfoItem item) 39 | : AssuanTransaction(), 40 | m_item(item), 41 | m_command(), 42 | m_data() 43 | { 44 | 45 | } 46 | 47 | ScdGetInfoAssuanTransaction::~ScdGetInfoAssuanTransaction() {} 48 | 49 | static std::vector to_reader_list(const std::string &s) 50 | { 51 | std::vector result; 52 | std::stringstream ss(s); 53 | std::string tok; 54 | while (std::getline(ss, tok, '\n')) { 55 | result.push_back(tok); 56 | } 57 | return result; 58 | } 59 | 60 | static std::vector to_app_list(const std::string &s) 61 | { 62 | return to_reader_list(s); 63 | } 64 | 65 | std::string ScdGetInfoAssuanTransaction::version() const 66 | { 67 | if (m_item == Version) { 68 | return m_data; 69 | } else { 70 | return std::string(); 71 | } 72 | } 73 | 74 | unsigned int ScdGetInfoAssuanTransaction::pid() const 75 | { 76 | if (m_item == Pid) { 77 | return to_pid(m_data); 78 | } else { 79 | return 0U; 80 | } 81 | } 82 | 83 | std::string ScdGetInfoAssuanTransaction::socketName() const 84 | { 85 | if (m_item == SocketName) { 86 | return m_data; 87 | } else { 88 | return std::string(); 89 | } 90 | } 91 | 92 | char ScdGetInfoAssuanTransaction::status() const 93 | { 94 | if (m_item == Status && !m_data.empty()) { 95 | return m_data[0]; 96 | } else { 97 | return '\0'; 98 | } 99 | } 100 | 101 | std::vector ScdGetInfoAssuanTransaction::readerList() const 102 | { 103 | if (m_item == ReaderList) { 104 | return to_reader_list(m_data); 105 | } else { 106 | return std::vector(); 107 | } 108 | } 109 | 110 | std::vector ScdGetInfoAssuanTransaction::applicationList() const 111 | { 112 | if (m_item == ApplicationList) { 113 | return to_app_list(m_data); 114 | } else { 115 | return std::vector(); 116 | } 117 | } 118 | 119 | static const char *const scd_getinfo_tokens[] = { 120 | "version", 121 | "pid", 122 | "socket_name", 123 | "status", 124 | "reader_list", 125 | "deny_admin", 126 | "app_list", 127 | }; 128 | static_assert((sizeof scd_getinfo_tokens / sizeof * scd_getinfo_tokens == ScdGetInfoAssuanTransaction::LastInfoItem), 129 | "getinfo_tokens size mismatch"); 130 | 131 | void ScdGetInfoAssuanTransaction::makeCommand() const 132 | { 133 | assert(m_item >= 0); 134 | assert(m_item < LastInfoItem); 135 | m_command = "SCD GETINFO "; 136 | m_command += scd_getinfo_tokens[m_item]; 137 | } 138 | 139 | const char *ScdGetInfoAssuanTransaction::command() const 140 | { 141 | makeCommand(); 142 | return m_command.c_str(); 143 | } 144 | 145 | Error ScdGetInfoAssuanTransaction::data(const char *data, size_t len) 146 | { 147 | m_data.append(data, len); 148 | return Error(); 149 | } 150 | 151 | Data ScdGetInfoAssuanTransaction::inquire(const char *name, const char *args, Error &err) 152 | { 153 | (void)name; (void)args; (void)err; 154 | return Data::null; 155 | } 156 | 157 | Error ScdGetInfoAssuanTransaction::status(const char *status, const char *args) 158 | { 159 | (void)status; (void)args; 160 | return Error(); 161 | } 162 | -------------------------------------------------------------------------------- /cmake/modules/FindGpgme.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2025 g10 Code GmbH 2 | # Software engineering by Ingo Klöcker 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions 6 | # are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | # 25 | # SPDX-License-Identifier: BSD-2-Clause 26 | 27 | #[=======================================================================[.rst: 28 | FindGpgme 29 | --------------- 30 | 31 | Try to find the GpgME library. 32 | 33 | This will define the following variables: 34 | 35 | ``Gpgme_FOUND`` 36 | True if (the requested version of) GpgME was found 37 | ``Gpgme_VERSION`` 38 | The version of the GpgME library which was found 39 | ``Gpgme_LIBRARIES`` 40 | Libraries you need to link when using GpgME This can be passed to 41 | target_link_libraries() instead of the ``Gpgme::Gpgme`` target. 42 | ``Gpgme_INCLUDE_DIRS`` 43 | Include directories needed to use GpgME This should be passed to 44 | target_include_directories() if the target is not used for linking. 45 | ``Gpgme_DEFINITIONS`` 46 | Compile definitions to use when compiling code that uses GpgME 47 | This should be passed to target_compile_options() if the target is not 48 | used for linking. 49 | 50 | If ``Gpgme_FOUND`` is TRUE, it will also define the following imported target: 51 | 52 | ``Gpgme::Gpgme`` 53 | The GpgME library 54 | 55 | #]=======================================================================] 56 | 57 | find_package(PkgConfig QUIET) 58 | pkg_check_modules(PC_Gpgme QUIET gpgme) 59 | 60 | set(Gpgme_VERSION ${PC_Gpgme_VERSION}) 61 | set(Gpgme_DEFINITIONS ${PC_Gpgme_CFLAGS_OTHER}) 62 | 63 | find_path(Gpgme_INCLUDE_DIR 64 | NAMES 65 | gpgme.h 66 | HINTS 67 | ${PC_Gpgme_INCLUDE_DIRS} 68 | ) 69 | find_library(Gpgme_LIBRARY 70 | NAMES 71 | gpgme 72 | HINTS 73 | ${PC_Gpgme_LIBRARY_DIRS} 74 | ) 75 | 76 | if(Gpgme_INCLUDE_DIR AND NOT Gpgme_VERSION) 77 | # The version is given in the format MAJOR.MINOR.PATCH optionally followed 78 | # by an intermediate "beta" version given as -betaNUM, e.g. "1.24.2-beta7". 79 | file(STRINGS "${Gpgme_INCLUDE_DIR}/gpgme.h" Gpgme_VERSION_STR 80 | REGEX "^#[\t ]*define[\t ]+GPGME_VERSION[\t ]+\"([0-9])+\\.([0-9])+\\.([0-9])+(-[a-z0-9]*)?\".*") 81 | string(REGEX REPLACE "^.*GPGME_VERSION[\t ]+\"([0-9]+\\.[0-9]+\\.[0-9]+(-[a-z0-9]*)?)\".*$" 82 | "\\1" Gpgme_VERSION_STR "${Gpgme_VERSION_STR}") 83 | 84 | set(Gpgme_VERSION "${Gpgme_VERSION_STR}") 85 | 86 | unset(Gpgme_VERSION_STR) 87 | endif() 88 | 89 | include(FindPackageHandleStandardArgs) 90 | find_package_handle_standard_args(Gpgme 91 | REQUIRED_VARS 92 | Gpgme_LIBRARY 93 | Gpgme_INCLUDE_DIR 94 | Gpgme_VERSION 95 | VERSION_VAR 96 | Gpgme_VERSION 97 | ) 98 | 99 | if(Gpgme_FOUND AND NOT TARGET Gpgme::Gpgme) 100 | add_library(Gpgme::Gpgme UNKNOWN IMPORTED) 101 | set_target_properties(Gpgme::Gpgme PROPERTIES 102 | IMPORTED_LOCATION "${Gpgme_LIBRARY}" 103 | INTERFACE_COMPILE_OPTIONS "${Gpgme_DEFINITIONS}" 104 | INTERFACE_INCLUDE_DIRECTORIES "${Gpgme_INCLUDE_DIR}" 105 | ) 106 | endif() 107 | 108 | mark_as_advanced( 109 | Gpgme_INCLUDE_DIR 110 | Gpgme_LIBRARY 111 | ) 112 | 113 | if(Gpgme_FOUND) 114 | set(Gpgme_LIBRARIES ${Gpgme_LIBRARY}) 115 | set(Gpgme_INCLUDE_DIRS ${Gpgme_INCLUDE_DIR}) 116 | endif() 117 | 118 | include(FeatureSummary) 119 | set_package_properties(Gpgme PROPERTIES 120 | DESCRIPTION "Interface library for GnuPG" 121 | URL https://www.gnupg.org/software/gpgme/ 122 | ) 123 | -------------------------------------------------------------------------------- /src/data.h: -------------------------------------------------------------------------------- 1 | /* 2 | data.h - wraps a gpgme data object 3 | Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB 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 | #ifndef __GPGMEPP_DATA_H__ 24 | #define __GPGMEPP_DATA_H__ 25 | 26 | #include "global.h" 27 | #include "key.h" 28 | 29 | #include 30 | 31 | #include // unit64_t 32 | #include // FILE 33 | #include 34 | #include 35 | 36 | namespace GpgME 37 | { 38 | 39 | class DataProvider; 40 | class Error; 41 | 42 | class GPGMEPP_EXPORT Data 43 | { 44 | struct Null { 45 | Null() {} 46 | }; 47 | public: 48 | /* implicit */ Data(const Null &); 49 | Data(); 50 | explicit Data(gpgme_data_t data); 51 | 52 | // Memory-Based Data Buffers: 53 | Data(const char *buffer, size_t size, bool copy = true); 54 | explicit Data(const char *filename); 55 | #ifdef _WIN32 56 | Data(const char *filename, gpgme_off_t offset, size_t length); 57 | Data(std::FILE *fp, gpgme_off_t offset, size_t length); 58 | #else 59 | Data(const char *filename, off_t offset, size_t length); 60 | Data(std::FILE *fp, off_t offset, size_t length); 61 | #endif 62 | // File-Based Data Buffers: 63 | explicit Data(std::FILE *fp); 64 | explicit Data(int fd); 65 | // Callback-Based Data Buffers: 66 | explicit Data(DataProvider *provider); 67 | 68 | static const Null null; 69 | 70 | Data(const Data &other) = default; 71 | const Data &operator=(Data other) 72 | { 73 | swap(other); 74 | return *this; 75 | } 76 | 77 | void swap(Data &other) 78 | { 79 | using std::swap; 80 | swap(this->d, other.d); 81 | } 82 | 83 | bool isNull() const; 84 | 85 | enum Encoding { 86 | AutoEncoding, 87 | BinaryEncoding, 88 | Base64Encoding, 89 | ArmorEncoding, 90 | MimeEncoding, 91 | UrlEncoding, 92 | UrlEscEncoding, 93 | Url0Encoding, 94 | }; 95 | Encoding encoding() const; 96 | Error setEncoding(Encoding encoding); 97 | 98 | enum Type { 99 | Invalid, 100 | Unknown, 101 | PGPSigned, 102 | PGPOther, 103 | PGPKey, 104 | CMSSigned, 105 | CMSEncrypted, 106 | CMSOther, 107 | X509Cert, 108 | PKCS12, 109 | PGPEncrypted, 110 | PGPSignature, 111 | }; 112 | Type type() const; 113 | 114 | char *fileName() const; 115 | Error setFileName(const char *name); 116 | Error setFileName(const std::string &name); 117 | 118 | #ifdef _WIN32 119 | gpgme_ssize_t read(void *buffer, size_t length); 120 | gpgme_ssize_t write(const void *buffer, size_t length); 121 | gpgme_off_t seek(gpgme_off_t offset, int whence); 122 | #else 123 | ssize_t read(void *buffer, size_t length); 124 | ssize_t write(const void *buffer, size_t length); 125 | off_t seek(off_t offset, int whence); 126 | #endif 127 | 128 | /* Convenience function to do a seek (0, SEEK_SET). */ 129 | Error rewind(); 130 | 131 | /** Try to parse the data to a key object using the 132 | * Protocol proto. Returns an empty list on error.*/ 133 | std::vector toKeys(const Protocol proto = Protocol::OpenPGP) const; 134 | 135 | /** Return a copy of the data as std::string. Sets seek pos to 0 */ 136 | std::string toString(); 137 | 138 | /** See gpgme_data_set_flag */ 139 | Error setFlag(const char *name, const char *value); 140 | 141 | /** Set a size hint for this data e.g. for progress calculations. */ 142 | Error setSizeHint(uint64_t size); 143 | 144 | class Private; 145 | Private *impl() 146 | { 147 | return d.get(); 148 | } 149 | const Private *impl() const 150 | { 151 | return d.get(); 152 | } 153 | private: 154 | std::shared_ptr d; 155 | }; 156 | 157 | } 158 | 159 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Data) 160 | 161 | #endif // __GPGMEPP_DATA_H__ 162 | -------------------------------------------------------------------------------- /cmake/modules/G10GitHooks.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2023 Alexander Lohnau 2 | # Copyright 2022 Ahmad Samir 3 | # Copyright 2023 Johannes Zarl-Zierl 4 | # Copyright 2025 g10 Code GmbH 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions 8 | # are met: 9 | # 10 | # 1. Redistributions of source code must retain the copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 2. Redistributions in binary form must reproduce the copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 3. The name of the author may not be used to endorse or promote products 16 | # derived from this software without specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | # 29 | # SPDX-License-Identifier: BSD-3-Clause 30 | 31 | #[=======================================================================[.rst: 32 | G10GitHooks 33 | ----------- 34 | 35 | Configure the usual Git hooks for g10 Code projects. 36 | 37 | :: 38 | 39 | g10_configure_git_hooks() 40 | 41 | This function will enable the pre-commit.sample hook (e.g. to disallow trailing 42 | whitespace) and the commit-msg hook in build-aux. 43 | If a custom hooks directory is set via ``core.hooksPath``, a warning is issued. 44 | 45 | Example usage: 46 | 47 | .. code-block:: cmake 48 | 49 | include(G10GitHooks) 50 | g10_configure_git_hooks() 51 | 52 | Since 5.79 53 | #]=======================================================================] 54 | 55 | function(G10_CONFIGURE_GIT_HOOKS) 56 | set(_oneValueArgs "") 57 | set(_multiValueArgs CHECKS CUSTOM_SCRIPTS) 58 | cmake_parse_arguments(ARG "" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN}) 59 | 60 | if(NOT UNIX) 61 | return() 62 | endif() 63 | 64 | if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) 65 | message(STATUS "Project is not top level project - pre-commit hook not installed") 66 | return() 67 | endif() 68 | 69 | set(git_dir "${CMAKE_SOURCE_DIR}/.git") 70 | if (NOT IS_DIRECTORY ${git_dir}) 71 | # ignore secondary git work trees and tarballs 72 | return() 73 | endif() 74 | 75 | find_package(Git QUIET) 76 | if (NOT GIT_FOUND) 77 | return() 78 | endif() 79 | 80 | set(git_hooks_dir "${git_dir}/hooks") 81 | execute_process(COMMAND "${GIT_EXECUTABLE}" config --get core.hooksPath 82 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 83 | RESULT_VARIABLE _gitresult 84 | OUTPUT_VARIABLE _gitoutput 85 | ERROR_QUIET 86 | OUTPUT_STRIP_TRAILING_WHITESPACE) 87 | 88 | if(_gitresult EQUAL 0 AND NOT ${git_hooks_dir} EQUAL "${_gitoutput}") 89 | message(WARNING "Git is configured to use '${_gitoutput}' for hooks. The generated commit hooks will likely not be executed.") 90 | endif() 91 | 92 | if(EXISTS "${git_hooks_dir}/pre-commit.sample" AND NOT EXISTS "${git_hooks_dir}/pre-commit") 93 | message(STATUS 94 | "*** Activating trailing whitespace git pre-commit hook. ***\n" 95 | " To deactivate this pre-commit hook again move .git/hooks/pre-commit\n" 96 | " and .git/hooks/pre-commit.sample out of the way.") 97 | execute_process(COMMAND cp -p "${git_hooks_dir}/pre-commit.sample" "${git_hooks_dir}/pre-commit" 98 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") 99 | execute_process(COMMAND chmod +x "${git_hooks_dir}/pre-commit") 100 | endif() 101 | if(EXISTS "${CMAKE_SOURCE_DIR}/build-aux/git-hooks/commit-msg" AND NOT EXISTS "${git_hooks_dir}/commit-msg") 102 | message(STATUS "*** Activating commit log message check hook. ***") 103 | file(COPY "${CMAKE_SOURCE_DIR}/build-aux/git-hooks/commit-msg" 104 | DESTINATION "${git_hooks_dir}") 105 | execute_process(COMMAND chmod +x "${git_hooks_dir}/commit-msg") 106 | endif() 107 | endfunction() 108 | -------------------------------------------------------------------------------- /src/gpgsetownertrusteditinteractor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | gpgsetownertrusteditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key 3 | Copyright (C) 2007 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include "gpgsetownertrusteditinteractor.h" 30 | #include "error.h" 31 | 32 | #include 33 | 34 | #include 35 | 36 | using std::strcmp; 37 | 38 | // avoid conflict (msvc) 39 | #ifdef ERROR 40 | # undef ERROR 41 | #endif 42 | 43 | using namespace GpgME; 44 | 45 | GpgSetOwnerTrustEditInteractor::GpgSetOwnerTrustEditInteractor(Key::OwnerTrust ot) 46 | : EditInteractor(), 47 | m_ownertrust(ot) 48 | { 49 | 50 | } 51 | 52 | GpgSetOwnerTrustEditInteractor::~GpgSetOwnerTrustEditInteractor() {} 53 | 54 | // work around --enable-final 55 | namespace GpgSetOwnerTrustEditInteractor_Private 56 | { 57 | enum { 58 | START = EditInteractor::StartState, 59 | COMMAND, 60 | VALUE, 61 | REALLY_ULTIMATE, 62 | QUIT, 63 | SAVE, 64 | 65 | ERROR = EditInteractor::ErrorState 66 | }; 67 | } 68 | 69 | const char *GpgSetOwnerTrustEditInteractor::action(Error &err) const 70 | { 71 | static const char truststrings[][2] = { "1", "1", "2", "3", "4", "5" }; 72 | 73 | using namespace GpgSetOwnerTrustEditInteractor_Private; 74 | 75 | switch (state()) { 76 | case COMMAND: 77 | return "trust"; 78 | case VALUE: 79 | return truststrings[m_ownertrust]; 80 | case REALLY_ULTIMATE: 81 | return "Y"; 82 | case QUIT: 83 | return "quit"; 84 | case SAVE: 85 | return "Y"; 86 | case START: 87 | case ERROR: 88 | return nullptr; 89 | default: 90 | err = Error::fromCode(GPG_ERR_GENERAL); 91 | return nullptr; 92 | } 93 | } 94 | 95 | unsigned int GpgSetOwnerTrustEditInteractor::nextState(unsigned int status, const char *args, Error &err) const 96 | { 97 | 98 | static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); 99 | //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME ); 100 | 101 | using namespace GpgSetOwnerTrustEditInteractor_Private; 102 | 103 | switch (state()) { 104 | case START: 105 | if (status == GPGME_STATUS_GET_LINE && 106 | strcmp(args, "keyedit.prompt") == 0) { 107 | return COMMAND; 108 | } 109 | err = GENERAL_ERROR; 110 | return ERROR; 111 | case COMMAND: 112 | if (status == GPGME_STATUS_GET_LINE && 113 | strcmp(args, "edit_ownertrust.value") == 0) { 114 | return VALUE; 115 | } 116 | err = GENERAL_ERROR; 117 | return ERROR; 118 | case VALUE: 119 | if (status == GPGME_STATUS_GET_LINE && 120 | strcmp(args, "keyedit.prompt") == 0) { 121 | return QUIT; 122 | } else if (status == GPGME_STATUS_GET_BOOL && 123 | strcmp(args, "edit_ownertrust.set_ultimate.okay") == 0) { 124 | return REALLY_ULTIMATE; 125 | } 126 | err = GENERAL_ERROR; 127 | return ERROR; 128 | case REALLY_ULTIMATE: 129 | if (status == GPGME_STATUS_GET_LINE && 130 | strcmp(args, "keyedit.prompt") == 0) { 131 | return QUIT; 132 | } 133 | err = GENERAL_ERROR; 134 | return ERROR; 135 | case QUIT: 136 | if (status == GPGME_STATUS_GET_BOOL && 137 | strcmp(args, "keyedit.save.okay") == 0) { 138 | return SAVE; 139 | } 140 | err = GENERAL_ERROR; 141 | return ERROR; 142 | case ERROR: 143 | if (status == GPGME_STATUS_GET_LINE && 144 | strcmp(args, "keyedit.prompt") == 0) { 145 | return QUIT; 146 | } 147 | err = lastError(); 148 | return ERROR; 149 | default: 150 | err = GENERAL_ERROR; 151 | return ERROR; 152 | }; 153 | } 154 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeLists.txt for GpgME++ 2 | # Copyright 2025 g10 Code GmbH 3 | # Software engineering by Carl Schwan 4 | # Software engineering by Ingo Klöcker 5 | # 6 | # This file is part of GPGME++. 7 | # 8 | # GPGME++ is free software; you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as 10 | # published by the Free Software Foundation; either version 2.1 of the 11 | # License, or (at your option) any later version. 12 | # 13 | # GPGME++ is distributed in the hope that it will be useful, but WITHOUT 14 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 16 | # Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with this program; if not, see . 20 | # SPDX-License-Identifier: LGPL-2.1-or-later 21 | 22 | cmake_minimum_required(VERSION 3.16 FATAL_ERROR) 23 | 24 | set(FULL_VERSION "2.0.1") 25 | 26 | string(REGEX MATCH "^[0-9]+.[0-9]+.[0-9]+" cmake_compat_version ${FULL_VERSION}) 27 | project(gpgmepp VERSION ${cmake_compat_version}) 28 | 29 | set(VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) 30 | set(VERSION_MINOR ${PROJECT_VERSION_MINOR}) 31 | set(VERSION_MICRO ${PROJECT_VERSION_PATCH}) 32 | 33 | # LT Version numbers, remember to change them just *before* a release. 34 | # (Code changed: REVISION++) 35 | # (Interfaces added/removed/changed: CURRENT++, REVISION=0) 36 | # (Interfaces added: AGE++) 37 | # (Interfaces removed: AGE=0) 38 | set(LIBGPGMEPP_LT_CURRENT "7") 39 | set(LIBGPGMEPP_LT_AGE "0") 40 | set(LIBGPGMEPP_LT_REVISION "0") 41 | math(EXPR LIBGPGMEPP_SOVERSION "${LIBGPGMEPP_LT_CURRENT} - ${LIBGPGMEPP_LT_AGE}") 42 | 43 | set(GPG_ERROR_REQUIRED_VERSION "1.47") 44 | set(GPGME_REQUIRED_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.0") 45 | 46 | option(ENABLE_SHARED "Build shared libraries" ON) 47 | option(ENABLE_STATIC "Build static libraries" OFF) 48 | # The following option is used in gpg4win to distinguish the 32-bit build from 49 | # the 64-bit build 50 | option(PKGCONFIG_HOST "The host value to write in the pkgconfig file" "") 51 | option(CONFIGURE_FOR_DISTRIBUTION "Configure only for `make dist`, etc., ignoring required dependencies" OFF) 52 | 53 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) 54 | 55 | include(G10CMakeSettings) 56 | 57 | include(G10AddDistTargets) 58 | include(G10AddGenChangeLogTarget) 59 | include(G10AddReleaseTargets) 60 | include(G10CompilerSettings) 61 | include(G10GetFullVersion) 62 | include(ECMUninstallTarget) 63 | include(FeatureSummary) 64 | include(GNUInstallDirs) 65 | 66 | find_package(LibGpgError ${GPG_ERROR_REQUIRED_VERSION}) 67 | find_package(Gpgme ${GPGME_REQUIRED_VERSION}) 68 | if (CONFIGURE_FOR_DISTRIBUTION) 69 | message(WARNING "Configuring only for running `make dist`, etc., ignoring required dependencies") 70 | else() 71 | set_package_properties(LibGpgError PROPERTIES TYPE REQUIRED) 72 | set_package_properties(Gpgme PROPERTIES TYPE REQUIRED) 73 | endif() 74 | 75 | g10_get_full_version() 76 | 77 | # create the VERSION file 78 | find_package(Git QUIET) 79 | if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") 80 | # get the current commit ID 81 | execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --verify HEAD 82 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 83 | OUTPUT_VARIABLE commit_id 84 | ) 85 | string(STRIP "${commit_id}" commit_id) # strip trailing whitespace 86 | file(WRITE "${CMAKE_BINARY_DIR}/VERSION" "${G10_FULL_VERSION}\n${commit_id}\n") 87 | elseif(EXISTS "${CMAKE_SOURCE_DIR}/VERSION") 88 | configure_file("${CMAKE_SOURCE_DIR}/VERSION" "VERSION" COPYONLY) 89 | else() 90 | file(WRITE "${CMAKE_BINARY_DIR}/VERSION" "${G10_FULL_VERSION}\nunknown\n") 91 | endif() 92 | 93 | if(UNIX) 94 | # start ChangeLog at import from KDE in gpgme repo 95 | g10_add_gen_changelog_target( 96 | SINCE "2016-03-08T00:00:00" 97 | FOOTER "${CMAKE_SOURCE_DIR}/build-aux/git-log-footer" 98 | ) 99 | 100 | set(EXTRA_DIST 101 | "${CMAKE_BINARY_DIR}/ChangeLog" 102 | "${CMAKE_BINARY_DIR}/VERSION" 103 | ) 104 | g10_add_dist_targets( 105 | VERSION "${G10_FULL_VERSION}" 106 | ARCHIVE_FORMAT "tar.xz" 107 | EXTRA_FILES ${EXTRA_DIST} 108 | ) 109 | add_dependencies(dist gen-ChangeLog) 110 | 111 | g10_add_release_targets( 112 | VERSION "${G10_FULL_VERSION}" 113 | ARCHIVE_FORMAT "tar.xz" 114 | RELEASE_ARCHIVE_SUFFIX "gpgme" 115 | ) 116 | endif() 117 | 118 | include(G10GitHooks) 119 | g10_configure_git_hooks() 120 | 121 | if (LibGpgError_FOUND AND Gpgme_FOUND) 122 | add_subdirectory(src) 123 | 124 | if(BUILD_TESTING AND ENABLE_SHARED) 125 | add_subdirectory(tests) 126 | endif() 127 | endif() 128 | 129 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) 130 | -------------------------------------------------------------------------------- /src/signingresult.h: -------------------------------------------------------------------------------- 1 | /* 2 | signingresult.h - wraps a gpgme sign result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifndef __GPGMEPP_SIGNINGRESULT_H__ 26 | #define __GPGMEPP_SIGNINGRESULT_H__ 27 | 28 | #include "global.h" 29 | #include "result.h" 30 | 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | namespace GpgME 39 | { 40 | 41 | class Error; 42 | class CreatedSignature; 43 | class InvalidSigningKey; 44 | 45 | class GPGMEPP_EXPORT SigningResult : public Result 46 | { 47 | public: 48 | SigningResult(); 49 | SigningResult(gpgme_ctx_t ctx, int error); 50 | SigningResult(gpgme_ctx_t ctx, const Error &error); 51 | explicit SigningResult(const Error &err); 52 | 53 | SigningResult(const SigningResult &other) = default; 54 | const SigningResult &operator=(SigningResult other) 55 | { 56 | swap(other); 57 | return *this; 58 | } 59 | 60 | void swap(SigningResult &other) 61 | { 62 | Result::swap(other); 63 | using std::swap; 64 | swap(this->d, other.d); 65 | } 66 | 67 | bool isNull() const; 68 | 69 | CreatedSignature createdSignature(unsigned int index) const; 70 | std::vector createdSignatures() const; 71 | 72 | InvalidSigningKey invalidSigningKey(unsigned int index) const; 73 | std::vector invalidSigningKeys() const; 74 | 75 | class Private; 76 | private: 77 | void init(gpgme_ctx_t ctx); 78 | std::shared_ptr d; 79 | }; 80 | 81 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const SigningResult &result); 82 | 83 | class GPGMEPP_EXPORT InvalidSigningKey 84 | { 85 | friend class ::GpgME::SigningResult; 86 | InvalidSigningKey(const std::shared_ptr &parent, unsigned int index); 87 | public: 88 | InvalidSigningKey(); 89 | 90 | InvalidSigningKey(const InvalidSigningKey &other) = default; 91 | const InvalidSigningKey &operator=(InvalidSigningKey other) 92 | { 93 | swap(other); 94 | return *this; 95 | } 96 | 97 | void swap(InvalidSigningKey &other) 98 | { 99 | using std::swap; 100 | swap(this->d, other.d); 101 | swap(this->idx, other.idx); 102 | } 103 | 104 | bool isNull() const; 105 | 106 | const char *fingerprint() const; 107 | Error reason() const; 108 | 109 | private: 110 | std::shared_ptr d; 111 | unsigned int idx; 112 | }; 113 | 114 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const InvalidSigningKey &key); 115 | 116 | class GPGMEPP_EXPORT CreatedSignature 117 | { 118 | friend class ::GpgME::SigningResult; 119 | CreatedSignature(const std::shared_ptr &parent, unsigned int index); 120 | public: 121 | 122 | CreatedSignature(); 123 | 124 | CreatedSignature(const CreatedSignature &other) = default; 125 | const CreatedSignature &operator=(CreatedSignature other) 126 | { 127 | swap(other); 128 | return *this; 129 | } 130 | 131 | void swap(CreatedSignature &other) 132 | { 133 | using std::swap; 134 | swap(this->d, other.d); 135 | swap(this->idx, other.idx); 136 | } 137 | 138 | bool isNull() const; 139 | 140 | const char *fingerprint() const; 141 | 142 | time_t creationTime() const; 143 | 144 | SignatureMode mode() const; 145 | 146 | unsigned int publicKeyAlgorithm() const; 147 | const char *publicKeyAlgorithmAsString() const; 148 | 149 | unsigned int hashAlgorithm() const; 150 | const char *hashAlgorithmAsString() const; 151 | 152 | unsigned int signatureClass() const; 153 | 154 | private: 155 | std::shared_ptr d; 156 | unsigned int idx; 157 | }; 158 | 159 | GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const CreatedSignature &sig); 160 | 161 | } 162 | 163 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(SigningResult) 164 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(InvalidSigningKey) 165 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(CreatedSignature) 166 | 167 | #endif // __GPGMEPP_SIGNINGRESULT_H__ 168 | -------------------------------------------------------------------------------- /cmake/modules/FindLibGpgError.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2022 g10 Code GmbH 2 | # Software engineering by Ingo Klöcker 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions 6 | # are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | # 25 | # SPDX-License-Identifier: BSD-2-Clause 26 | 27 | #[=======================================================================[.rst: 28 | FindLibGpgError 29 | --------------- 30 | 31 | Try to find the Libgpg-error library. 32 | 33 | This will define the following variables: 34 | 35 | ``LibGpgError_FOUND`` 36 | True if (the requested version of) Libgpg-error was found 37 | ``LibGpgError_VERSION`` 38 | The version of the Libgpg-error library which was found 39 | ``LibGpgError_LIBRARIES`` 40 | Libraries you need to link when using Libgpg-error This can be passed to 41 | target_link_libraries() instead of the ``LibGpgError::LibGpgError`` target. 42 | ``LibGpgError_INCLUDE_DIRS`` 43 | Include directories needed to use Libgpg-error This should be passed to 44 | target_include_directories() if the target is not used for linking. 45 | ``LibGpgError_DEFINITIONS`` 46 | Compile definitions to use when compiling code that uses Libgpg-error 47 | This should be passed to target_compile_options() if the target is not 48 | used for linking. 49 | 50 | If ``LibGpgError_FOUND`` is TRUE, it will also define the following imported target: 51 | 52 | ``LibGpgError::LibGpgError`` 53 | The Libgpg-error library 54 | 55 | #]=======================================================================] 56 | 57 | find_package(PkgConfig QUIET) 58 | pkg_check_modules(PC_LibGpgError QUIET gpg-error) 59 | 60 | set(LibGpgError_VERSION ${PC_LibGpgError_VERSION}) 61 | set(LibGpgError_DEFINITIONS ${PC_LibGpgError_CFLAGS_OTHER}) 62 | 63 | find_path(LibGpgError_INCLUDE_DIR 64 | NAMES 65 | gpg-error.h 66 | HINTS 67 | ${PC_LibGpgError_INCLUDE_DIRS} 68 | ) 69 | find_library(LibGpgError_LIBRARY 70 | NAMES 71 | gpg-error 72 | HINTS 73 | ${PC_LibGpgError_LIBRARY_DIRS} 74 | ) 75 | 76 | if(LibGpgError_INCLUDE_DIR AND NOT LibGpgError_VERSION) 77 | # The version is given in the format MAJOR.MINOR optionally followed 78 | # by an intermediate "beta" version given as -betaNUM, e.g. "1.47-beta7". 79 | file(STRINGS "${LibGpgError_INCLUDE_DIR}/gpg-error.h" LibGpgError_VERSION_STR 80 | REGEX "^#[\t ]*define[\t ]+GPG_ERROR_VERSION[\t ]+\"([0-9])+\\.([0-9])+(-[a-z0-9]*)?\".*") 81 | string(REGEX REPLACE "^.*GPG_ERROR_VERSION[\t ]+\"([0-9]+\\.[0-9]+(-[a-z0-9]*)?)\".*$" 82 | "\\1" LibGpgError_VERSION_STR "${LibGpgError_VERSION_STR}") 83 | 84 | set(LibGpgError_VERSION "${LibGpgError_VERSION_STR}") 85 | 86 | unset(LibGpgError_VERSION_STR) 87 | endif() 88 | 89 | include(FindPackageHandleStandardArgs) 90 | find_package_handle_standard_args(LibGpgError 91 | REQUIRED_VARS 92 | LibGpgError_LIBRARY 93 | LibGpgError_INCLUDE_DIR 94 | LibGpgError_VERSION 95 | VERSION_VAR 96 | LibGpgError_VERSION 97 | ) 98 | 99 | if(LibGpgError_FOUND AND NOT TARGET LibGpgError::LibGpgError) 100 | add_library(LibGpgError::LibGpgError UNKNOWN IMPORTED) 101 | set_target_properties(LibGpgError::LibGpgError PROPERTIES 102 | IMPORTED_LOCATION "${LibGpgError_LIBRARY}" 103 | INTERFACE_COMPILE_OPTIONS "${LibGpgError_DEFINITIONS}" 104 | INTERFACE_INCLUDE_DIRECTORIES "${LibGpgError_INCLUDE_DIR}" 105 | ) 106 | endif() 107 | 108 | mark_as_advanced( 109 | LibGpgError_INCLUDE_DIR 110 | LibGpgError_LIBRARY 111 | ) 112 | 113 | if(LibGpgError_FOUND) 114 | set(LibGpgError_LIBRARIES ${LibGpgError_LIBRARY}) 115 | set(LibGpgError_INCLUDE_DIRS ${LibGpgError_INCLUDE_DIR}) 116 | endif() 117 | 118 | include(FeatureSummary) 119 | set_package_properties(LibGpgError PROPERTIES 120 | DESCRIPTION "Runtime library for all GnuPG components" 121 | URL https://www.gnupg.org/software/libgpg-error 122 | ) 123 | -------------------------------------------------------------------------------- /src/tofuinfo.cpp: -------------------------------------------------------------------------------- 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 30 | #include "util.h" 31 | 32 | class GpgME::TofuInfo::Private 33 | { 34 | public: 35 | Private() {} 36 | Private(gpgme_tofu_info_t info) 37 | : mInfo(info ? new _gpgme_tofu_info(*info) : nullptr) 38 | { 39 | if (mInfo && mInfo->description) { 40 | mInfo->description = strdup(mInfo->description); 41 | } 42 | } 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 | ~Private() 53 | { 54 | if (mInfo) { 55 | std::free(mInfo->description); 56 | mInfo->description = nullptr; 57 | 58 | delete mInfo; 59 | } 60 | } 61 | 62 | gpgme_tofu_info_t mInfo; 63 | }; 64 | 65 | GpgME::TofuInfo::TofuInfo(gpgme_tofu_info_t info) 66 | : d(new Private(info)) 67 | { 68 | } 69 | 70 | GpgME::TofuInfo::TofuInfo() : d() 71 | { 72 | } 73 | 74 | bool GpgME::TofuInfo::isNull() const 75 | { 76 | return !d || !d->mInfo; 77 | } 78 | 79 | GpgME::TofuInfo::Validity GpgME::TofuInfo::validity() const 80 | { 81 | if (isNull()) { 82 | return ValidityUnknown; 83 | } 84 | switch (d->mInfo->validity) { 85 | case 0: 86 | return Conflict; 87 | case 1: 88 | return NoHistory; 89 | case 2: 90 | return LittleHistory; 91 | case 3: 92 | return BasicHistory; 93 | case 4: 94 | return LargeHistory; 95 | default: 96 | return ValidityUnknown; 97 | } 98 | } 99 | 100 | GpgME::TofuInfo::Policy GpgME::TofuInfo::policy() const 101 | { 102 | if (isNull()) { 103 | return PolicyUnknown; 104 | } 105 | switch (d->mInfo->policy) { 106 | case GPGME_TOFU_POLICY_NONE: 107 | return PolicyNone; 108 | case GPGME_TOFU_POLICY_AUTO: 109 | return PolicyAuto; 110 | case GPGME_TOFU_POLICY_GOOD: 111 | return PolicyGood; 112 | case GPGME_TOFU_POLICY_BAD: 113 | return PolicyBad; 114 | case GPGME_TOFU_POLICY_ASK: 115 | return PolicyAsk; 116 | case GPGME_TOFU_POLICY_UNKNOWN: 117 | default: 118 | return PolicyUnknown; 119 | } 120 | } 121 | 122 | const char *GpgME::TofuInfo::description() const 123 | { 124 | return isNull() ? nullptr : d->mInfo->description; 125 | } 126 | 127 | unsigned short GpgME::TofuInfo::signCount() const 128 | { 129 | return isNull() ? 0 : d->mInfo->signcount; 130 | } 131 | 132 | unsigned short GpgME::TofuInfo::encrCount() const 133 | { 134 | return isNull() ? 0 : d->mInfo->encrcount; 135 | } 136 | 137 | unsigned long GpgME::TofuInfo::signFirst() const 138 | { 139 | return isNull() ? 0 : d->mInfo->signfirst; 140 | } 141 | 142 | unsigned long GpgME::TofuInfo::signLast() const 143 | { 144 | return isNull() ? 0 : d->mInfo->signlast; 145 | } 146 | 147 | unsigned long GpgME::TofuInfo::encrFirst() const 148 | { 149 | return isNull() ? 0 : d->mInfo->encrfirst; 150 | } 151 | 152 | unsigned long GpgME::TofuInfo::encrLast() const 153 | { 154 | return isNull() ? 0 : d->mInfo->encrlast; 155 | } 156 | 157 | std::ostream &GpgME::operator<<(std::ostream &os, const GpgME::TofuInfo &info) 158 | { 159 | os << "GpgME::Signature::TofuInfo("; 160 | if (!info.isNull()) { 161 | os << "\n desc: " << protect(info.description()) 162 | << "\n validity: " << info.validity() 163 | << "\n policy: " << info.policy() 164 | << "\n signcount: "<< info.signCount() 165 | << "\n signfirst: "<< info.signFirst() 166 | << "\n signlast: " << info.signLast() 167 | << "\n encrcount: "<< info.encrCount() 168 | << "\n encrfirst: "<< info.encrFirst() 169 | << "\n encrlast: " << info.encrLast() 170 | << '\n'; 171 | } 172 | return os << ")"; 173 | } 174 | -------------------------------------------------------------------------------- /src/encryptionresult.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | encryptionresult.cpp - wraps a gpgme verify result 3 | Copyright (C) 2004 Klarälvdalens Datakonsult AB 4 | 2016 Bundesamt für Sicherheit in der Informationstechnik 5 | Software engineering by Intevation GmbH 6 | 7 | This file is part of GPGME++. 8 | 9 | GPGME++ is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Library General Public 11 | License as published by the Free Software Foundation; either 12 | version 2 of the License, or (at your option) any later version. 13 | 14 | GPGME++ is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU Library General Public License 20 | along with GPGME++; see the file COPYING.LIB. If not, write to the 21 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | Boston, MA 02110-1301, USA. 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include 30 | #include "result_p.h" 31 | #include "util.h" 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | 43 | class GpgME::EncryptionResult::Private 44 | { 45 | public: 46 | explicit Private(const gpgme_encrypt_result_t r) 47 | { 48 | if (!r) { 49 | return; 50 | } 51 | for (gpgme_invalid_key_t ik = r->invalid_recipients ; ik ; ik = ik->next) { 52 | gpgme_invalid_key_t copy = new _gpgme_invalid_key(*ik); 53 | if (ik->fpr) { 54 | copy->fpr = strdup(ik->fpr); 55 | } 56 | copy->next = nullptr; 57 | invalid.push_back(copy); 58 | } 59 | } 60 | ~Private() 61 | { 62 | for (std::vector::iterator it = invalid.begin() ; it != invalid.end() ; ++it) { 63 | std::free((*it)->fpr); 64 | delete *it; *it = nullptr; 65 | } 66 | } 67 | 68 | std::vector invalid; 69 | }; 70 | 71 | GpgME::EncryptionResult::EncryptionResult(gpgme_ctx_t ctx, int error) 72 | : GpgME::Result(error), d() 73 | { 74 | init(ctx); 75 | } 76 | 77 | GpgME::EncryptionResult::EncryptionResult(gpgme_ctx_t ctx, const Error &error) 78 | : GpgME::Result(error), d() 79 | { 80 | init(ctx); 81 | } 82 | 83 | void GpgME::EncryptionResult::init(gpgme_ctx_t ctx) 84 | { 85 | if (!ctx) { 86 | return; 87 | } 88 | gpgme_encrypt_result_t res = gpgme_op_encrypt_result(ctx); 89 | if (!res) { 90 | return; 91 | } 92 | d.reset(new Private(res)); 93 | } 94 | 95 | make_standard_stuff(EncryptionResult) 96 | 97 | unsigned int GpgME::EncryptionResult::numInvalidRecipients() const 98 | { 99 | return d ? d->invalid.size() : 0 ; 100 | } 101 | 102 | GpgME::InvalidRecipient GpgME::EncryptionResult::invalidEncryptionKey(unsigned int idx) const 103 | { 104 | return InvalidRecipient(d, idx); 105 | } 106 | 107 | std::vector GpgME::EncryptionResult::invalidEncryptionKeys() const 108 | { 109 | if (!d) { 110 | return std::vector(); 111 | } 112 | std::vector result; 113 | result.reserve(d->invalid.size()); 114 | for (unsigned int i = 0 ; i < d->invalid.size() ; ++i) { 115 | result.push_back(InvalidRecipient(d, i)); 116 | } 117 | return result; 118 | } 119 | 120 | GpgME::InvalidRecipient::InvalidRecipient(const std::shared_ptr &parent, unsigned int i) 121 | : d(parent), idx(i) 122 | { 123 | 124 | } 125 | 126 | GpgME::InvalidRecipient::InvalidRecipient() : d(), idx(0) {} 127 | 128 | bool GpgME::InvalidRecipient::isNull() const 129 | { 130 | return !d || idx >= d->invalid.size() ; 131 | } 132 | 133 | const char *GpgME::InvalidRecipient::fingerprint() const 134 | { 135 | return isNull() ? nullptr : d->invalid[idx]->fpr ; 136 | } 137 | 138 | GpgME::Error GpgME::InvalidRecipient::reason() const 139 | { 140 | return Error(isNull() ? 0 : d->invalid[idx]->reason); 141 | } 142 | 143 | std::ostream &GpgME::operator<<(std::ostream &os, const EncryptionResult &result) 144 | { 145 | os << "GpgME::EncryptionResult("; 146 | if (!result.isNull()) { 147 | os << "\n error: " << result.error() 148 | << "\n invalid recipients:\n"; 149 | const std::vector ir = result.invalidEncryptionKeys(); 150 | std::copy(ir.begin(), ir.end(), 151 | std::ostream_iterator(os, "\n")); 152 | } 153 | return os << ')'; 154 | } 155 | 156 | std::ostream &GpgME::operator<<(std::ostream &os, const InvalidRecipient &ir) 157 | { 158 | os << "GpgME::InvalidRecipient("; 159 | if (!ir.isNull()) { 160 | os << "\n fingerprint: " << protect(ir.fingerprint()) 161 | << "\n reason: " << ir.reason() 162 | << '\n'; 163 | } 164 | return os << ')'; 165 | } 166 | --------------------------------------------------------------------------------