diff options
author | Ingo Klöcker <[email protected]> | 2025-02-03 09:49:25 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2025-02-03 09:55:40 +0000 |
commit | 763d5f5d6a88ec938b8678ab597e1404af724553 (patch) | |
tree | 7f3791e3560bd3a51470494bf965b9f9a40a87bd /lang/cpp/src | |
parent | build: Fix generation of ChangeLog on secondary working trees (diff) | |
download | gpgme-763d5f5d6a88ec938b8678ab597e1404af724553.tar.gz gpgme-763d5f5d6a88ec938b8678ab597e1404af724553.zip |
cpp,qt: Remove C++ and Qt bindings
* README: Update.
* configure.ac: Remove checks, variables and file generations related to
the C++/Qt bindings. Remove cpp and qt* from available_languages and
default_languages.
* lang/Makefile.am (DIST_SUBDIRS): Remove cpp and qt.
* lang/cpp, lang/qt: Remove.
* m4/ax_check_compile_flag.m4, m4/ax_cxx_compile_stdcxx.m4,
m4/ax_gcc_func_attribute.m4, m4/pkg.m4, m4/qt5.m4, m4/qt6.m4: Remove.
--
The C++ and Qt bindings have been moved to separate Git repositories:
gpgmepp and gpgmeqt.
GnuPG-bug-id: 7262
Diffstat (limited to 'lang/cpp/src')
85 files changed, 0 insertions, 16521 deletions
diff --git a/lang/cpp/src/GpgmeppConfig-w32.cmake.in.in b/lang/cpp/src/GpgmeppConfig-w32.cmake.in.in deleted file mode 100644 index 51ada3b1..00000000 --- a/lang/cpp/src/GpgmeppConfig-w32.cmake.in.in +++ /dev/null @@ -1,99 +0,0 @@ -# CMake Config file for GPGMEPP. -# Copyright (C) 2016 Intevation GmbH -# -# This file is part of GPGMEPP. -# -# GPGME-CL is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# GPGME-CL is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA - -# based on a generated file from cmake. -# Generated by CMake 3.0.2 - -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) - message(FATAL_ERROR "CMake >= 2.6.0 required") -endif() -cmake_policy(PUSH) -cmake_policy(VERSION 2.6) -#---------------------------------------------------------------- -# Generated CMake target import file. -#---------------------------------------------------------------- - -# Commands may need to know the format version. -set(CMAKE_IMPORT_FILE_VERSION 1) - -# Protect against multiple inclusion, which would fail when already imported targets are added once more. -set(_targetsDefined) -set(_targetsNotDefined) -set(_expectedTargets) -foreach(_expectedTarget Gpgmepp) - list(APPEND _expectedTargets ${_expectedTarget}) - if(NOT TARGET ${_expectedTarget}) - list(APPEND _targetsNotDefined ${_expectedTarget}) - endif() - if(TARGET ${_expectedTarget}) - list(APPEND _targetsDefined ${_expectedTarget}) - endif() -endforeach() -if("${_targetsDefined}" STREQUAL "${_expectedTargets}") - set(CMAKE_IMPORT_FILE_VERSION) - cmake_policy(POP) - return() -endif() -if(NOT "${_targetsDefined}" STREQUAL "") - message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") -endif() -unset(_targetsDefined) -unset(_targetsNotDefined) -unset(_expectedTargets) - -# Create imported target Gpgmepp -add_library(Gpgmepp SHARED IMPORTED) - -set_target_properties(Gpgmepp PROPERTIES - IMPORTED_IMPLIB "@resolved_libdir@/libgpgmepp.dll.a" - INTERFACE_INCLUDE_DIRECTORIES "@resolved_includedir@/gpgme++;@resolved_includedir@" - INTERFACE_LINK_LIBRARIES "pthread;@resolved_libdir@/libgpgme.dll.a;@LIBASSUAN_LIBS@" - IMPORTED_LOCATION "@resolved_bindir@/libgpgmepp-6.dll" -) -list(APPEND _IMPORT_CHECK_TARGETS Gpgmepp ) -list(APPEND _IMPORT_CHECK_FILES_FOR_Gpgmepp "@resolved_libdir@/libgpgmepp.dll.a" "@resolved_bindir@/libgpgmepp-6.dll" ) - - -if(CMAKE_VERSION VERSION_LESS 2.8.12) - message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.") -endif() - -# Loop over all imported files and verify that they actually exist -foreach(target ${_IMPORT_CHECK_TARGETS} ) - foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) - if(NOT EXISTS "${file}" ) - message(FATAL_ERROR "The imported target \"${target}\" references the file - \"${file}\" -but this file does not exist. Possible reasons include: -* The file was deleted, renamed, or moved to another location. -* An install or uninstall procedure did not complete successfully. -* The installation package was faulty and contained - \"${CMAKE_CURRENT_LIST_FILE}\" -but not all the files it references. -") - endif() - endforeach() - unset(_IMPORT_CHECK_FILES_FOR_${target}) -endforeach() -unset(_IMPORT_CHECK_TARGETS) - -# Commands beyond this point should not need to know the version. -set(CMAKE_IMPORT_FILE_VERSION) -cmake_policy(POP) diff --git a/lang/cpp/src/GpgmeppConfig.cmake.in.in b/lang/cpp/src/GpgmeppConfig.cmake.in.in deleted file mode 100644 index 8777623e..00000000 --- a/lang/cpp/src/GpgmeppConfig.cmake.in.in +++ /dev/null @@ -1,95 +0,0 @@ -# CMake Config file for GPGMEPP. -# Copyright (C) 2016 Intevation GmbH -# -# This file is part of GPGMEPP. -# -# GPGME-CL is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# GPGME-CL is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA - -# based on a generated file from cmake. -# Generated by CMake 3.0.2 - -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) - message(FATAL_ERROR "CMake >= 2.6.0 required") -endif() -cmake_policy(PUSH) -cmake_policy(VERSION 2.6) -#---------------------------------------------------------------- -# Generated CMake target import file. -#---------------------------------------------------------------- - -# Commands may need to know the format version. -set(CMAKE_IMPORT_FILE_VERSION 1) - -# Protect against multiple inclusion, which would fail when already imported targets are added once more. -set(_targetsDefined) -set(_targetsNotDefined) -set(_expectedTargets) -foreach(_expectedTarget Gpgmepp) - list(APPEND _expectedTargets ${_expectedTarget}) - if(NOT TARGET ${_expectedTarget}) - list(APPEND _targetsNotDefined ${_expectedTarget}) - endif() - if(TARGET ${_expectedTarget}) - list(APPEND _targetsDefined ${_expectedTarget}) - endif() -endforeach() -if("${_targetsDefined}" STREQUAL "${_expectedTargets}") - set(CMAKE_IMPORT_FILE_VERSION) - cmake_policy(POP) - return() -endif() -if(NOT "${_targetsDefined}" STREQUAL "") - message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") -endif() -unset(_targetsDefined) -unset(_targetsNotDefined) -unset(_expectedTargets) - -# Create imported target Gpgmepp -add_library(Gpgmepp SHARED IMPORTED) - -set_target_properties(Gpgmepp PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "@resolved_includedir@/gpgme++;@resolved_includedir@" - INTERFACE_LINK_LIBRARIES "pthread;@resolved_libdir@/libgpgme@libsuffix@;@LIBASSUAN_LIBS@" - IMPORTED_LOCATION "@resolved_libdir@/libgpgmepp@libsuffix@" -) - -if(CMAKE_VERSION VERSION_LESS 2.8.12) - message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.") -endif() - -# Loop over all imported files and verify that they actually exist -foreach(target ${_IMPORT_CHECK_TARGETS} ) - foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) - if(NOT EXISTS "${file}" ) - message(FATAL_ERROR "The imported target \"${target}\" references the file - \"${file}\" -but this file does not exist. Possible reasons include: -* The file was deleted, renamed, or moved to another location. -* An install or uninstall procedure did not complete successfully. -* The installation package was faulty and contained - \"${CMAKE_CURRENT_LIST_FILE}\" -but not all the files it references. -") - endif() - endforeach() - unset(_IMPORT_CHECK_FILES_FOR_${target}) -endforeach() -unset(_IMPORT_CHECK_TARGETS) - -# Commands beyond this point should not need to know the version. -set(CMAKE_IMPORT_FILE_VERSION) -cmake_policy(POP) diff --git a/lang/cpp/src/GpgmeppConfigVersion.cmake.in b/lang/cpp/src/GpgmeppConfigVersion.cmake.in deleted file mode 100644 index 259bddd5..00000000 --- a/lang/cpp/src/GpgmeppConfigVersion.cmake.in +++ /dev/null @@ -1,31 +0,0 @@ -# CMake Version file for GPGMEPP. -# Copyright (C) 2016 Intevation GmbH -# -# This file is part of GPGMEPP. -# -# GPGME-CL is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# GPGME-CL is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA - -# based on a generated file from cmake. -set(PACKAGE_VERSION "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_MICRO@") - -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() diff --git a/lang/cpp/src/Makefile.am b/lang/cpp/src/Makefile.am deleted file mode 100644 index db363226..00000000 --- a/lang/cpp/src/Makefile.am +++ /dev/null @@ -1,134 +0,0 @@ -# Makefile.am for GPGMEPP. -# Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik -# Software engineering by Intevation GmbH -# -# This file is part of GPGMEPP. -# -# GPGME-CL is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# GPGME-CL is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = gpgmepp.pc - -EXTRA_DIST = GpgmeppConfig.cmake.in.in GpgmeppConfigVersion.cmake.in \ - gpgmepp_version.h.in GpgmeppConfig-w32.cmake.in.in \ - gpgmepp.pc.in - -lib_LTLIBRARIES = libgpgmepp.la - -main_sources = \ - exception.cpp context.cpp key.cpp trustitem.cpp data.cpp callbacks.cpp \ - eventloopinteractor.cpp editinteractor.cpp \ - keylistresult.cpp keygenerationresult.cpp importresult.cpp \ - decryptionresult.cpp verificationresult.cpp \ - signingresult.cpp encryptionresult.cpp \ - engineinfo.cpp gpgsetexpirytimeeditinteractor.cpp \ - gpgsetownertrusteditinteractor.cpp gpgsignkeyeditinteractor.cpp \ - gpgadduserideditinteractor.cpp gpggencardkeyinteractor.cpp \ - gpgaddexistingsubkeyeditinteractor.cpp \ - gpgrevokekeyeditinteractor.cpp \ - defaultassuantransaction.cpp \ - scdgetinfoassuantransaction.cpp gpgagentgetinfoassuantransaction.cpp \ - statusconsumerassuantransaction.cpp \ - vfsmountresult.cpp configuration.cpp tofuinfo.cpp swdbresult.cpp \ - util.cpp - -gpgmepp_headers = \ - configuration.h context.h data.h decryptionresult.h \ - defaultassuantransaction.h editinteractor.h encryptionresult.h \ - engineinfo.h error.h eventloopinteractor.h exception.h global.h \ - gpgadduserideditinteractor.h gpgagentgetinfoassuantransaction.h \ - gpgmefw.h gpgsetexpirytimeeditinteractor.h \ - gpgsetownertrusteditinteractor.h gpgsignkeyeditinteractor.h \ - gpggencardkeyinteractor.h \ - gpgaddexistingsubkeyeditinteractor.h \ - gpgrevokekeyeditinteractor.h \ - importresult.h keygenerationresult.h key.h keylistresult.h \ - notation.h result.h scdgetinfoassuantransaction.h signingresult.h \ - statusconsumerassuantransaction.h \ - trustitem.h verificationresult.h vfsmountresult.h gpgmepp_export.h \ - tofuinfo.h swdbresult.h - -private_gpgmepp_headers = \ - result_p.h context_p.h util.h callbacks.h data_p.h - -interface_headers= \ - interfaces/assuantransaction.h interfaces/dataprovider.h \ - interfaces/passphraseprovider.h interfaces/progressprovider.h \ - interfaces/statusconsumer.h - -gpgmeppincludedir = $(includedir)/gpgme++ -gpgmeppinclude_HEADERS = $(gpgmepp_headers) -nobase_gpgmeppinclude_HEADERS = $(interface_headers) -nodist_gpgmeppinclude_HEADERS = gpgmepp_version.h - -libgpgmepp_la_SOURCES = $(main_sources) $(gpgmepp_headers) context_vanilla.cpp \ - $(interface_headers) $(private_gpgmepp_headers) - -AM_CPPFLAGS = -I$(top_builddir)/src \ - @GPGME_CPP_CFLAGS@ @GPG_ERROR_CFLAGS@ @LIBASSUAN_CFLAGS@ \ - -DBUILDING_GPGMEPP -Wsuggest-override \ - -Wzero-as-null-pointer-constant - -libgpgmepp_la_LIBADD = ../../../src/libgpgme.la @LIBASSUAN_LIBS@ -libgpgmepp_la_LDFLAGS = -no-undefined -version-info \ - @LIBGPGMEPP_LT_CURRENT@:@LIBGPGMEPP_LT_REVISION@:@LIBGPGMEPP_LT_AGE@ - -if HAVE_MACOS_SYSTEM -libsuffix=.dylib -else -libsuffix=.so -endif - -copied_headers = $(gpgmepp_headers:%=gpgme++/%) $(interface_headers:%=gpgme++/%) - -$(copied_headers): Makefile.am - mkdir -p $(builddir)/gpgme++/interfaces - echo -n "#include \"$(abs_srcdir)" > "$@" - echo -n "$@" | sed "s/gpgme++//" >> "$@" - echo "\"" >> "$@" - -if HAVE_W32_SYSTEM -GpgmeppConfig.cmake: GpgmeppConfig-w32.cmake.in - sed -e 's|[@]resolved_bindir@|$(bindir)|g' < "$<" | \ - sed -e 's|[@]resolved_libdir@|$(libdir)|g' | \ - sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ -else -GpgmeppConfig.cmake: GpgmeppConfig.cmake.in - sed -e 's|[@]resolved_libdir@|$(libdir)|g' < "$<" | \ - sed -e 's|[@]libsuffix@|$(libsuffix)|g' | \ - sed -e 's|[@]resolved_includedir@|$(includedir)|g' > $@ -endif -install-cmake-files: GpgmeppConfig.cmake GpgmeppConfigVersion.cmake - -$(INSTALL) -d $(DESTDIR)$(libdir)/cmake/Gpgmepp - $(INSTALL) -m 644 GpgmeppConfig.cmake \ - $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfig.cmake - $(INSTALL) -m 644 GpgmeppConfigVersion.cmake \ - $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfigVersion.cmake - -uninstall-cmake-files: - -rm $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfigVersion.cmake - -rm $(DESTDIR)$(libdir)/cmake/Gpgmepp/GpgmeppConfig.cmake - -rmdir $(DESTDIR)$(libdir)/cmake/Gpgmepp/ - -install-data-local: install-cmake-files - -uninstall-local: uninstall-cmake-files - -BUILT_SOURCES = $(copied_headers) - -CLEANFILES = GpgmeppConfig.cmake GpgmeppConfigVersion.cmake \ - gpgmepp_version.h GpgmeppConfig.cmake.in \ - $(copied_headers) diff --git a/lang/cpp/src/callbacks.cpp b/lang/cpp/src/callbacks.cpp deleted file mode 100644 index 21c2a813..00000000 --- a/lang/cpp/src/callbacks.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - callbacks.cpp - callback targets for internal use: - Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "callbacks.h" -#include "util.h" - -#include <interfaces/progressprovider.h> -#include <interfaces/passphraseprovider.h> -#include <interfaces/dataprovider.h> -#include <error.h> - -#include <gpgme.h> -#include <gpg-error.h> - -#include <cassert> -#include <cerrno> -#include <cstring> -#include <unistd.h> -#include <stdlib.h> - -static inline gpgme_error_t make_err_from_syserror() -{ - return gpgme_error_from_syserror(); -} - -using GpgME::ProgressProvider; -using GpgME::PassphraseProvider; -using GpgME::DataProvider; - -void progress_callback(void *opaque, const char *what, - int type, int current, int total) -{ - ProgressProvider *provider = static_cast<ProgressProvider *>(opaque); - if (provider) { - provider->showProgress(what, type, current, total); - } -} - -/* To avoid that a compiler optimizes certain memset calls away, these - macros may be used instead. */ -#define wipememory2(_ptr,_set,_len) do { \ - volatile char *_vptr=(volatile char *)(_ptr); \ - size_t _vlen=(_len); \ - while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \ - } while(0) -#define wipememory(_ptr,_len) wipememory2(_ptr,0,_len) - -gpgme_error_t passphrase_callback(void *opaque, const char *uid_hint, const char *desc, - int prev_was_bad, int fd) -{ - PassphraseProvider *provider = static_cast<PassphraseProvider *>(opaque); - bool canceled = false; - gpgme_error_t err = GPG_ERR_NO_ERROR; - char *passphrase = provider ? provider->getPassphrase(uid_hint, desc, prev_was_bad, canceled) : nullptr ; - if (canceled) { - err = make_error(GPG_ERR_CANCELED); - } else { - if (passphrase && *passphrase) { - size_t passphrase_length = std::strlen(passphrase); - size_t written = 0; - do { - ssize_t now_written = gpgme_io_write(fd, passphrase + written, passphrase_length - written); - if (now_written < 0) { - err = make_err_from_syserror(); - break; - } - written += now_written; - } while (written < passphrase_length); - } - } - - if (passphrase && *passphrase) { - wipememory(passphrase, std::strlen(passphrase)); - } - free(passphrase); - gpgme_io_write(fd, "\n", 1); - return err; -} - -static gpgme_ssize_t -data_read_callback(void *opaque, void *buf, size_t buflen) -{ - DataProvider *provider = static_cast<DataProvider *>(opaque); - if (!provider) { - gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); - return -1; - } - return (gpgme_ssize_t)provider->read(buf, buflen); -} - -static gpgme_ssize_t -data_write_callback(void *opaque, const void *buf, size_t buflen) -{ - DataProvider *provider = static_cast<DataProvider *>(opaque); - if (!provider) { - gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); - return -1; - } - return (gpgme_ssize_t)provider->write(buf, buflen); -} - -static gpgme_off_t -data_seek_callback(void *opaque, gpgme_off_t offset, int whence) -{ - DataProvider *provider = static_cast<DataProvider *>(opaque); - if (!provider) { - gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); - return -1; - } - if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) { - gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); - return -1; - } - return provider->seek((off_t)offset, whence); -} - -static void data_release_callback(void *opaque) -{ - DataProvider *provider = static_cast<DataProvider *>(opaque); - if (provider) { - provider->release(); - } -} - -const gpgme_data_cbs GpgME::data_provider_callbacks = { - &data_read_callback, - &data_write_callback, - &data_seek_callback, - &data_release_callback -}; diff --git a/lang/cpp/src/callbacks.h b/lang/cpp/src/callbacks.h deleted file mode 100644 index a2c6e1b9..00000000 --- a/lang/cpp/src/callbacks.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - callbacks.h - callback targets for internal use: - Copyright (C) 2003 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - This is an internal header file, subject to change without - notice. DO NOT USE. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_CALLBACKS_H__ -#define __GPGMEPP_CALLBACKS_H__ - -#include <gpgme.h> - -extern "C" { - - void progress_callback(void *opaque, const char *what, - int type, int current, int total); - gpgme_error_t passphrase_callback(void *opaque, const char *uid_hint, - const char *desc, int prev_was_bad, int fd); -} - -namespace GpgME -{ -extern const gpgme_data_cbs data_provider_callbacks; -extern const gpgme_edit_cb_t edit_interactor_callback; -} - -#endif // __GPGME_CALLBACKS_H__ diff --git a/lang/cpp/src/configuration.cpp b/lang/cpp/src/configuration.cpp deleted file mode 100644 index b3b62d6f..00000000 --- a/lang/cpp/src/configuration.cpp +++ /dev/null @@ -1,788 +0,0 @@ -/* - configuration.cpp - wraps gpgme configuration components - Copyright (C) 2010 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "configuration.h" -#include "error.h" -#include "util.h" - -#include <gpgme.h> - -#include <iterator> -#include <algorithm> -#include <ostream> -#include <cstring> -#include <assert.h> - -using namespace GpgME; -using namespace GpgME::Configuration; - -typedef std::shared_ptr< std::remove_pointer<gpgme_conf_opt_t>::type > shared_gpgme_conf_opt_t; -typedef std::weak_ptr< std::remove_pointer<gpgme_conf_opt_t>::type > weak_gpgme_conf_opt_t; - -typedef std::shared_ptr< std::remove_pointer<gpgme_conf_arg_t>::type > shared_gpgme_conf_arg_t; -typedef std::weak_ptr< std::remove_pointer<gpgme_conf_arg_t>::type > weak_gpgme_conf_arg_t; - -typedef std::shared_ptr< std::remove_pointer<gpgme_ctx_t>::type > shared_gpgme_ctx_t; -typedef std::weak_ptr< std::remove_pointer<gpgme_ctx_t>::type > weak_gpgme_ctx_t; - -namespace -{ -struct nodelete { - template <typename T> void operator()(T *) {} -}; -} - -// static -std::vector<Component> Component::load(Error &returnedError) -{ - - // - // 1. get a context: - // - gpgme_ctx_t ctx_native = nullptr; - if (const gpgme_error_t err = gpgme_new(&ctx_native)) { - returnedError = Error(err); - return std::vector<Component>(); - } - const shared_gpgme_ctx_t ctx(ctx_native, &gpgme_release); - - // - // 2. load the config: - // - gpgme_conf_comp_t conf_list_native = nullptr; - if (const gpgme_error_t err = gpgme_op_conf_load(ctx_native, &conf_list_native)) { - returnedError = Error(err); - return std::vector<Component>(); - } - shared_gpgme_conf_comp_t head(conf_list_native, &gpgme_conf_release); - - // - // 3. convert to vector<Component>: - // - std::vector<Component> result; - - while (head) { - // secure 'head->next' (if any) against memleaks: - shared_gpgme_conf_comp_t next; - if (head->next) { - next.reset(head->next, &gpgme_conf_release); - } - - // now prevent double-free of next.get() and following: - head->next = nullptr; - - // now add a new Component to 'result' (may throw): - result.resize(result.size() + 1); - result.back().comp.swap(head); // .comp = std::move( head ); - head.swap(next); // head = std::move( next ); - } - - return result; -} - -Error Component::save() const -{ - - if (isNull()) { - return Error(make_error(GPG_ERR_INV_ARG)); - } - - // - // 1. get a context: - // - gpgme_ctx_t ctx_native = nullptr; - if (const gpgme_error_t err = gpgme_new(&ctx_native)) { - return Error(err); - } - const shared_gpgme_ctx_t ctx(ctx_native, &gpgme_release); - - // - // 2. save the config: - // - return Error(gpgme_op_conf_save(ctx.get(), comp.get())); -} - -const char *Component::name() const -{ - return comp ? comp->name : nullptr; -} - -const char *Component::description() const -{ - return comp ? comp->description : nullptr ; -} - -const char *Component::programName() const -{ - return comp ? comp->program_name : nullptr ; -} - -Option Component::option(unsigned int idx) const -{ - gpgme_conf_opt_t opt = nullptr; - if (comp) { - opt = comp->options; - } - while (opt && idx) { - opt = opt->next; - --idx; - } - if (opt) { - return Option(comp, opt); - } - return Option(); -} - -Option Component::option(const char *name) const -{ - gpgme_conf_opt_t opt = nullptr; - if (comp) { - opt = comp->options; - } - using namespace std; // for strcmp - while (opt && strcmp(name, opt->name) != 0) { - opt = opt->next; - } - if (opt) { - return Option(comp, opt); - } - return Option(); -} - -unsigned int Component::numOptions() const -{ - unsigned int result = 0; - for (gpgme_conf_opt_t opt = comp ? comp->options : nullptr ; opt ; opt = opt->next) { - ++result; - } - return result; -} - -std::vector<Option> Component::options() const -{ - std::vector<Option> result; - for (gpgme_conf_opt_t opt = comp ? comp->options : nullptr ; opt ; opt = opt->next) { - result.push_back(Option(comp, opt)); - } - return result; -} - -static gpgme_conf_arg_t mygpgme_conf_arg_copy(gpgme_conf_arg_t other, gpgme_conf_type_t type) -{ - gpgme_conf_arg_t result = nullptr, last = nullptr; - for (gpgme_conf_arg_t a = other ; a ; a = a->next) { - gpgme_conf_arg_t arg = nullptr; - const gpgme_error_t err - = gpgme_conf_arg_new(&arg, type, - a->no_arg ? nullptr : - type == GPGME_CONF_STRING ? a->value.string : - /* else */ static_cast<void *>(&a->value)); - if (err) { - gpgme_conf_arg_release(result, type); - return nullptr; - } - assert(arg); - if (result) { - last->next = arg; - } else { - result = arg; - } - last = arg; - } - return result; -} - -Component Option::parent() const -{ - return Component(comp.lock()); -} - -unsigned int Option::flags() const -{ - return isNull() ? 0 : opt->flags; -} - -Level Option::level() const -{ - return isNull() ? Internal : static_cast<Level>(opt->level) ; -} - -const char *Option::name() const -{ - return isNull() ? nullptr : opt->name ; -} - -const char *Option::description() const -{ - return isNull() ? nullptr : opt->description ; -} - -const char *Option::argumentName() const -{ - return isNull() ? nullptr : opt->argname ; -} - -Type Option::type() const -{ - return isNull() ? NoType : static_cast<Type>(opt->type) ; -} - -Type Option::alternateType() const -{ - return isNull() ? NoType : static_cast<Type>(opt->alt_type) ; -} - -Argument Option::defaultValue() const -{ - if (isNull()) { - return Argument(); - } else { - return Argument(comp.lock(), opt, opt->default_value, false); - } -} - -const char *Option::defaultDescription() const -{ - return isNull() ? nullptr : opt->default_description ; -} - -Argument Option::noArgumentValue() const -{ - if (isNull()) { - return Argument(); - } else { - return Argument(comp.lock(), opt, opt->no_arg_value, false); - } -} - -const char *Option::noArgumentDescription() const -{ - return isNull() ? nullptr : opt->no_arg_description ; -} - -Argument Option::activeValue() const -{ - if (isNull()) { - return Argument(); - } else { - return Argument(comp.lock(), opt, opt->value, false); - } -} - -Argument Option::currentValue() const -{ - if (isNull()) { - return Argument(); - } - const gpgme_conf_arg_t arg = - opt->change_value ? opt->new_value ? opt->new_value : opt->default_value : - opt->value ? opt->value : - /* else */ opt->default_value ; - return Argument(comp.lock(), opt, arg, false); -} - -Argument Option::newValue() const -{ - if (isNull()) { - return Argument(); - } else { - return Argument(comp.lock(), opt, opt->new_value, false); - } -} - -bool Option::set() const -{ - if (isNull()) { - return false; - } else if (opt->change_value) { - return opt->new_value; - } else { - return opt->value; - } -} - -bool Option::dirty() const -{ - return !isNull() && opt->change_value ; -} - -Error Option::setNewValue(const Argument &argument) -{ - if (isNull()) { - return Error(make_error(GPG_ERR_INV_ARG)); - } else if (argument.isNull()) { - return resetToDefaultValue(); - } else if (const gpgme_conf_arg_t arg = mygpgme_conf_arg_copy(argument.arg, opt->alt_type)) { - return Error(gpgme_conf_opt_change(opt, 0, arg)); - } else { - return Error(make_error(GPG_ERR_ENOMEM)); - } -} - -Error Option::resetToActiveValue() -{ - if (isNull()) { - return Error(make_error(GPG_ERR_INV_ARG)); - } else { - return Error(gpgme_conf_opt_change(opt, 1, nullptr)); - } -} - -Error Option::resetToDefaultValue() -{ - if (isNull()) { - return Error(make_error(GPG_ERR_INV_ARG)); - } else { - return Error(gpgme_conf_opt_change(opt, 0, nullptr)); - } -} - -static gpgme_conf_arg_t make_argument(gpgme_conf_type_t type, const void *value) -{ - gpgme_conf_arg_t arg = nullptr; - if (const gpgme_error_t err = gpgme_conf_arg_new(&arg, type, value)) { - return nullptr; - } else { - return arg; - } -} - -Argument Option::createNoneArgument(bool set) const -{ - if (isNull() || alternateType() != NoType) { - return Argument(); - } else { - if (set) { - return createNoneListArgument(1); - } - } - return Argument(); -} - -Argument Option::createStringArgument(const char *value) const -{ - if (isNull() || alternateType() != StringType) { - return Argument(); - } else { - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_STRING, value), true); - } -} - -Argument Option::createStringArgument(const std::string &value) const -{ - if (isNull() || alternateType() != StringType) { - return Argument(); - } else { - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_STRING, value.c_str()), true); - } -} - -Argument Option::createIntArgument(int value) const -{ - if (isNull() || alternateType() != IntegerType) { - return Argument(); - } else { - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_INT32, &value), true); - } -} - -Argument Option::createUIntArgument(unsigned int value) const -{ - if (isNull() || alternateType() != UnsignedIntegerType) { - return Argument(); - } else { - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_UINT32, &value), true); - } -} - -namespace -{ -const void *to_void_star(const char *s) -{ - return s; -} -const void *to_void_star(const std::string &s) -{ - return s.c_str(); -} -const void *to_void_star(const int &i) -{ - return &i; // const-&: sic! -} -const void *to_void_star(const unsigned int &i) -{ - return &i; // const-&: sic! -} - -template <typename T> -gpgme_conf_arg_t make_argument(gpgme_conf_type_t type, const std::vector<T> &value) -{ - gpgme_conf_arg_t result = nullptr; - gpgme_conf_arg_t last = nullptr; - for (typename std::vector<T>::const_iterator it = value.begin(), end = value.end() ; it != end ; ++it) { - if (gpgme_conf_arg_t arg = make_argument(type, to_void_star(*it))) { - if (last) { - last = last->next = arg; - } else { - result = last = arg; - } - } - } - return result; -} -} - -Argument Option::createNoneListArgument(unsigned int value) const -{ - if (value) { - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_NONE, &value), true); - } - return Argument(); -} - -Argument Option::createStringListArgument(const std::vector<const char *> &value) const -{ - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_STRING, value), true); -} - -Argument Option::createStringListArgument(const std::vector<std::string> &value) const -{ - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_STRING, value), true); -} - -Argument Option::createIntListArgument(const std::vector<int> &value) const -{ - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_INT32, value), true); -} - -Argument Option::createUIntListArgument(const std::vector<unsigned int> &value) const -{ - return Argument(comp.lock(), opt, make_argument(GPGME_CONF_UINT32, value), true); -} - -Argument::Argument(const shared_gpgme_conf_comp_t &comp, gpgme_conf_opt_t opt, gpgme_conf_arg_t arg, bool owns) - : comp(comp), - opt(opt), - arg(owns ? arg : mygpgme_conf_arg_copy(arg, opt ? opt->alt_type : GPGME_CONF_NONE)) -{ - -} - -#if 0 -Argument::Argument(const shared_gpgme_conf_comp_t &comp, gpgme_conf_opt_t opt, gpgme_conf_arg_t arg) - : comp(comp), - opt(opt), - arg(mygpgme_conf_arg_copy(arg, opt ? opt->alt_type : GPGME_CONF_NONE)) -{ - -} -#endif - -Argument::Argument(const Argument &other) - : comp(other.comp), - opt(other.opt), - arg(mygpgme_conf_arg_copy(other.arg, opt ? opt->alt_type : GPGME_CONF_NONE)) -{ - -} - -Argument::~Argument() -{ - gpgme_conf_arg_release(arg, opt ? opt->alt_type : GPGME_CONF_NONE); -} - -Option Argument::parent() const -{ - return Option(comp.lock(), opt); -} - -bool Argument::boolValue() const -{ - return numberOfTimesSet(); -} - -unsigned int Argument::numElements() const -{ - if (isNull()) { - return 0; - } - unsigned int result = 0; - for (gpgme_conf_arg_t a = arg ; a ; a = a->next) { - ++result; - } - return result; -} - -const char *Argument::stringValue(unsigned int idx) const -{ - if (isNull() || opt->alt_type != GPGME_CONF_STRING) { - return nullptr; - } - gpgme_conf_arg_t a = arg; - while (a && idx) { - a = a->next; - --idx; - } - return a ? a->value.string : nullptr ; -} - -int Argument::intValue(unsigned int idx) const -{ - if (isNull() || opt->alt_type != GPGME_CONF_INT32) { - return 0; - } - gpgme_conf_arg_t a = arg; - while (a && idx) { - a = a->next; - --idx; - } - return a ? a->value.int32 : 0 ; -} - -unsigned int Argument::uintValue(unsigned int idx) const -{ - if (isNull() || opt->alt_type != GPGME_CONF_UINT32) { - return 0; - } - gpgme_conf_arg_t a = arg; - while (a && idx) { - a = a->next; - --idx; - } - return a ? a->value.uint32 : 0 ; -} - -unsigned int Argument::numberOfTimesSet() const -{ - if (isNull() || opt->alt_type != GPGME_CONF_NONE) { - return 0; - } - return arg->value.count; -} - -std::vector<const char *> Argument::stringValues() const -{ - if (isNull() || opt->alt_type != GPGME_CONF_STRING) { - return std::vector<const char *>(); - } - std::vector<const char *> result; - for (gpgme_conf_arg_t a = arg ; a ; a = a->next) { - result.push_back(a->value.string); - } - return result; -} - -std::vector<int> Argument::intValues() const -{ - if (isNull() || opt->alt_type != GPGME_CONF_INT32) { - return std::vector<int>(); - } - std::vector<int> result; - for (gpgme_conf_arg_t a = arg ; a ; a = a->next) { - result.push_back(a->value.int32); - } - return result; -} - -std::vector<unsigned int> Argument::uintValues() const -{ - if (isNull() || opt->alt_type != GPGME_CONF_UINT32) { - return std::vector<unsigned int>(); - } - std::vector<unsigned int> result; - for (gpgme_conf_arg_t a = arg ; a ; a = a->next) { - result.push_back(a->value.uint32); - } - return result; -} - -std::ostream &Configuration::operator<<(std::ostream &os, Level level) -{ - switch (level) { - case Basic: return os << "Basic"; - case Advanced: return os << "Advanced"; - case Expert: return os << "Expert"; - case Invisible: return os << "Invisible"; - case Internal: return os << "Internal"; - case NumLevels: ; - } - return os << "<unknown>"; -} - -std::ostream &Configuration::operator<<(std::ostream &os, Type type) -{ - switch (type) { - case NoType: return os << "None"; - case StringType: return os << "String"; - case IntegerType: return os << "Integer"; - case UnsignedIntegerType: return os << "UnsignedInteger"; - case FilenameType: return os << "Filename"; - case LdapServerType: return os << "LdapServer"; - case KeyFingerprintType: return os << "KeyFingerprint"; - case PublicKeyType: return os << "PublicKey"; - case SecretKeyType: return os << "SecretKey"; - case AliasListType: return os << "AliasList"; - case MaxType: ; - } - return os << "<unknown>"; -} - -std::ostream &Configuration::operator<<(std::ostream &os, Flag f) -{ - unsigned int flags = f; - std::vector<const char *> s; - if (flags & Group) { - s.push_back("Group"); - } - if (flags & Optional) { - s.push_back("Optional"); - } - if (flags & List) { - s.push_back("List"); - } - if (flags & Runtime) { - s.push_back("Runtime"); - } - if (flags & Default) { - s.push_back("Default"); - } - if (flags & DefaultDescription) { - s.push_back("DefaultDescription"); - } - if (flags & NoArgumentDescription) { - s.push_back("NoArgumentDescription"); - } - if (flags & NoChange) { - s.push_back("NoChange"); - } - flags &= ~(Group | Optional | List | Runtime | Default | DefaultDescription | NoArgumentDescription | NoChange); - if (flags) { - s.push_back("other flags("); - } - std::copy(s.begin(), s.end(), - std::ostream_iterator<const char *>(os, "|")); - if (flags) { - os << flags << ')'; - } - return os; -} - -std::ostream &Configuration::operator<<(std::ostream &os, const Component &c) -{ - os << "Component[" - << "\n name : " << protect(c.name()) - << "\n description: " << protect(c.description()) - << "\n programName: " << protect(c.programName()) - << "\n options : \n"; - const std::vector<Option> options = c.options(); - std::copy(options.begin(), options.end(), - std::ostream_iterator<Option>(os, "\n")); - os << "\n]"; - return os; -} - -std::ostream &Configuration::operator<<(std::ostream &os, const Option &o) -{ - return os << "Option[" - << "\n name: : " << protect(o.name()) - << "\n description : " << protect(o.description()) - << "\n argName : " << protect(o.argumentName()) - << "\n flags : " << static_cast<Flag>(o.flags()) - << "\n level : " << o.level() - << "\n type : " << o.type() - << "\n alt_type : " << o.alternateType() - << "\n default_val : " << o.defaultValue() - << "\n default_desc: " << protect(o.defaultDescription()) - << "\n no_arg_value: " << o.noArgumentValue() - << "\n no_arg_desc : " << protect(o.noArgumentDescription()) - << "\n active_value: " << o.activeValue() - << "\n new_value : " << o.newValue() - << "\n --> cur_val : " << o.currentValue() - << "\n set : " << o.set() - << "\n dirty : " << o.dirty() - << "\n]" - ; -} - -std::ostream &Configuration::operator<<(std::ostream &os, const Argument &a) -{ - const Option o = a.parent(); - const bool list = o.flags() & List; - os << "Argument["; - if (a) { - switch (o.alternateType()) { - case NoType: - if (list) { - os << a.numberOfTimesSet() << 'x'; - } else { - os << a.boolValue(); - } - break; - default: - case StringType: - if (list) { - const std::vector<const char *> v = a.stringValues(); - os << v.size() << ':'; - // can't use std::copy + ostream_iterator here, since we need the protect() call - bool first = true; - std::for_each(v.begin(), v.end(), [&first, &os](const char *s) { - if (first) { - first = false; - } else { - os << ','; - } - os << protect(s); - }); - } else { - os << protect(a.stringValue()); - } - break; - case IntegerType: - if (list) { - const std::vector<int> v = a.intValues(); - os << v.size() << ':'; - std::copy(v.begin(), v.end(), - std::ostream_iterator<int>(os, ",")); - } else { - os << a.intValue(); - } - break; - case UnsignedIntegerType: - if (list) { - const std::vector<unsigned int> v = a.uintValues(); - os << v.size() << ':'; - std::copy(v.begin(), v.end(), - std::ostream_iterator<unsigned int>(os, ",")); - } else { - os << a.intValue(); - } - break; - } - } - return os << ']'; -} diff --git a/lang/cpp/src/configuration.h b/lang/cpp/src/configuration.h deleted file mode 100644 index 286b7c02..00000000 --- a/lang/cpp/src/configuration.h +++ /dev/null @@ -1,292 +0,0 @@ -/* - configuration.h - wraps gpgme configuration components - Copyright (C) 2010 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_CONFIGURATION_H__ -#define __GPGMEPP_CONFIGURATION_H__ - -#include "global.h" - -#include "gpgmefw.h" - -#include <iosfwd> -#include <vector> -#include <string> -#include <algorithm> -#include <memory> - -namespace GpgME -{ -namespace Configuration -{ - -typedef std::shared_ptr< std::remove_pointer<gpgme_conf_comp_t>::type > shared_gpgme_conf_comp_t; -typedef std::weak_ptr< std::remove_pointer<gpgme_conf_comp_t>::type > weak_gpgme_conf_comp_t; - -class Argument; -class Option; -class Component; - -enum Level { - Basic, - Advanced, - Expert, - Invisible, - Internal, - - NumLevels -}; - -enum Type { - NoType, - StringType, - IntegerType, - UnsignedIntegerType, - - FilenameType = 32, - LdapServerType, - KeyFingerprintType, - PublicKeyType, - SecretKeyType, - AliasListType, - - MaxType -}; - -enum Flag { - Group = (1 << 0), - Optional = (1 << 1), - List = (1 << 2), - Runtime = (1 << 3), - Default = (1 << 4), - DefaultDescription = (1 << 5), - NoArgumentDescription = (1 << 6), - NoChange = (1 << 7), - - LastFlag = NoChange -}; - -// -// class Component -// - -class GPGMEPP_EXPORT Component -{ -public: - Component() : comp() {} - explicit Component(const shared_gpgme_conf_comp_t &gpgme_comp) - : comp(gpgme_comp) {} - - Component(const Component &other) = default; - const Component &operator=(const Component &other) - { - if (this != &other) { - Component(other).swap(*this); - } - return *this; - } - - void swap(Component &other) - { - using std::swap; - swap(this->comp, other.comp); - } - - bool isNull() const - { - return !comp; - } - - static std::vector<Component> load(Error &err); - Error save() const; - - const char *name() const; - const char *description() const; - const char *programName() const; - - Option option(unsigned int index) const; - Option option(const char *name) const; - - unsigned int numOptions() const; - - std::vector<Option> options() const; - - GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(!isNull()) -private: - shared_gpgme_conf_comp_t comp; -}; - -// -// class Option -// - -class GPGMEPP_EXPORT Option -{ -public: - Option() : comp(), opt(nullptr) {} - Option(const shared_gpgme_conf_comp_t &gpgme_comp, gpgme_conf_opt_t gpgme_opt) - : comp(gpgme_comp), opt(gpgme_opt) {} - - Option(const Option &other) = default; - const Option &operator=(const Option &other) - { - if (this != &other) { - Option(other).swap(*this); - } - return *this; - } - - void swap(Option &other) - { - using std::swap; - swap(this->comp, other.comp); - swap(this->opt, other.opt); - } - - bool isNull() const - { - return comp.expired() || !opt; - } - - Component parent() const; - - unsigned int flags() const; - - Level level() const; - - const char *name() const; - const char *description() const; - const char *argumentName() const; - - Type type() const; - Type alternateType() const; - - Argument defaultValue() const; - const char *defaultDescription() const; - - Argument noArgumentValue() const; - const char *noArgumentDescription() const; - - /*! The value that is in the config file (or null, if it's not set). */ - Argument activeValue() const; - /*! The value that is in this object, i.e. either activeValue(), newValue(), or defaultValue() */ - Argument currentValue() const; - - Argument newValue() const; - bool set() const; - bool dirty() const; - - Error setNewValue(const Argument &argument); - Error resetToDefaultValue(); - Error resetToActiveValue(); - - Argument createNoneArgument(bool set) const; - Argument createStringArgument(const char *value) const; - Argument createStringArgument(const std::string &value) const; - Argument createIntArgument(int value) const; - Argument createUIntArgument(unsigned int value) const; - - Argument createNoneListArgument(unsigned int count) const; - Argument createStringListArgument(const std::vector<const char *> &value) const; - Argument createStringListArgument(const std::vector<std::string> &value) const; - Argument createIntListArgument(const std::vector<int> &values) const; - Argument createUIntListArgument(const std::vector<unsigned int> &values) const; - - GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(!isNull()) -private: - weak_gpgme_conf_comp_t comp; - gpgme_conf_opt_t opt; -}; - -// -// class Argument -// - -class GPGMEPP_EXPORT Argument -{ - friend class ::GpgME::Configuration::Option; - Argument(const shared_gpgme_conf_comp_t &comp, gpgme_conf_opt_t opt, gpgme_conf_arg_t arg, bool owns); -public: - Argument() : comp(), opt(nullptr), arg(nullptr) {} - //Argument( const shared_gpgme_conf_comp_t & comp, gpgme_conf_opt_t opt, gpgme_conf_arg_t arg ); - Argument(const Argument &other); - ~Argument(); - - const Argument &operator=(const Argument &other) - { - if (this != &other) { - Argument(other).swap(*this); - } - return *this; - } - - void swap(Argument &other) - { - using std::swap; - swap(this->comp, other.comp); - swap(this->opt, other.opt); - swap(this->arg, other.arg); - } - - bool isNull() const - { - return comp.expired() || !opt || !arg; - } - - Option parent() const; - - unsigned int numElements() const; - - bool boolValue() const; - const char *stringValue(unsigned int index = 0) const; - int intValue(unsigned int index = 0) const; - unsigned int uintValue(unsigned int index = 0) const; - - unsigned int numberOfTimesSet() const; - std::vector<const char *> stringValues() const; - std::vector<int> intValues() const; - std::vector<unsigned int> uintValues() const; - - GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(!isNull()) -private: - weak_gpgme_conf_comp_t comp; - gpgme_conf_opt_t opt; - gpgme_conf_arg_t arg; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Level level); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Type type); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Flag flag); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Component &component); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Option &option); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Argument &argument); - -} // namespace Configuration -} // namespace GpgME - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Configuration::Component) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Configuration::Option) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Configuration::Argument) - -#endif // __GPGMEPP_CONFIGURATION_H__ diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp deleted file mode 100644 index 7a0fb23f..00000000 --- a/lang/cpp/src/context.cpp +++ /dev/null @@ -1,2138 +0,0 @@ -/* - context.cpp - wraps a gpgme key context - Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB - 2017, 2018 Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <context.h> -#include <eventloopinteractor.h> -#include <trustitem.h> -#include <keylistresult.h> -#include <keygenerationresult.h> -#include <importresult.h> -#include <decryptionresult.h> -#include <verificationresult.h> -#include <signingresult.h> -#include <encryptionresult.h> -#include <engineinfo.h> -#include <editinteractor.h> -#include <vfsmountresult.h> - -#include <interfaces/assuantransaction.h> -#include <defaultassuantransaction.h> - -#include "callbacks.h" -#include "data_p.h" -#include "context_p.h" -#include "util.h" -#include "tofuinfo.h" - -#include <gpgme.h> - -#include <functional> -#include <istream> -#include <numeric> -#ifndef NDEBUG -#include <iostream> -using std::cerr; -using std::endl; -#endif - -#include <cassert> - -namespace GpgME -{ - -static inline unsigned int xtoi_1(const char *str) -{ - const unsigned int ch = *str; - const unsigned int result = - ch <= '9' ? ch - '0' : - ch <= 'F' ? ch - 'A' + 10 : - /* else */ ch - 'a' + 10 ; - return result < 16 ? result : 0 ; -} -static inline int xtoi_2(const char *str) -{ - return xtoi_1(str) * 16U + xtoi_1(str + 1); -} - -static void percent_unescape(std::string &s, bool plus2space) -{ - std::string::iterator src = s.begin(), dest = s.begin(), end = s.end(); - while (src != end) { - if (*src == '%' && end - src > 2) { - *dest++ = xtoi_2(&*++src); - src += 2; - } else if (*src == '+' && plus2space) { - *dest++ = ' '; - ++src; - } else { - *dest++ = *src++; - } - } - s.erase(dest, end); -} - -void initializeLibrary() -{ - gpgme_check_version(nullptr); -} - -Error initializeLibrary(int) -{ - if (gpgme_check_version(GPGME_VERSION)) { - return Error(); - } else { - return Error::fromCode(GPG_ERR_USER_1); - } -} - -static void format_error(gpgme_error_t err, std::string &str) -{ - char buffer[ 1024 ]; - gpgme_strerror_r(err, buffer, sizeof buffer); - buffer[ sizeof buffer - 1 ] = '\0'; - str = buffer; -} - -const char *Error::source() const -{ - return gpgme_strsource((gpgme_error_t)mErr); -} - -const char *Error::asString() const -{ - if (mMessage.empty()) { - format_error(static_cast<gpgme_error_t>(mErr), mMessage); - } - return mMessage.c_str(); -} - -std::string Error::asStdString() const -{ - std::string message; - format_error(static_cast<gpgme_error_t>(mErr), message); - return message; -} - -int Error::code() const -{ - return gpgme_err_code(mErr); -} - -int Error::sourceID() const -{ - return gpgme_err_source(mErr); -} - -bool Error::isCanceled() const -{ - return code() == GPG_ERR_CANCELED || code() == GPG_ERR_FULLY_CANCELED; -} - -int Error::toErrno() const -{ - return gpgme_err_code_to_errno(static_cast<gpgme_err_code_t>(code())); -} - -// static -bool Error::hasSystemError() -{ - return gpgme_err_code_from_syserror() != GPG_ERR_MISSING_ERRNO ; -} - -// static -void Error::setSystemError(gpg_err_code_t err) -{ - setErrno(gpgme_err_code_to_errno(err)); -} - -// static -void Error::setErrno(int err) -{ - gpgme_err_set_errno(err); -} - -// static -Error Error::fromSystemError(unsigned int src) -{ - return Error(gpgme_err_make(static_cast<gpgme_err_source_t>(src), gpgme_err_code_from_syserror())); -} - -// static -Error Error::fromErrno(int err, unsigned int src) -{ - return Error(gpgme_err_make(static_cast<gpgme_err_source_t>(src), gpgme_err_code_from_errno(err))); -} - -// static -Error Error::fromCode(unsigned int err, unsigned int src) -{ - return Error(gpgme_err_make(static_cast<gpgme_err_source_t>(src), static_cast<gpgme_err_code_t>(err))); -} - -std::ostream &operator<<(std::ostream &os, const Error &err) -{ - return os << "GpgME::Error(" << err.encodedError() << " (" << err.asStdString() << "))"; -} - -Context::KeyListModeSaver::KeyListModeSaver(Context *ctx) - : mCtx{ctx} - , mKeyListMode{ctx ? ctx->keyListMode() : 0} -{ -} - -Context::KeyListModeSaver::~KeyListModeSaver() -{ - if (mCtx) { - mCtx->setKeyListMode(mKeyListMode); - } -} - -Context::Context(gpgme_ctx_t ctx) : d(new Private(ctx)) -{ -} - -Context::~Context() -{ - delete d; -} - -Context *Context::createForProtocol(Protocol proto) -{ - gpgme_ctx_t ctx = nullptr; - if (gpgme_new(&ctx) != 0) { - return nullptr; - } - - switch (proto) { - case OpenPGP: - if (gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP) != 0) { - gpgme_release(ctx); - return nullptr; - } - break; - case CMS: - if (gpgme_set_protocol(ctx, GPGME_PROTOCOL_CMS) != 0) { - gpgme_release(ctx); - return nullptr; - } - break; - default: - return nullptr; - } - - return new Context(ctx); -} - -std::unique_ptr<Context> Context::create(Protocol proto) -{ - return std::unique_ptr <Context> (createForProtocol(proto)); -} - -std::unique_ptr<Context> Context::createForEngine(Engine eng, Error *error) -{ - gpgme_ctx_t ctx = nullptr; - if (const gpgme_error_t err = gpgme_new(&ctx)) { - if (error) { - *error = Error(err); - } - return std::unique_ptr<Context>(); - } - - switch (eng) { - case AssuanEngine: - if (const gpgme_error_t err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_ASSUAN)) { - gpgme_release(ctx); - if (error) { - *error = Error(err); - } - return std::unique_ptr<Context>(); - } - break; - case G13Engine: - if (const gpgme_error_t err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_G13)) { - gpgme_release(ctx); - if (error) { - *error = Error(err); - } - return std::unique_ptr<Context>(); - } - break; - case SpawnEngine: - if (const gpgme_error_t err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_SPAWN)) { - gpgme_release(ctx); - if (error) { - *error = Error(err); - } - return std::unique_ptr<Context>(); - } - break; - default: - if (error) { - *error = Error::fromCode(GPG_ERR_INV_ARG); - } - return std::unique_ptr<Context>(); - } - - if (error) { - *error = Error(); - } - - return std::unique_ptr<Context>(new Context(ctx)); -} - -void Context::setDecryptionFlags(DecryptionFlags flags) -{ - d->decryptFlags = flags; -} - -// -// -// Context::Private -// -// - -Context::Private::Private(gpgme_ctx_t c) - : ctx(c), - iocbs(nullptr), - lastop(None), - lasterr(GPG_ERR_NO_ERROR), - lastAssuanInquireData(Data::null), - lastAssuanTransaction(), - lastEditInteractor(), - lastCardEditInteractor(), - decryptFlags(DecryptNone) -{ - -} - -Context::Private::~Private() -{ - if (ctx) { - gpgme_release(ctx); - } - ctx = nullptr; - delete iocbs; -} - -// -// -// Context attributes: -// -// - -Protocol Context::protocol() const -{ - gpgme_protocol_t p = gpgme_get_protocol(d->ctx); - switch (p) { - case GPGME_PROTOCOL_OpenPGP: return OpenPGP; - case GPGME_PROTOCOL_CMS: return CMS; - default: return UnknownProtocol; - } -} - -void Context::setArmor(bool useArmor) -{ - gpgme_set_armor(d->ctx, int(useArmor)); -} -bool Context::armor() const -{ - return gpgme_get_armor(d->ctx); -} - -void Context::setTextMode(bool useTextMode) -{ - gpgme_set_textmode(d->ctx, int(useTextMode)); -} -bool Context::textMode() const -{ - return gpgme_get_textmode(d->ctx); -} - -void Context::setOffline(bool useOfflineMode) -{ - gpgme_set_offline(d->ctx, int(useOfflineMode)); -} -bool Context::offline() const -{ - return gpgme_get_offline(d->ctx); -} - -void Context::setIncludeCertificates(int which) -{ - if (which == DefaultCertificates) { - which = GPGME_INCLUDE_CERTS_DEFAULT; - } - gpgme_set_include_certs(d->ctx, which); -} - -int Context::includeCertificates() const -{ - return gpgme_get_include_certs(d->ctx); -} - -void Context::setKeyListMode(unsigned int mode) -{ - gpgme_set_keylist_mode(d->ctx, add_to_gpgme_keylist_mode_t(0, mode)); -} - -void Context::addKeyListMode(unsigned int mode) -{ - const unsigned int cur = gpgme_get_keylist_mode(d->ctx); - gpgme_set_keylist_mode(d->ctx, add_to_gpgme_keylist_mode_t(cur, mode)); -} - -unsigned int Context::keyListMode() const -{ - return convert_from_gpgme_keylist_mode_t(gpgme_get_keylist_mode(d->ctx)); -} - -void Context::setProgressProvider(ProgressProvider *provider) -{ - gpgme_set_progress_cb(d->ctx, provider ? &progress_callback : nullptr, provider); -} -ProgressProvider *Context::progressProvider() const -{ - void *pp = nullptr; - gpgme_progress_cb_t pcb = &progress_callback; - gpgme_get_progress_cb(d->ctx, &pcb, &pp); - return static_cast<ProgressProvider *>(pp); -} - -void Context::setPassphraseProvider(PassphraseProvider *provider) -{ - gpgme_set_passphrase_cb(d->ctx, provider ? &passphrase_callback : nullptr, provider); -} - -PassphraseProvider *Context::passphraseProvider() const -{ - void *pp = nullptr; - gpgme_passphrase_cb_t pcb = &passphrase_callback; - gpgme_get_passphrase_cb(d->ctx, &pcb, &pp); - return static_cast<PassphraseProvider *>(pp); -} - -void Context::setManagedByEventLoopInteractor(bool manage) -{ - if (!EventLoopInteractor::instance()) { -#ifndef NDEBUG - cerr << "Context::setManagedByEventLoopInteractor(): " - "You must create an instance of EventLoopInteractor " - "before using anything that needs one." << endl; -#endif - return; - } - if (manage) { - EventLoopInteractor::instance()->manage(this); - } else { - EventLoopInteractor::instance()->unmanage(this); - } -} -bool Context::managedByEventLoopInteractor() const -{ - return d->iocbs != nullptr; -} - -void Context::installIOCallbacks(gpgme_io_cbs *iocbs) -{ - if (!iocbs) { - uninstallIOCallbacks(); - return; - } - gpgme_set_io_cbs(d->ctx, iocbs); - delete d->iocbs; d->iocbs = iocbs; -} - -void Context::uninstallIOCallbacks() -{ - static gpgme_io_cbs noiocbs = { nullptr, nullptr, nullptr, nullptr, nullptr }; - // io.add == 0 means disable io callbacks: - gpgme_set_io_cbs(d->ctx, &noiocbs); - delete d->iocbs; d->iocbs = nullptr; -} - -Error Context::setLocale(int cat, const char *val) -{ - return Error(d->lasterr = gpgme_set_locale(d->ctx, cat, val)); -} - -static GpgME::EngineInfo get_engine_info(gpgme_engine_info_t engineInfos, gpgme_protocol_t protocol) -{ - if (!engineInfos) { - return EngineInfo{}; - } - - for (gpgme_engine_info_t i = engineInfos ; i ; i = i->next) { - if (i->protocol == protocol) { - return EngineInfo{i}; - } - } - - return EngineInfo{}; -} - -static GpgME::EngineInfo get_static_engine_info(gpgme_protocol_t protocol) -{ - gpgme_engine_info_t ei = nullptr; - if (gpgme_get_engine_info(&ei)) { - return EngineInfo{}; - } - return get_engine_info(ei, protocol); -} - -EngineInfo Context::engineInfo() const -{ - return get_engine_info(gpgme_ctx_get_engine_info(d->ctx), gpgme_get_protocol(d->ctx)); -} - -Error Context::setEngineFileName(const char *filename) -{ - const char *const home_dir = engineInfo().homeDirectory(); - return Error(gpgme_ctx_set_engine_info(d->ctx, gpgme_get_protocol(d->ctx), filename, home_dir)); -} - -Error Context::setEngineHomeDirectory(const char *home_dir) -{ - const char *const filename = engineInfo().fileName(); - return Error(gpgme_ctx_set_engine_info(d->ctx, gpgme_get_protocol(d->ctx), filename, home_dir)); -} - -Error Context::setSender (const char *sender) -{ - return Error(gpgme_set_sender(d->ctx, sender)); -} - -const char *Context::getSender () -{ - return gpgme_get_sender(d->ctx); -} - -// -// -// Key Management -// -// - -Error Context::startKeyListing(const char *pattern, bool secretOnly) -{ - d->lastop = (((keyListMode() & GpgME::Locate) == GpgME::Locate) - ? Private::KeyListWithImport - : Private::KeyList); - return Error(d->lasterr = gpgme_op_keylist_start(d->ctx, pattern, int(secretOnly))); -} - -Error Context::startKeyListing(const char *patterns[], bool secretOnly) -{ - d->lastop = (((keyListMode() & GpgME::Locate) == GpgME::Locate) - ? Private::KeyListWithImport - : Private::KeyList); - return Error(d->lasterr = gpgme_op_keylist_ext_start(d->ctx, patterns, int(secretOnly), 0)); -} - -Key Context::nextKey(GpgME::Error &e) -{ - d->lastop = (((keyListMode() & GpgME::Locate) == GpgME::Locate) - ? Private::KeyListWithImport - : Private::KeyList); - gpgme_key_t key = nullptr; - e = Error(d->lasterr = gpgme_op_keylist_next(d->ctx, &key)); - return Key(key, false); -} - -KeyListResult Context::endKeyListing() -{ - d->lasterr = gpgme_op_keylist_end(d->ctx); - return keyListResult(); -} - -KeyListResult Context::keyListResult() const -{ - return KeyListResult(d->ctx, Error(d->lasterr)); -} - -Key Context::key(const char *fingerprint, GpgME::Error &e , bool secret /*, bool forceUpdate*/) -{ - d->lastop = Private::KeyList; - gpgme_key_t key = nullptr; - e = Error(d->lasterr = gpgme_get_key(d->ctx, fingerprint, &key, int(secret)/*, int( forceUpdate )*/)); - return Key(key, false); -} - -KeyGenerationResult Context::generateKey(const char *parameters, Data &pubKey) -{ - d->lastop = Private::KeyGen; - Data::Private *const dp = pubKey.impl(); - d->lasterr = gpgme_op_genkey(d->ctx, parameters, dp ? dp->data : nullptr, nullptr); - return KeyGenerationResult(d->ctx, Error(d->lasterr)); -} - -Error Context::startKeyGeneration(const char *parameters, Data &pubKey) -{ - d->lastop = Private::KeyGen; - Data::Private *const dp = pubKey.impl(); - return Error(d->lasterr = gpgme_op_genkey_start(d->ctx, parameters, dp ? dp->data : nullptr, nullptr)); -} - -KeyGenerationResult Context::keyGenerationResult() const -{ - if (d->lastop & Private::KeyGen) { - return KeyGenerationResult(d->ctx, Error(d->lasterr)); - } else { - return KeyGenerationResult(); - } -} - -Error Context::exportKeys(const char *pattern, Data &keyData, unsigned int mode) -{ - d->lastop = Private::Export; - Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export(d->ctx, pattern, mode, dp ? dp->data : nullptr)); -} - -Error Context::exportKeys(const char *patterns[], Data &keyData, unsigned int mode) -{ - d->lastop = Private::Export; - Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export_ext(d->ctx, patterns, mode, dp ? dp->data : nullptr)); -} - -Error Context::startKeyExport(const char *pattern, Data &keyData, unsigned int mode) -{ - d->lastop = Private::Export; - Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export_start(d->ctx, pattern, mode, dp ? dp->data : nullptr)); -} - -Error Context::startKeyExport(const char *patterns[], Data &keyData, unsigned int mode) -{ - d->lastop = Private::Export; - Data::Private *const dp = keyData.impl(); - return Error(d->lasterr = gpgme_op_export_ext_start(d->ctx, patterns, mode, dp ? dp->data : nullptr)); -} - -Error Context::exportPublicKeys(const char *pattern, Data &keyData, unsigned int mode) -{ - if (mode & (ExportSecret | ExportSecretSubkey)) { - return Error::fromCode(GPG_ERR_INV_FLAG); - } - return exportKeys(pattern, keyData, mode); -} - -Error Context::exportPublicKeys(const char *patterns[], Data &keyData, unsigned int mode) -{ - if (mode & (ExportSecret | ExportSecretSubkey)) { - return Error::fromCode(GPG_ERR_INV_FLAG); - } - return exportKeys(patterns, keyData, mode); -} - -Error Context::startPublicKeyExport(const char *pattern, Data &keyData, unsigned int mode) -{ - if (mode & (ExportSecret | ExportSecretSubkey)) { - return Error::fromCode(GPG_ERR_INV_FLAG); - } - return startKeyExport(pattern, keyData, mode); -} - -Error Context::startPublicKeyExport(const char *patterns[], Data &keyData, unsigned int mode) -{ - if (mode & (ExportSecret | ExportSecretSubkey)) { - return Error::fromCode(GPG_ERR_INV_FLAG); - } - return startKeyExport(patterns, keyData, mode); -} - -/* Same as above but without mode */ -Error Context::exportPublicKeys(const char *pattern, Data &keyData) -{ - return exportPublicKeys(pattern, keyData, 0); -} - -Error Context::exportPublicKeys(const char *patterns[], Data &keyData) -{ - return exportPublicKeys(patterns, keyData, 0); -} - -Error Context::startPublicKeyExport(const char *pattern, Data &keyData) -{ - return startPublicKeyExport(pattern, keyData, 0); -} - -Error Context::startPublicKeyExport(const char *patterns[], Data &keyData) -{ - return startPublicKeyExport(patterns, keyData, 0); -} - -Error Context::exportSecretKeys(const char *pattern, Data &keyData, unsigned int mode) -{ - if (mode & ExportSecretSubkey) { - return Error::fromCode(GPG_ERR_INV_FLAG); - } - return exportKeys(pattern, keyData, mode|ExportSecret); -} - -Error Context::exportSecretKeys(const char *patterns[], Data &keyData, unsigned int mode) -{ - if (mode & ExportSecretSubkey) { - return Error::fromCode(GPG_ERR_INV_FLAG); - } - return exportKeys(patterns, keyData, mode|ExportSecret); -} - -Error Context::startSecretKeyExport(const char *pattern, Data &keyData, unsigned int mode) -{ - if (mode & ExportSecretSubkey) { - return Error::fromCode(GPG_ERR_INV_FLAG); - } - return startKeyExport(pattern, keyData, mode|ExportSecret); -} - -Error Context::startSecretKeyExport(const char *patterns[], Data &keyData, unsigned int mode) -{ - if (mode & ExportSecretSubkey) { - return Error::fromCode(GPG_ERR_INV_FLAG); - } - return startKeyExport(patterns, keyData, mode|ExportSecret); -} - -Error Context::exportSecretSubkeys(const char *pattern, Data &keyData, unsigned int mode) -{ - return exportKeys(pattern, keyData, mode|ExportSecretSubkey); -} - -Error Context::exportSecretSubkeys(const char *patterns[], Data &keyData, unsigned int mode) -{ - return exportKeys(patterns, keyData, mode|ExportSecretSubkey); -} - -Error Context::startSecretSubkeyExport(const char *pattern, Data &keyData, unsigned int mode) -{ - return startKeyExport(pattern, keyData, mode|ExportSecretSubkey); -} - -Error Context::startSecretSubkeyExport(const char *patterns[], Data &keyData, unsigned int mode) -{ - return startKeyExport(patterns, keyData, mode|ExportSecretSubkey); -} - -ImportResult Context::importKeys(const Data &data) -{ - d->lastop = Private::Import; - const Data::Private *const dp = data.impl(); - d->lasterr = gpgme_op_import(d->ctx, dp ? dp->data : nullptr); - return ImportResult(d->ctx, Error(d->lasterr)); -} - -ImportResult Context::importKeys(const std::vector<Key> &kk) -{ - d->lastop = Private::Import; - d->lasterr = make_error(GPG_ERR_NOT_IMPLEMENTED); - - bool shouldHaveResult = false; - gpgme_key_t * const keys = new gpgme_key_t[ kk.size() + 1 ]; - gpgme_key_t *keys_it = &keys[0]; - for (std::vector<Key>::const_iterator it = kk.begin(), end = kk.end() ; it != end ; ++it) { - if (it->impl()) { - *keys_it++ = it->impl(); - } - } - *keys_it++ = nullptr; - d->lasterr = gpgme_op_import_keys(d->ctx, keys); - shouldHaveResult = true; - if ((gpgme_err_code(d->lasterr) == GPG_ERR_NOT_IMPLEMENTED || - gpgme_err_code(d->lasterr) == GPG_ERR_NOT_SUPPORTED) && - protocol() == CMS) { - // ok, try the workaround (export+import): - std::vector<const char *> fprs; - for (std::vector<Key>::const_iterator it = kk.begin(), end = kk.end() ; it != end ; ++it) { - if (const char *fpr = it->primaryFingerprint()) { - if (*fpr) { - fprs.push_back(fpr); - } - } else if (const char *keyid = it->keyID()) { - if (*keyid) { - fprs.push_back(keyid); - } - } - } - fprs.push_back(nullptr); - Data data; - Data::Private *const dp = data.impl(); - const gpgme_keylist_mode_t oldMode = gpgme_get_keylist_mode(d->ctx); - gpgme_set_keylist_mode(d->ctx, GPGME_KEYLIST_MODE_EXTERN); - d->lasterr = gpgme_op_export_ext(d->ctx, &fprs[0], 0, dp ? dp->data : nullptr); - gpgme_set_keylist_mode(d->ctx, oldMode); - if (!d->lasterr) { - data.seek(0, SEEK_SET); - d->lasterr = gpgme_op_import(d->ctx, dp ? dp->data : nullptr); - shouldHaveResult = true; - } - } - delete[] keys; - if (shouldHaveResult) { - return ImportResult(d->ctx, Error(d->lasterr)); - } else { - return ImportResult(Error(d->lasterr)); - } -} - -Error Context::startKeyImport(const Data &data) -{ - d->lastop = Private::Import; - const Data::Private *const dp = data.impl(); - return Error(d->lasterr = gpgme_op_import_start(d->ctx, dp ? dp->data : nullptr)); -} - -Error Context::startKeyImport(const std::vector<Key> &kk) -{ - d->lastop = Private::Import; - gpgme_key_t * const keys = new gpgme_key_t[ kk.size() + 1 ]; - gpgme_key_t *keys_it = &keys[0]; - for (std::vector<Key>::const_iterator it = kk.begin(), end = kk.end() ; it != end ; ++it) { - if (it->impl()) { - *keys_it++ = it->impl(); - } - } - *keys_it++ = nullptr; - Error err = Error(d->lasterr = gpgme_op_import_keys_start(d->ctx, keys)); - delete[] keys; - return err; -} - -ImportResult Context::importKeys(const std::vector<std::string> &keyIds) -{ - d->lastop = Private::Import; - const StringsToCStrings keyids{keyIds}; - d->lasterr = gpgme_op_receive_keys(d->ctx, keyids.c_strs()); - return ImportResult(d->ctx, Error(d->lasterr)); -} - -Error Context::startKeyImport(const std::vector<std::string> &keyIds) -{ - d->lastop = Private::Import; - const StringsToCStrings keyids{keyIds}; - d->lasterr = gpgme_op_receive_keys_start(d->ctx, keyids.c_strs()); - return Error(d->lasterr); -} - -ImportResult Context::importResult() const -{ - if (d->lastop & Private::Import) { - return ImportResult(d->ctx, Error(d->lasterr)); - } else { - return ImportResult(); - } -} - -Error Context::deleteKey(const Key &key, bool allowSecretKeyDeletion) -{ - d->lastop = Private::Delete; - return Error(d->lasterr = gpgme_op_delete(d->ctx, key.impl(), int(allowSecretKeyDeletion))); -} - -Error Context::startKeyDeletion(const Key &key, bool allowSecretKeyDeletion) -{ - d->lastop = Private::Delete; - return Error(d->lasterr = gpgme_op_delete_start(d->ctx, key.impl(), int(allowSecretKeyDeletion))); -} - -Error Context::passwd(const Key &key) -{ - d->lastop = Private::Passwd; - return Error(d->lasterr = gpgme_op_passwd(d->ctx, key.impl(), 0U)); -} - -Error Context::startPasswd(const Key &key) -{ - d->lastop = Private::Passwd; - return Error(d->lasterr = gpgme_op_passwd_start(d->ctx, key.impl(), 0U)); -} - - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - -Error Context::edit(const Key &key, std::unique_ptr<EditInteractor> func, Data &data) -{ - d->lastop = Private::Edit; - d->lastEditInteractor = std::move(func); - Data::Private *const dp = data.impl(); - return Error(d->lasterr = gpgme_op_edit(d->ctx, key.impl(), - d->lastEditInteractor.get() ? edit_interactor_callback : nullptr, - d->lastEditInteractor.get() ? d->lastEditInteractor->d : nullptr, - dp ? dp->data : nullptr)); -} - - -Error Context::startEditing(const Key &key, std::unique_ptr<EditInteractor> func, Data &data) -{ - d->lastop = Private::Edit; - d->lastEditInteractor = std::move(func); - Data::Private *const dp = data.impl(); - return Error(d->lasterr = gpgme_op_edit_start(d->ctx, key.impl(), - d->lastEditInteractor.get() ? edit_interactor_callback : nullptr, - d->lastEditInteractor.get() ? d->lastEditInteractor->d : nullptr, - dp ? dp->data : nullptr)); -} - - -EditInteractor *Context::lastEditInteractor() const -{ - return d->lastEditInteractor.get(); -} - -std::unique_ptr<EditInteractor> Context::takeLastEditInteractor() -{ - return std::move(d->lastEditInteractor); -} - - -Error Context::cardEdit(const Key &key, std::unique_ptr<EditInteractor> func, Data &data) -{ - d->lastop = Private::CardEdit; - d->lastCardEditInteractor = std::move(func); - Data::Private *const dp = data.impl(); - return Error(d->lasterr = gpgme_op_card_edit(d->ctx, key.impl(), - d->lastCardEditInteractor.get() ? edit_interactor_callback : nullptr, - d->lastCardEditInteractor.get() ? d->lastCardEditInteractor->d : nullptr, - dp ? dp->data : nullptr)); -} - -Error Context::startCardEditing(const Key &key, std::unique_ptr<EditInteractor> func, Data &data) -{ - d->lastop = Private::CardEdit; - d->lastCardEditInteractor = std::move(func); - Data::Private *const dp = data.impl(); - return Error(d->lasterr = gpgme_op_card_edit_start(d->ctx, key.impl(), - d->lastCardEditInteractor.get() ? edit_interactor_callback : nullptr, - d->lastCardEditInteractor.get() ? d->lastCardEditInteractor->d : nullptr, - dp ? dp->data : nullptr)); -} - -#pragma GCC diagnostic pop - -EditInteractor *Context::lastCardEditInteractor() const -{ - return d->lastCardEditInteractor.get(); -} - -std::unique_ptr<EditInteractor> Context::takeLastCardEditInteractor() -{ - return std::move(d->lastCardEditInteractor); -} - -Error Context::startTrustItemListing(const char *pattern, int maxLevel) -{ - d->lastop = Private::TrustList; - return Error(d->lasterr = gpgme_op_trustlist_start(d->ctx, pattern, maxLevel)); -} - -TrustItem Context::nextTrustItem(Error &e) -{ - gpgme_trust_item_t ti = nullptr; - e = Error(d->lasterr = gpgme_op_trustlist_next(d->ctx, &ti)); - return TrustItem(ti); -} - -Error Context::endTrustItemListing() -{ - return Error(d->lasterr = gpgme_op_trustlist_end(d->ctx)); -} - -static gpgme_error_t assuan_transaction_data_callback(void *opaque, const void *data, size_t datalen) -{ - assert(opaque); - AssuanTransaction *t = static_cast<AssuanTransaction *>(opaque); - return t->data(static_cast<const char *>(data), datalen).encodedError(); -} - -static gpgme_error_t assuan_transaction_inquire_callback(void *opaque, const char *name, const char *args, gpgme_data_t *r_data) -{ - assert(opaque); - Context::Private *p = static_cast<Context::Private *>(opaque); - AssuanTransaction *t = p->lastAssuanTransaction.get(); - assert(t); - Error err; - if (name) { - p->lastAssuanInquireData = t->inquire(name, args, err); - } else { - p->lastAssuanInquireData = Data::null; - } - if (!p->lastAssuanInquireData.isNull()) { - *r_data = p->lastAssuanInquireData.impl()->data; - } - return err.encodedError(); -} - -static gpgme_error_t assuan_transaction_status_callback(void *opaque, const char *status, const char *args) -{ - assert(opaque); - AssuanTransaction *t = static_cast<AssuanTransaction *>(opaque); - std::string a = args; - percent_unescape(a, true); // ### why doesn't gpgme do this?? - return t->status(status, a.c_str()).encodedError(); -} - -Error Context::assuanTransact(const char *command) -{ - return assuanTransact(command, std::unique_ptr<AssuanTransaction>(new DefaultAssuanTransaction)); -} - -Error Context::assuanTransact(const char *command, std::unique_ptr<AssuanTransaction> transaction) -{ - gpgme_error_t err, operr; - - d->lastop = Private::AssuanTransact; - d->lastAssuanTransaction = std::move(transaction); - if (!d->lastAssuanTransaction.get()) { - return Error(d->lasterr = make_error(GPG_ERR_INV_ARG)); - } - err = gpgme_op_assuan_transact_ext - (d->ctx, - command, - assuan_transaction_data_callback, - d->lastAssuanTransaction.get(), - assuan_transaction_inquire_callback, - d, - assuan_transaction_status_callback, - d->lastAssuanTransaction.get(), - &operr); - - if (!err) - err = operr; - d->lasterr = err; - - return Error(d->lasterr); -} - -Error Context::startAssuanTransaction(const char *command) -{ - return startAssuanTransaction(command, std::unique_ptr<AssuanTransaction>(new DefaultAssuanTransaction)); -} - -Error Context::startAssuanTransaction(const char *command, std::unique_ptr<AssuanTransaction> transaction) -{ - gpgme_error_t err; - - d->lastop = Private::AssuanTransact; - d->lastAssuanTransaction = std::move(transaction); - if (!d->lastAssuanTransaction.get()) { - return Error(d->lasterr = make_error(GPG_ERR_INV_ARG)); - } - err = gpgme_op_assuan_transact_start - (d->ctx, - command, - assuan_transaction_data_callback, - d->lastAssuanTransaction.get(), - assuan_transaction_inquire_callback, - d, - assuan_transaction_status_callback, - d->lastAssuanTransaction.get()); - - d->lasterr = err; - - return Error(d->lasterr); -} - -AssuanTransaction *Context::lastAssuanTransaction() const -{ - return d->lastAssuanTransaction.get(); -} - -std::unique_ptr<AssuanTransaction> Context::takeLastAssuanTransaction() -{ - return std::move(d->lastAssuanTransaction); -} - -DecryptionResult Context::decrypt(const Data &cipherText, Data &plainText, const DecryptionFlags flags) -{ - d->lastop = Private::Decrypt; - const Data::Private *const cdp = cipherText.impl(); - Data::Private *const pdp = plainText.impl(); - d->lasterr = gpgme_op_decrypt_ext(d->ctx, static_cast<gpgme_decrypt_flags_t> (d->decryptFlags | flags), cdp ? cdp->data : nullptr, pdp ? pdp->data : nullptr); - return decryptionResult(); -} - -DecryptionResult Context::decrypt(const Data &cipherText, Data &plainText) -{ - return decrypt(cipherText, plainText, DecryptNone); -} - -Error Context::startDecryption(const Data &cipherText, Data &plainText, const DecryptionFlags flags) -{ - d->lastop = Private::Decrypt; - const Data::Private *const cdp = cipherText.impl(); - Data::Private *const pdp = plainText.impl(); - return Error(d->lasterr = gpgme_op_decrypt_ext_start(d->ctx, static_cast<gpgme_decrypt_flags_t> (d->decryptFlags | flags), - cdp ? cdp->data : nullptr, pdp ? pdp->data : nullptr)); -} - -Error Context::startDecryption(const Data &cipherText, Data &plainText) -{ - return startDecryption(cipherText, plainText, DecryptNone); -} - -DecryptionResult Context::decryptionResult() const -{ - if (d->lastop & Private::Decrypt) { - return DecryptionResult(d->ctx, Error(d->lasterr)); - } else { - return DecryptionResult(); - } -} - -VerificationResult Context::verifyDetachedSignature(const Data &signature, const Data &signedText) -{ - d->lastop = Private::Verify; - const Data::Private *const sdp = signature.impl(); - const Data::Private *const tdp = signedText.impl(); - d->lasterr = gpgme_op_verify(d->ctx, sdp ? sdp->data : nullptr, tdp ? tdp->data : nullptr, nullptr); - return verificationResult(); -} - -VerificationResult Context::verifyOpaqueSignature(const Data &signedData, Data &plainText) -{ - d->lastop = Private::Verify; - const Data::Private *const sdp = signedData.impl(); - Data::Private *const pdp = plainText.impl(); - d->lasterr = gpgme_op_verify(d->ctx, sdp ? sdp->data : nullptr, nullptr, pdp ? pdp->data : nullptr); - return verificationResult(); -} - -Error Context::startDetachedSignatureVerification(const Data &signature, const Data &signedText) -{ - d->lastop = Private::Verify; - const Data::Private *const sdp = signature.impl(); - const Data::Private *const tdp = signedText.impl(); - return Error(d->lasterr = gpgme_op_verify_start(d->ctx, sdp ? sdp->data : nullptr, tdp ? tdp->data : nullptr, nullptr)); -} - -Error Context::startOpaqueSignatureVerification(const Data &signedData, Data &plainText) -{ - d->lastop = Private::Verify; - const Data::Private *const sdp = signedData.impl(); - Data::Private *const pdp = plainText.impl(); - return Error(d->lasterr = gpgme_op_verify_start(d->ctx, sdp ? sdp->data : nullptr, nullptr, pdp ? pdp->data : nullptr)); -} - -VerificationResult Context::verificationResult() const -{ - if (d->lastop & Private::Verify) { - const auto res = VerificationResult{d->ctx, Error(d->lasterr)}; - if ((d->lastop == Private::DecryptAndVerify) - && (res.error().code() == GPG_ERR_NO_DATA) - && (res.numSignatures() > 0)) { - // ignore "no data" error for verification if there are signatures and - // the operation was a combined (tentative) decryption and verification - // because then "no data" just indicates that there was nothing to decrypt - return VerificationResult{d->ctx, Error{}}; - } - return res; - } else { - return {}; - } -} - -std::pair<DecryptionResult, VerificationResult> Context::decryptAndVerify(const Data &cipherText, Data &plainText, DecryptionFlags flags) -{ - d->lastop = Private::DecryptAndVerify; - const Data::Private *const cdp = cipherText.impl(); - Data::Private *const pdp = plainText.impl(); - d->lasterr = gpgme_op_decrypt_ext(d->ctx, static_cast<gpgme_decrypt_flags_t> (d->decryptFlags | flags | DecryptVerify), - cdp ? cdp->data : nullptr, pdp ? pdp->data : nullptr); - return std::make_pair(decryptionResult(), verificationResult()); -} - -std::pair<DecryptionResult, VerificationResult> Context::decryptAndVerify(const Data &cipherText, Data &plainText) -{ - return decryptAndVerify(cipherText, plainText, DecryptNone); -} - -Error Context::startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText, DecryptionFlags flags) -{ - d->lastop = Private::DecryptAndVerify; - const Data::Private *const cdp = cipherText.impl(); - Data::Private *const pdp = plainText.impl(); - return Error(d->lasterr = gpgme_op_decrypt_ext_start(d->ctx, static_cast<gpgme_decrypt_flags_t> (d->decryptFlags | flags | DecryptVerify), cdp ? cdp->data : nullptr, pdp ? pdp->data : nullptr)); -} - -Error Context::startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText) -{ - return startCombinedDecryptionAndVerification(cipherText, plainText, DecryptNone); -} - -namespace { -unsigned int to_auditlog_flags(unsigned int flags) -{ - unsigned int result = 0; - if (flags & Context::HtmlAuditLog) { - result |= GPGME_AUDITLOG_HTML; - } - if (flags & Context::AuditLogWithHelp) { - result |= GPGME_AUDITLOG_WITH_HELP; - } - if (flags & Context::DiagnosticAuditLog) { - result |= GPGME_AUDITLOG_DIAG; - } - return result; -} -} - -Error Context::startGetAuditLog(Data &output, unsigned int flags) -{ - d->lastop = Private::GetAuditLog; - Data::Private *const odp = output.impl(); - return Error(d->lasterr = gpgme_op_getauditlog_start(d->ctx, odp ? odp->data : nullptr, to_auditlog_flags(flags))); -} - -Error Context::getAuditLog(Data &output, unsigned int flags) -{ - d->lastop = Private::GetAuditLog; - Data::Private *const odp = output.impl(); - return Error(d->lasterr = gpgme_op_getauditlog(d->ctx, odp ? odp->data : nullptr, to_auditlog_flags(flags))); -} - -void Context::clearSigningKeys() -{ - gpgme_signers_clear(d->ctx); -} - -Error Context::addSigningKey(const Key &key) -{ - return Error(d->lasterr = gpgme_signers_add(d->ctx, key.impl())); -} - -Key Context::signingKey(unsigned int idx) const -{ - gpgme_key_t key = gpgme_signers_enum(d->ctx, idx); - return Key(key, false); -} - -std::vector<Key> Context::signingKeys() const -{ - std::vector<Key> result; - gpgme_key_t key = nullptr; - for (unsigned int i = 0 ; (key = gpgme_signers_enum(d->ctx, i)) ; ++i) { - result.push_back(Key(key, false)); - } - return result; -} - -void Context::clearSignatureNotations() -{ - gpgme_sig_notation_clear(d->ctx); -} - -GpgME::Error Context::addSignatureNotation(const char *name, const char *value, unsigned int flags) -{ - return Error(gpgme_sig_notation_add(d->ctx, name, value, add_to_gpgme_sig_notation_flags_t(0, flags))); -} - -GpgME::Error Context::addSignaturePolicyURL(const char *url, bool critical) -{ - return Error(gpgme_sig_notation_add(d->ctx, nullptr, url, critical ? GPGME_SIG_NOTATION_CRITICAL : 0)); -} - -const char *Context::signaturePolicyURL() const -{ - for (gpgme_sig_notation_t n = gpgme_sig_notation_get(d->ctx) ; n ; n = n->next) { - if (!n->name) { - return n->value; - } - } - return nullptr; -} - -Notation Context::signatureNotation(unsigned int idx) const -{ - for (gpgme_sig_notation_t n = gpgme_sig_notation_get(d->ctx) ; n ; n = n->next) { - if (n->name) { - if (idx-- == 0) { - return Notation(n); - } - } - } - return Notation(); -} - -std::vector<Notation> Context::signatureNotations() const -{ - std::vector<Notation> result; - for (gpgme_sig_notation_t n = gpgme_sig_notation_get(d->ctx) ; n ; n = n->next) { - if (n->name) { - result.push_back(Notation(n)); - } - } - return result; -} - -static gpgme_sig_mode_t sigflags2sigflags(SignatureMode flags) -{ - unsigned int result = 0; - if (flags & SignatureMode::NormalSignatureMode) { - result |= GPGME_SIG_MODE_NORMAL; - } - if (flags & SignatureMode::Detached) { - result |= GPGME_SIG_MODE_DETACH; - } - if (flags & SignatureMode::Clearsigned) { - result |= GPGME_SIG_MODE_CLEAR; - } - if (flags & SignatureMode::SignArchive) { - result |= GPGME_SIG_MODE_ARCHIVE; - } - if (flags & SignatureMode::SignFile) { - result |= GPGME_SIG_MODE_FILE; - } - return static_cast<gpgme_sig_mode_t>(result); -} - -SigningResult Context::sign(const Data &plainText, Data &signature, SignatureMode mode) -{ - d->lastop = Private::Sign; - const Data::Private *const pdp = plainText.impl(); - Data::Private *const sdp = signature.impl(); - d->lasterr = gpgme_op_sign(d->ctx, pdp ? pdp->data : nullptr, sdp ? sdp->data : nullptr, sigflags2sigflags(mode)); - return SigningResult(d->ctx, Error(d->lasterr)); -} - -Error Context::startSigning(const Data &plainText, Data &signature, SignatureMode mode) -{ - d->lastop = Private::Sign; - const Data::Private *const pdp = plainText.impl(); - Data::Private *const sdp = signature.impl(); - return Error(d->lasterr = gpgme_op_sign_start(d->ctx, pdp ? pdp->data : nullptr, sdp ? sdp->data : nullptr, sigflags2sigflags(mode))); -} - -SigningResult Context::signingResult() const -{ - if (d->lastop & Private::Sign) { - return SigningResult(d->ctx, Error(d->lasterr)); - } else { - return SigningResult(); - } -} - -static gpgme_encrypt_flags_t encryptflags2encryptflags(Context::EncryptionFlags flags) -{ - unsigned int result = 0; - if (flags & Context::AlwaysTrust) { - result |= GPGME_ENCRYPT_ALWAYS_TRUST; - } - if (flags & Context::NoEncryptTo) { - result |= GPGME_ENCRYPT_NO_ENCRYPT_TO; - } - if (flags & Context::Prepare) { - result |= GPGME_ENCRYPT_PREPARE; - } - if (flags & Context::ExpectSign) { - result |= GPGME_ENCRYPT_EXPECT_SIGN; - } - if (flags & Context::NoCompress) { - result |= GPGME_ENCRYPT_NO_COMPRESS; - } - if (flags & Context::Symmetric) { - result |= GPGME_ENCRYPT_SYMMETRIC; - } - if (flags & Context::ThrowKeyIds) { - result |= GPGME_ENCRYPT_THROW_KEYIDS; - } - if (flags & Context::EncryptWrap) { - result |= GPGME_ENCRYPT_WRAP; - } - if (flags & Context::WantAddress) { - result |= GPGME_ENCRYPT_WANT_ADDRESS; - } - if (flags & Context::EncryptArchive) { - result |= GPGME_ENCRYPT_ARCHIVE; - } - if (flags & Context::EncryptFile) { - result |= GPGME_ENCRYPT_FILE; - } - return static_cast<gpgme_encrypt_flags_t>(result); -} - -gpgme_key_t *Context::getKeysFromRecipients(const std::vector<Key> &recipients) -{ - if (recipients.empty()) { - return nullptr; - } - gpgme_key_t *ret = new gpgme_key_t[ recipients.size() + 1 ]; - gpgme_key_t *keys_it = ret; - for (std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it) { - if (it->impl()) { - *keys_it++ = it->impl(); - } - } - *keys_it++ = nullptr; - return ret; -} - -EncryptionResult Context::encrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags) -{ - d->lastop = Private::Encrypt; - if (flags & NoEncryptTo) { - return EncryptionResult(Error(d->lasterr = make_error(GPG_ERR_NOT_IMPLEMENTED))); - } - const Data::Private *const pdp = plainText.impl(); - Data::Private *const cdp = cipherText.impl(); - gpgme_key_t *const keys = getKeysFromRecipients(recipients); - d->lasterr = gpgme_op_encrypt(d->ctx, keys, encryptflags2encryptflags(flags), - pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr); - if (keys) { - delete[] keys; - } - return EncryptionResult(d->ctx, Error(d->lasterr)); -} - -Error Context::encryptSymmetrically(const Data &plainText, Data &cipherText) -{ - d->lastop = Private::Encrypt; - const Data::Private *const pdp = plainText.impl(); - Data::Private *const cdp = cipherText.impl(); - return Error(d->lasterr = gpgme_op_encrypt(d->ctx, nullptr, (gpgme_encrypt_flags_t)0, - pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr)); -} - -Error Context::startEncryption(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags) -{ - d->lastop = Private::Encrypt; - if (flags & NoEncryptTo) { - return Error(d->lasterr = make_error(GPG_ERR_NOT_IMPLEMENTED)); - } - const Data::Private *const pdp = plainText.impl(); - Data::Private *const cdp = cipherText.impl(); - gpgme_key_t *const keys = getKeysFromRecipients(recipients); - d->lasterr = gpgme_op_encrypt_start(d->ctx, keys, encryptflags2encryptflags(flags), - pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr); - if (keys) { - delete[] keys; - } - return Error(d->lasterr); -} - -EncryptionResult Context::encryptionResult() const -{ - if (d->lastop & Private::Encrypt) { - return EncryptionResult(d->ctx, Error(d->lasterr)); - } else { - return EncryptionResult(); - } -} - -std::pair<SigningResult, EncryptionResult> Context::signAndEncrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags) -{ - d->lastop = Private::SignAndEncrypt; - const Data::Private *const pdp = plainText.impl(); - Data::Private *const cdp = cipherText.impl(); - gpgme_key_t *const keys = getKeysFromRecipients(recipients); - d->lasterr = gpgme_op_encrypt_sign(d->ctx, keys, encryptflags2encryptflags(flags), - pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr); - if (keys) { - delete[] keys; - } - return std::make_pair(SigningResult(d->ctx, Error(d->lasterr)), - EncryptionResult(d->ctx, Error(d->lasterr))); -} - -Error Context::startCombinedSigningAndEncryption(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags) -{ - d->lastop = Private::SignAndEncrypt; - const Data::Private *const pdp = plainText.impl(); - Data::Private *const cdp = cipherText.impl(); - gpgme_key_t *const keys = getKeysFromRecipients(recipients); - d->lasterr = gpgme_op_encrypt_sign_start(d->ctx, keys, encryptflags2encryptflags(flags), - pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr); - if (keys) { - delete[] keys; - } - return Error(d->lasterr); -} - -Error Context::createVFS(const char *containerFile, const std::vector< Key > &recipients) -{ - d->lastop = Private::CreateVFS; - gpgme_key_t *const keys = new gpgme_key_t[ recipients.size() + 1 ]; - gpgme_key_t *keys_it = keys; - for (std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it) { - if (it->impl()) { - *keys_it++ = it->impl(); - } - } - *keys_it++ = nullptr; - - gpgme_error_t op_err; - d->lasterr = gpgme_op_vfs_create(d->ctx, keys, containerFile, 0, &op_err); - delete[] keys; - Error error(d->lasterr); - if (error) { - return error; - } - return Error(d->lasterr = op_err); -} - -VfsMountResult Context::mountVFS(const char *containerFile, const char *mountDir) -{ - d->lastop = Private::MountVFS; - gpgme_error_t op_err; - d->lasterr = gpgme_op_vfs_mount(d->ctx, containerFile, mountDir, 0, &op_err); - return VfsMountResult(d->ctx, Error(d->lasterr), Error(op_err)); -} - -Error Context::cancelPendingOperation() -{ - return Error(gpgme_cancel_async(d->ctx)); -} - -Error Context::cancelPendingOperationImmediately() -{ - return Error(gpgme_cancel(d->ctx)); -} - -bool Context::poll() -{ - gpgme_error_t e = GPG_ERR_NO_ERROR; - const bool finished = gpgme_wait(d->ctx, &e, 0); - if (finished) { - d->lasterr = e; - } - return finished; -} - -Error Context::wait() -{ - gpgme_error_t e = GPG_ERR_NO_ERROR; - gpgme_wait(d->ctx, &e, 1); - return Error(d->lasterr = e); -} - -Error Context::lastError() const -{ - return Error(d->lasterr); -} - -Context::PinentryMode Context::pinentryMode() const -{ - switch (gpgme_get_pinentry_mode (d->ctx)) { - case GPGME_PINENTRY_MODE_ASK: - return PinentryAsk; - case GPGME_PINENTRY_MODE_CANCEL: - return PinentryCancel; - case GPGME_PINENTRY_MODE_ERROR: - return PinentryError; - case GPGME_PINENTRY_MODE_LOOPBACK: - return PinentryLoopback; - case GPGME_PINENTRY_MODE_DEFAULT: - default: - return PinentryDefault; - } -} - -Error Context::setPinentryMode(PinentryMode which) -{ - gpgme_pinentry_mode_t mode; - switch (which) { - case PinentryAsk: - mode = GPGME_PINENTRY_MODE_ASK; - break; - case PinentryCancel: - mode = GPGME_PINENTRY_MODE_CANCEL; - break; - case PinentryError: - mode = GPGME_PINENTRY_MODE_ERROR; - break; - case PinentryLoopback: - mode = GPGME_PINENTRY_MODE_LOOPBACK; - break; - case PinentryDefault: - default: - mode = GPGME_PINENTRY_MODE_DEFAULT; - } - return Error(d->lasterr = gpgme_set_pinentry_mode(d->ctx, mode)); -} - -static gpgme_tofu_policy_t to_tofu_policy_t(unsigned int policy) -{ - switch (policy) { - case TofuInfo::PolicyNone: - return GPGME_TOFU_POLICY_NONE; - case TofuInfo::PolicyAuto: - return GPGME_TOFU_POLICY_AUTO; - case TofuInfo::PolicyGood: - return GPGME_TOFU_POLICY_GOOD; - case TofuInfo::PolicyBad: - return GPGME_TOFU_POLICY_BAD; - case TofuInfo::PolicyAsk: - return GPGME_TOFU_POLICY_ASK; - case TofuInfo::PolicyUnknown: - default: - return GPGME_TOFU_POLICY_UNKNOWN; - } -} - -Error Context::setTofuPolicy(const Key &k, unsigned int policy) -{ - return Error(d->lasterr = gpgme_op_tofu_policy(d->ctx, - k.impl(), to_tofu_policy_t(policy))); -} - -Error Context::setTofuPolicyStart(const Key &k, unsigned int policy) -{ - return Error(d->lasterr = gpgme_op_tofu_policy_start(d->ctx, - k.impl(), to_tofu_policy_t(policy))); -} - -Error Context::startCreateKey (const char *userid, - const char *algo, - unsigned long reserved, - unsigned long expires, - const Key &certkey, - unsigned int flags) -{ - return Error(d->lasterr = gpgme_op_createkey_start(d->ctx, - userid, - algo, - reserved, - expires, - certkey.impl(), - flags)); -} - -Error Context::createKey (const char *userid, - const char *algo, - unsigned long reserved, - unsigned long expires, - const Key &certkey, - unsigned int flags) -{ - return Error(d->lasterr = gpgme_op_createkey(d->ctx, - userid, - algo, - reserved, - expires, - certkey.impl(), - flags)); -} - -KeyGenerationResult Context::createKeyEx (const char *userid, - const char *algo, - unsigned long reserved, - unsigned long expires, - const Key &certkey, - unsigned int flags) -{ - d->lasterr = gpgme_op_createkey(d->ctx, - userid, - algo, - reserved, - expires, - certkey.impl(), - flags); - return KeyGenerationResult(d->ctx, Error(d->lasterr)); -} - -Error Context::addUid(const Key &k, const char *userid) -{ - return Error(d->lasterr = gpgme_op_adduid(d->ctx, - k.impl(), userid, 0)); -} - -Error Context::startAddUid(const Key &k, const char *userid) -{ - return Error(d->lasterr = gpgme_op_adduid_start(d->ctx, - k.impl(), userid, 0)); -} - -Error Context::revUid(const Key &k, const char *userid) -{ - return Error(d->lasterr = gpgme_op_revuid(d->ctx, - k.impl(), userid, 0)); -} - -Error Context::startRevUid(const Key &k, const char *userid) -{ - return Error(d->lasterr = gpgme_op_revuid_start(d->ctx, - k.impl(), userid, 0)); -} - -Error Context::setPrimaryUid(const Key &k, const char *userid) -{ - return Error(d->lasterr = gpgme_op_set_uid_flag(d->ctx, k.impl(), userid, "primary", nullptr)); -} - -Error Context::startSetPrimaryUid(const Key &k, const char *userid) -{ - return Error(d->lasterr = gpgme_op_set_uid_flag_start(d->ctx, k.impl(), userid, "primary", nullptr)); -} - -Error Context::createSubkey(const Key &k, const char *algo, - unsigned long reserved, - unsigned long expires, - unsigned int flags) -{ - return Error(d->lasterr = gpgme_op_createsubkey(d->ctx, - k.impl(), algo, reserved, expires, flags)); -} - -Error Context::startCreateSubkey(const Key &k, const char *algo, - unsigned long reserved, - unsigned long expires, - unsigned int flags) -{ - return Error(d->lasterr = gpgme_op_createsubkey_start(d->ctx, - k.impl(), algo, reserved, expires, flags)); -} - -static std::string getLFSeparatedListOfStrings(const std::vector<std::string> &strings) -{ - if (strings.empty()) { - return std::string(); - } - - return std::accumulate( - std::next(strings.begin()), - strings.end(), - strings[0], - [](const std::string &a, const std::string &b) { - return a + '\n' + b; - } - ); -} - -static std::string getLFSeparatedListOfFingerprintsFromSubkeys(const std::vector<Subkey> &subkeys) -{ - if (subkeys.empty()) { - return std::string(); - } - - std::vector<std::string> fprs; - fprs.reserve(subkeys.size()); - for (auto &it : subkeys) { - if (it.fingerprint()) { - fprs.push_back(std::string(it.fingerprint())); - } - } - - return getLFSeparatedListOfStrings(fprs); -} - -Error Context::setExpire(const Key &k, unsigned long expires, - const std::vector<Subkey> &subkeys, - const Context::SetExpireFlags flags) -{ - std::string subfprs; - if (flags & Context::SetExpireAllSubkeys) { - subfprs = "*"; - } else { - subfprs = getLFSeparatedListOfFingerprintsFromSubkeys(subkeys); - } - return Error(d->lasterr = gpgme_op_setexpire(d->ctx, - k.impl(), expires, subfprs.c_str(), 0)); -} - -Error Context::startSetExpire(const Key &k, unsigned long expires, - const std::vector<Subkey> &subkeys, - const Context::SetExpireFlags flags) -{ - std::string subfprs; - if (flags & Context::SetExpireAllSubkeys) { - subfprs = "*"; - } else { - subfprs = getLFSeparatedListOfFingerprintsFromSubkeys(subkeys); - } - return Error(d->lasterr = gpgme_op_setexpire_start(d->ctx, - k.impl(), expires, subfprs.c_str(), 0)); -} - -static const char *owner_trust_to_string(Key::OwnerTrust trust) -{ - static const char *const owner_trust_strings[] = { - "undefined", // --quick-set-ownertrust wants "undefined" for Unknown - "undefined", // Undefined is never used for key->owner_trust - "never", - "marginal", - "full", - "ultimate", - }; - - if (Key::OwnerTrust::Unknown <= trust && trust <= Key::OwnerTrust::Ultimate) { - return owner_trust_strings[trust]; - } - return nullptr; -} - -Error Context::setOwnerTrust(const Key &key, Key::OwnerTrust trust) -{ - d->lasterr = gpgme_op_setownertrust(d->ctx, key.impl(), - owner_trust_to_string(trust)); - return Error(d->lasterr); -} - -Error Context::startSetOwnerTrust(const Key &key, Key::OwnerTrust trust) -{ - d->lasterr = gpgme_op_setownertrust_start(d->ctx, key.impl(), - owner_trust_to_string(trust)); - return Error(d->lasterr); -} - -Error Context::setKeyEnabled(const Key &key, bool enabled) -{ - d->lasterr = gpgme_op_setownertrust(d->ctx, key.impl(), - enabled ? "enable" : "disable"); - return Error(d->lasterr); -} - -Error Context::startSetKeyEnabled(const Key &key, bool enabled) -{ - d->lasterr = gpgme_op_setownertrust_start(d->ctx, key.impl(), - enabled ? "enable" : "disable"); - return Error(d->lasterr); -} - -static std::string getLFSeparatedListOfUserIds(const std::vector<UserID> &userIds) -{ - if (userIds.empty()) { - return std::string(); - } - - std::vector<std::string> uids; - uids.reserve(userIds.size()); - for (auto &userId : userIds) { - if (userId.id()) { - uids.push_back(std::string(userId.id())); - } - } - - return getLFSeparatedListOfStrings(uids); -} - -Error Context::revokeSignature(const Key &key, const Key &signingKey, - const std::vector<UserID> &userIds) -{ - const unsigned int flags = userIds.size() > 1 ? GPGME_REVSIG_LFSEP : 0; - const std::string uids = getLFSeparatedListOfUserIds(userIds); - return Error(d->lasterr = gpgme_op_revsig(d->ctx, - key.impl(), signingKey.impl(), uids.c_str(), flags)); -} - -Error Context::startRevokeSignature(const Key &key, const Key &signingKey, - const std::vector<UserID> &userIds) -{ - const unsigned int flags = userIds.size() > 1 ? GPGME_REVSIG_LFSEP : 0; - const std::string uids = getLFSeparatedListOfUserIds(userIds); - return Error(d->lasterr = gpgme_op_revsig_start(d->ctx, - key.impl(), signingKey.impl(), uids.c_str(), flags)); -} - -Error Context::addAdsk(const Key &k, const char *adsk) -{ - return Error(d->lasterr = gpgme_op_createsubkey(d->ctx, k.impl(), adsk, 0, 0, GPGME_CREATE_ADSK)); -} - -Error Context::startAddAdsk(const Key &k, const char *adsk) -{ - return Error(d->lasterr = gpgme_op_createsubkey_start(d->ctx, k.impl(), adsk, 0, 0, GPGME_CREATE_ADSK)); -} - -Error Context::setFlag(const char *name, const char *value) -{ - return Error(d->lasterr = gpgme_set_ctx_flag(d->ctx, name, value)); -} - -const char *Context::getFlag(const char *name) const -{ - return gpgme_get_ctx_flag(d->ctx, name); -} - -// Engine Spawn stuff -Error Context::spawn(const char *file, const char *argv[], - Data &input, Data &output, Data &err, - SpawnFlags flags) -{ - return Error(d->lasterr = gpgme_op_spawn (d->ctx, file, argv, - input.impl() ? input.impl()->data : nullptr, - output.impl() ? output.impl()->data : nullptr, - err.impl() ? err.impl()->data : nullptr, - static_cast<int>(flags))); -} - -Error Context::spawnAsync(const char *file, const char *argv[], - Data &input, Data &output, Data &err, - SpawnFlags flags) -{ - return Error(d->lasterr = gpgme_op_spawn_start (d->ctx, file, argv, - input.impl() ? input.impl()->data : nullptr, - output.impl() ? output.impl()->data : nullptr, - err.impl() ? err.impl()->data : nullptr, - static_cast<int>(flags))); -} - -std::ostream &operator<<(std::ostream &os, Protocol proto) -{ - os << "GpgME::Protocol("; - switch (proto) { - case OpenPGP: - os << "OpenPGP"; - break; - case CMS: - os << "CMS"; - break; - default: - case UnknownProtocol: - os << "UnknownProtocol"; - break; - } - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, Engine eng) -{ - os << "GpgME::Engine("; - switch (eng) { - case GpgEngine: - os << "GpgEngine"; - break; - case GpgSMEngine: - os << "GpgSMEngine"; - break; - case GpgConfEngine: - os << "GpgConfEngine"; - break; - case AssuanEngine: - os << "AssuanEngine"; - break; - case SpawnEngine: - os << "SpawnEngine"; - break; - default: - case UnknownEngine: - os << "UnknownEngine"; - break; - } - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, Context::CertificateInclusion incl) -{ - os << "GpgME::Context::CertificateInclusion(" << static_cast<int>(incl); - switch (incl) { - case Context::DefaultCertificates: - os << "(DefaultCertificates)"; - break; - case Context::AllCertificatesExceptRoot: - os << "(AllCertificatesExceptRoot)"; - break; - case Context::AllCertificates: - os << "(AllCertificates)"; - break; - case Context::NoCertificates: - os << "(NoCertificates)"; - break; - case Context::OnlySenderCertificate: - os << "(OnlySenderCertificate)"; - break; - } - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, KeyListMode mode) -{ - os << "GpgME::KeyListMode("; -#define CHECK( x ) if ( !(mode & (x)) ) {} else do { os << #x " "; } while (0) - CHECK(Local); - CHECK(Extern); - CHECK(Signatures); - CHECK(Validate); - CHECK(Ephemeral); - CHECK(WithTofu); - CHECK(WithKeygrip); - CHECK(WithSecret); - CHECK(ForceExtern); -#undef CHECK - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, SignatureMode mode) -{ - os << "GpgME::SignatureMode("; -#undef CHECK - switch (mode & (NormalSignatureMode|Detached|Clearsigned)) { -#define CHECK( x ) case x: os << #x; break - CHECK(NormalSignatureMode); - CHECK(Detached); - CHECK(Clearsigned); -#undef CHECK - default: - os << "???" "(" << static_cast<int>(mode) << ')'; - break; - } -#define CHECK( x ) if ( !(mode & (x)) ) {} else do { os << #x " "; } while (0) - CHECK(SignArchive); - CHECK(SignFile); -#undef CHECK - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, Context::EncryptionFlags flags) -{ - os << "GpgME::Context::EncryptionFlags("; -#define CHECK( x ) if ( !(flags & (Context::x)) ) {} else do { os << #x " "; } while (0) - CHECK(AlwaysTrust); - CHECK(NoEncryptTo); - CHECK(Prepare); - CHECK(ExpectSign); - CHECK(NoCompress); - CHECK(Symmetric); - CHECK(ThrowKeyIds); - CHECK(EncryptWrap); - CHECK(WantAddress); - CHECK(EncryptArchive); - CHECK(EncryptFile); -#undef CHECK - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, Context::AuditLogFlags flags) -{ - os << "GpgME::Context::AuditLogFlags("; -#define CHECK( x ) if ( !(flags & (Context::x)) ) {} else do { os << #x " "; } while (0) - CHECK(HtmlAuditLog); - CHECK(AuditLogWithHelp); -#undef CHECK - return os << ')'; -} - -} // namespace GpgME - -GpgME::Error GpgME::setDefaultLocale(int cat, const char *val) -{ - return Error(gpgme_set_locale(nullptr, cat, val)); -} - -GpgME::EngineInfo GpgME::engineInfo(GpgME::Protocol proto) -{ - return get_static_engine_info(proto == CMS ? GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP); -} - -const char *GpgME::dirInfo(const char *what) -{ - return gpgme_get_dirinfo(what); -} - -GpgME::Error GpgME::checkEngine(GpgME::Protocol proto) -{ - const gpgme_protocol_t p = proto == CMS ? GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP ; - - return Error(gpgme_engine_check_version(p)); -} - -static const gpgme_protocol_t UNKNOWN_PROTOCOL = static_cast<gpgme_protocol_t>(255); - -static gpgme_protocol_t engine2protocol(const GpgME::Engine engine) -{ - switch (engine) { - case GpgME::GpgEngine: return GPGME_PROTOCOL_OpenPGP; - case GpgME::GpgSMEngine: return GPGME_PROTOCOL_CMS; - case GpgME::GpgConfEngine: - return GPGME_PROTOCOL_GPGCONF; - case GpgME::AssuanEngine: - return GPGME_PROTOCOL_ASSUAN; - case GpgME::G13Engine: - return GPGME_PROTOCOL_G13; - case GpgME::SpawnEngine: - return GPGME_PROTOCOL_SPAWN; - case GpgME::UnknownEngine: - ; - } - return UNKNOWN_PROTOCOL; -} - -GpgME::EngineInfo GpgME::engineInfo(GpgME::Engine engine) -{ - return get_static_engine_info(engine2protocol(engine)); -} - -GpgME::Error GpgME::checkEngine(GpgME::Engine engine) -{ - const gpgme_protocol_t p = engine2protocol(engine); - - return Error(gpgme_engine_check_version(p)); -} - -static const unsigned long supported_features = 0 - | GpgME::ValidatingKeylistModeFeature - | GpgME::CancelOperationFeature - | GpgME::WrongKeyUsageFeature - | GpgME::DefaultCertificateInclusionFeature - | GpgME::GetSetEngineInfoFeature - | GpgME::ClearAddGetSignatureNotationsFeature - | GpgME::SetDataFileNameFeeature - | GpgME::SignatureNotationsKeylistModeFeature - | GpgME::KeySignatureNotationsFeature - | GpgME::KeyIsQualifiedFeature - | GpgME::SignatureNotationsCriticalFlagFeature - | GpgME::SignatureNotationsFlagsFeature - | GpgME::SignatureNotationsHumanReadableFlagFeature - | GpgME::SubkeyIsQualifiedFeature - | GpgME::EngineInfoHomeDirFeature - | GpgME::DecryptionResultFileNameFeature - | GpgME::DecryptionResultRecipientsFeature - | GpgME::VerificationResultFileNameFeature - | GpgME::SignaturePkaFieldsFeature - | GpgME::SignatureAlgorithmFieldsFeature - | GpgME::FdPointerFeature - | GpgME::AuditLogFeature - | GpgME::GpgConfEngineFeature - | GpgME::CancelOperationAsyncFeature - | GpgME::NoEncryptToEncryptionFlagFeature - | GpgME::CardKeyFeature - | GpgME::AssuanEngineFeature - | GpgME::EphemeralKeylistModeFeature - | GpgME::ImportFromKeyserverFeature - | GpgME::G13VFSFeature - | GpgME::PasswdFeature - ; - -static const unsigned long supported_features2 = 0 - | GpgME::BinaryAndFineGrainedIdentify - ; - -bool GpgME::hasFeature(unsigned long features) -{ - return features == (features & supported_features); -} - -bool GpgME::hasFeature(unsigned long features, unsigned long features2) -{ - return features == (features & supported_features) - && features2 == (features2 & supported_features2) - ; -} - -int GpgME::setGlobalFlag(const char *name, const char *value) -{ - return gpgme_set_global_flag(name, value); -} diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h deleted file mode 100644 index e2c73b64..00000000 --- a/lang/cpp/src/context.h +++ /dev/null @@ -1,586 +0,0 @@ -/* - context.h - wraps a gpgme key context - Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_CONTEXT_H__ -#define __GPGMEPP_CONTEXT_H__ - -#include "global.h" - -#include "error.h" -#include "key.h" -#include "verificationresult.h" // for Signature::Notation - -#include <memory> -#include <string> -#include <vector> -#include <utility> -#include <iosfwd> - -namespace GpgME -{ - -class Data; -class TrustItem; -class ProgressProvider; -class PassphraseProvider; -class EventLoopInteractor; -class EditInteractor; -class AssuanTransaction; - -class KeyListResult; -class KeyGenerationResult; -class ImportResult; -class DecryptionResult; -class VerificationResult; -class SigningResult; -class EncryptionResult; -class VfsMountResult; - -class EngineInfo; - -class GPGMEPP_EXPORT Context -{ - explicit Context(gpgme_ctx_t); -public: - //using GpgME::Protocol; - - /// RAII-style class for saving/restoring the key list mode. - class GPGMEPP_EXPORT KeyListModeSaver - { - public: - explicit KeyListModeSaver(Context *ctx); - ~KeyListModeSaver(); - private: - Context *mCtx; - unsigned int mKeyListMode; - }; - - // - // Creation and destruction: - // - - static Context *createForProtocol(Protocol proto); - /** Same as above but returning a unique ptr. */ - static std::unique_ptr<Context> create(Protocol proto); - static std::unique_ptr<Context> createForEngine(Engine engine, Error *err = nullptr); - virtual ~Context(); - - // - // Context Attributes - // - - Protocol protocol() const; - - void setArmor(bool useArmor); - bool armor() const; - - void setTextMode(bool useTextMode); - bool textMode() const; - - void setOffline(bool useOfflineMode); - bool offline() const; - - const char *getFlag(const char *name) const; - Error setFlag(const char *name, const char *value); - - enum CertificateInclusion { - DefaultCertificates = -256, - AllCertificatesExceptRoot = -2, - AllCertificates = -1, - NoCertificates = 0, - OnlySenderCertificate = 1 - }; - void setIncludeCertificates(int which); - int includeCertificates() const; - - //using GpgME::KeyListMode; - void setKeyListMode(unsigned int keyListMode); - void addKeyListMode(unsigned int keyListMode); - unsigned int keyListMode() const; - - /** Set the passphrase provider - * - * To avoid problems where a class using a context registers - * itself as the provider the Context does not take ownership - * of the provider and the caller must ensure that the provider - * is deleted if it is no longer needed. - */ - void setPassphraseProvider(PassphraseProvider *provider); - PassphraseProvider *passphraseProvider() const; - - /** Set the progress provider - * - * To avoid problems where a class using a context registers - * itself as the provider the Context does not take ownership - * of the provider and the caller must ensure that the provider - * is deleted if it is no longer needed. - */ - void setProgressProvider(ProgressProvider *provider); - ProgressProvider *progressProvider() const; - - void setManagedByEventLoopInteractor(bool managed); - bool managedByEventLoopInteractor() const; - - GpgME::Error setLocale(int category, const char *value); - - EngineInfo engineInfo() const; - GpgME::Error setEngineFileName(const char *filename); - GpgME::Error setEngineHomeDirectory(const char *filename); - - enum PinentryMode{ - PinentryDefault = 0, - PinentryAsk = 1, - PinentryCancel = 2, - PinentryError = 3, - PinentryLoopback = 4 - }; - GpgME::Error setPinentryMode(PinentryMode which); - PinentryMode pinentryMode() const; - -private: - friend class ::GpgME::EventLoopInteractor; - void installIOCallbacks(gpgme_io_cbs *iocbs); - void uninstallIOCallbacks(); - -public: - // - // - // Key Management - // - // - - // - // Key Listing - // - - GpgME::Error startKeyListing(const char *pattern = nullptr, bool secretOnly = false); - GpgME::Error startKeyListing(const char *patterns[], bool secretOnly = false); - - Key nextKey(GpgME::Error &e); - - KeyListResult endKeyListing(); - KeyListResult keyListResult() const; - - Key key(const char *fingerprint, GpgME::Error &e, bool secret = false); - - // - // Key Generation - // - - KeyGenerationResult generateKey(const char *parameters, Data &pubKey); - GpgME::Error startKeyGeneration(const char *parameters, Data &pubkey); - KeyGenerationResult keyGenerationResult() const; - - // - // Key Export - // - enum ExportMode { - ExportDefault = 0, - ExportExtern = 2, - ExportMinimal = 4, - ExportSecret = 16, - ExportRaw = 32, - ExportPKCS12 = 64, - ExportNoUID = 128, // obsolete; has no effect - ExportSSH = 256, - ExportSecretSubkey = 512, - }; - - GpgME::Error exportPublicKeys(const char *pattern, Data &keyData); - GpgME::Error exportPublicKeys(const char *pattern, Data &keyData, unsigned int mode); - GpgME::Error exportPublicKeys(const char *pattern[], Data &keyData); - GpgME::Error exportPublicKeys(const char *pattern[], Data &keyData, unsigned int mode); - GpgME::Error startPublicKeyExport(const char *pattern, Data &keyData); - GpgME::Error startPublicKeyExport(const char *pattern, Data &keyData, unsigned int mode); - GpgME::Error startPublicKeyExport(const char *pattern[], Data &keyData); - GpgME::Error startPublicKeyExport(const char *pattern[], Data &keyData, unsigned int mode); - - GpgME::Error exportSecretKeys(const char *pattern, Data &keyData, unsigned int mode = ExportSecret); - GpgME::Error exportSecretKeys(const char *pattern[], Data &keyData, unsigned int mode = ExportSecret); - GpgME::Error startSecretKeyExport(const char *pattern, Data &keyData, unsigned int mode = ExportSecret); - GpgME::Error startSecretKeyExport(const char *pattern[], Data &keyData, unsigned int mode = ExportSecret); - - GpgME::Error exportSecretSubkeys(const char *pattern, Data &keyData, unsigned int mode = ExportSecretSubkey); - GpgME::Error exportSecretSubkeys(const char *pattern[], Data &keyData, unsigned int mode = ExportSecretSubkey); - GpgME::Error startSecretSubkeyExport(const char *pattern, Data &keyData, unsigned int mode = ExportSecretSubkey); - GpgME::Error startSecretSubkeyExport(const char *pattern[], Data &keyData, unsigned int mode = ExportSecretSubkey); - - // generic export functions; prefer using the specific public/secret key export functions - GpgME::Error exportKeys(const char *pattern, Data &keyData, unsigned int mode = ExportDefault); - GpgME::Error exportKeys(const char *pattern[], Data &keyData, unsigned int mode = ExportDefault); - GpgME::Error startKeyExport(const char *pattern, Data &keyData, unsigned int mode = ExportDefault); - GpgME::Error startKeyExport(const char *pattern[], Data &keyData, unsigned int mode = ExportDefault); - - // - // Key Import - // - - ImportResult importKeys(const Data &data); - ImportResult importKeys(const std::vector<Key> &keys); - ImportResult importKeys(const std::vector<std::string> &keyIds); - GpgME::Error startKeyImport(const Data &data); - GpgME::Error startKeyImport(const std::vector<Key> &keys); - GpgME::Error startKeyImport(const std::vector<std::string> &keyIds); - ImportResult importResult() const; - - // - // Key Deletion - // - - GpgME::Error deleteKey(const Key &key, bool allowSecretKeyDeletion = false); - GpgME::Error startKeyDeletion(const Key &key, bool allowSecretKeyDeletion = false); - - // - // Passphrase changing - // - - GpgME::Error passwd(const Key &key); - GpgME::Error startPasswd(const Key &key); - - // - // Key Editing - // - - GpgME::Error edit(const Key &key, std::unique_ptr<EditInteractor> function, Data &out); - GpgME::Error startEditing(const Key &key, std::unique_ptr<EditInteractor> function, Data &out); - - - // - // Modern Interface actions. Require 2.1.x - // - Error startCreateKey (const char *userid, - const char *algo, - unsigned long reserved, - unsigned long expires, - const Key &certkey, - unsigned int flags); - Error createKey (const char *userid, - const char *algo, - unsigned long reserved, - unsigned long expires, - const Key &certkey, - unsigned int flags); - - // Same as create key but returning a result - GpgME::KeyGenerationResult createKeyEx (const char *userid, - const char *algo, - unsigned long reserved, - unsigned long expires, - const Key &certkey, - unsigned int flags); - - Error addUid(const Key &key, const char *userid); - Error startAddUid(const Key &key, const char *userid); - - Error revUid(const Key &key, const char *userid); - Error startRevUid(const Key &key, const char *userid); - - Error setPrimaryUid(const Key &key, const char *userid); - Error startSetPrimaryUid(const Key &key, const char *userid); - - Error createSubkey(const Key &key, const char *algo, - unsigned long reserved = 0, - unsigned long expires = 0, - unsigned int flags = 0); - Error startCreateSubkey(const Key &key, const char *algo, - unsigned long reserved = 0, - unsigned long expires = 0, - unsigned int flags = 0); - - enum SetExpireFlags { - SetExpireDefault = 0, - SetExpireAllSubkeys = 1 - }; - - Error setExpire(const Key &k, unsigned long expires, - const std::vector<Subkey> &subkeys = std::vector<Subkey>(), - const SetExpireFlags flags = SetExpireDefault); - Error startSetExpire(const Key &k, unsigned long expires, - const std::vector<Subkey> &subkeys = std::vector<Subkey>(), - const SetExpireFlags flags = SetExpireDefault); - - /** - * Sets the owner trust of the key \a key to the value \a trust. - * Requires gpg 2.4.6. - */ - Error setOwnerTrust(const Key &key, Key::OwnerTrust trust); - /** - * Starts the operation to set the owner trust of the key \a key to the value \a trust. - * Requires gpg 2.4.6. - */ - Error startSetOwnerTrust(const Key &key, Key::OwnerTrust trust); - - /** - * Enables or disables the key \a key. - * Requires gpg 2.4.6. - */ - Error setKeyEnabled(const Key &key, bool enabled); - /** - * Starts the operation to enable or disable the key \a key. - * Requires gpg 2.4.6. - */ - Error startSetKeyEnabled(const Key &key, bool enabled); - - Error revokeSignature(const Key &key, const Key &signingKey, - const std::vector<UserID> &userIds = std::vector<UserID>()); - Error startRevokeSignature(const Key &key, const Key &signingKey, - const std::vector<UserID> &userIds = std::vector<UserID>()); - - Error addAdsk(const Key &k, const char *adsk); - Error startAddAdsk(const Key &k, const char *adsk); - - // using TofuInfo::Policy - Error setTofuPolicy(const Key &k, unsigned int policy); - Error setTofuPolicyStart(const Key &k, unsigned int policy); - - EditInteractor *lastEditInteractor() const; - std::unique_ptr<EditInteractor> takeLastEditInteractor(); - - // - // SmartCard Editing - // - - GpgME::Error cardEdit(const Key &key, std::unique_ptr<EditInteractor> function, Data &out); - GpgME::Error startCardEditing(const Key &key, std::unique_ptr<EditInteractor> function, Data &out); - - EditInteractor *lastCardEditInteractor() const; - std::unique_ptr<EditInteractor> takeLastCardEditInteractor(); - - // - // Trust Item Management - // - - GpgME::Error startTrustItemListing(const char *pattern, int maxLevel); - TrustItem nextTrustItem(GpgME::Error &e); - GpgME::Error endTrustItemListing(); - - // - // Assuan Transactions - // - - GpgME::Error assuanTransact(const char *command, std::unique_ptr<AssuanTransaction> transaction); - GpgME::Error assuanTransact(const char *command); - GpgME::Error startAssuanTransaction(const char *command, std::unique_ptr<AssuanTransaction> transaction); - GpgME::Error startAssuanTransaction(const char *command); - - AssuanTransaction *lastAssuanTransaction() const; - std::unique_ptr<AssuanTransaction> takeLastAssuanTransaction(); - - // - // - // Crypto Operations - // - - enum DecryptionFlags { - // Keep in line with core's flags - DecryptNone = 0, - DecryptVerify = 1, - DecryptArchive = 2, - DecryptUnwrap = 128, - DecryptMaxValue = 0x80000000 - }; - - // - // Decryption - // - - // Alternative way to set decryption flags as they were added only in - // 1.9.0 and so other API can still be used but with 1.9.0 additionally - // flags can be set. - void setDecryptionFlags (const DecryptionFlags flags); - - DecryptionResult decrypt(const Data &cipherText, Data &plainText); - GpgME::Error startDecryption(const Data &cipherText, Data &plainText); - DecryptionResult decrypt(const Data &cipherText, Data &plainText, const DecryptionFlags flags); - GpgME::Error startDecryption(const Data &cipherText, Data &plainText, const DecryptionFlags flags); - DecryptionResult decryptionResult() const; - - // - // Signature Verification - // - - VerificationResult verifyDetachedSignature(const Data &signature, const Data &signedText); - VerificationResult verifyOpaqueSignature(const Data &signedData, Data &plainText); - GpgME::Error startDetachedSignatureVerification(const Data &signature, const Data &signedText); - GpgME::Error startOpaqueSignatureVerification(const Data &signedData, Data &plainText); - VerificationResult verificationResult() const; - - // - // Combined Decryption and Signature Verification - // - - std::pair<DecryptionResult, VerificationResult> decryptAndVerify(const Data &cipherText, Data &plainText); - std::pair<DecryptionResult, VerificationResult> decryptAndVerify(const Data &cipherText, Data &plainText, const DecryptionFlags flags); - GpgME::Error startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText); - GpgME::Error startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText, const DecryptionFlags flags); - // use verificationResult() and decryptionResult() to retrieve the result objects... - - // - // Signing - // - - void clearSigningKeys(); - GpgME::Error addSigningKey(const Key &signer); - Key signingKey(unsigned int index) const; - std::vector<Key> signingKeys() const; - - void clearSignatureNotations(); - GpgME::Error addSignatureNotation(const char *name, const char *value, unsigned int flags = 0); - GpgME::Error addSignaturePolicyURL(const char *url, bool critical = false); - const char *signaturePolicyURL() const; - Notation signatureNotation(unsigned int index) const; - std::vector<Notation> signatureNotations() const; - - //using GpgME::SignatureMode; - SigningResult sign(const Data &plainText, Data &signature, SignatureMode mode); - GpgME::Error startSigning(const Data &plainText, Data &signature, SignatureMode mode); - SigningResult signingResult() const; - - // wrapper for gpgme_set_sender - const char *getSender(); - GpgME::Error setSender(const char *sender); - - // - // Encryption - // - - enum EncryptionFlags { - None = 0, - AlwaysTrust = 1, - NoEncryptTo = 2, - Prepare = 4, - ExpectSign = 8, - NoCompress = 16, - Symmetric = 32, - ThrowKeyIds = 64, - EncryptWrap = 128, - WantAddress = 256, - EncryptArchive = 512, - EncryptFile = 1024 - }; - EncryptionResult encrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags); - GpgME::Error encryptSymmetrically(const Data &plainText, Data &cipherText); - GpgME::Error startEncryption(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags); - EncryptionResult encryptionResult() const; - - // - // Combined Signing and Encryption - // - - std::pair<SigningResult, EncryptionResult> signAndEncrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags); - GpgME::Error startCombinedSigningAndEncryption(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags); - // use encryptionResult() and signingResult() to retrieve the result objects... - - // - // - // Audit Log - // - // - enum AuditLogFlags { - DefaultAuditLog = 0, - HtmlAuditLog = 1, - DiagnosticAuditLog = 2, - AuditLogWithHelp = 128 - }; - GpgME::Error startGetAuditLog(Data &output, unsigned int flags = 0); - GpgME::Error getAuditLog(Data &output, unsigned int flags = 0); - - // - // - // G13 crypto container operations - // - // - GpgME::Error createVFS(const char *containerFile, const std::vector<Key> &recipients); - VfsMountResult mountVFS(const char *containerFile, const char *mountDir); - - // Spawn Engine - enum SpawnFlags { - SpawnNone = 0, - SpawnDetached = 1, - SpawnAllowSetFg = 2, - SpawnShowWindow = 4 - }; - /** Spwan the process \a file with arguments \a argv. - * - * If a data parameter is null the /dev/null will be - * used. (Or other platform stuff). - * - * @param file The executable to start. - * @param argv list of arguments file should be argv[0]. - * @param input The data to be sent through stdin. - * @param output The data to be receive the stdout. - * @param err The data to receive stderr. - * @param flags Additional flags. - * - * @returns An error or empty error. - */ - GpgME::Error spawn(const char *file, const char *argv[], - Data &input, Data &output, Data &err, - SpawnFlags flags); - /** Async variant of spawn. Immediately returns after starting the - * process. */ - GpgME::Error spawnAsync(const char *file, const char *argv[], - Data &input, Data &output, - Data &err, SpawnFlags flags); - // - // - // Run Control - // - // - - bool poll(); - GpgME::Error wait(); - GpgME::Error lastError() const; - GpgME::Error cancelPendingOperation(); - GpgME::Error cancelPendingOperationImmediately(); - - class Private; - const Private *impl() const - { - return d; - } - Private *impl() - { - return d; - } - -private: - // Helper functions that need to be context because they rely - // on the "Friendlyness" of context to access the gpgme types. - gpgme_key_t *getKeysFromRecipients(const std::vector<Key> &recipients); - -private: - Private *const d; - -private: // disable... - Context(const Context &); - const Context &operator=(const Context &); -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Context::CertificateInclusion incl); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Context::EncryptionFlags flags); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Context::AuditLogFlags flags); - -} // namespace GpgME - -#endif // __GPGMEPP_CONTEXT_H__ diff --git a/lang/cpp/src/context_p.h b/lang/cpp/src/context_p.h deleted file mode 100644 index 8782609c..00000000 --- a/lang/cpp/src/context_p.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - context_p.h - wraps a gpgme context (private part) - Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_CONTEXT_P_H__ -#define __GPGMEPP_CONTEXT_P_H__ - -#include <context.h> -#include <data.h> - -#include <gpgme.h> - -namespace GpgME -{ - -class Context::Private -{ -public: - enum Operation { - None = 0, - - Encrypt = 0x001, - Decrypt = 0x002, - Sign = 0x004, - Verify = 0x008, - DecryptAndVerify = Decrypt | Verify, - SignAndEncrypt = Sign | Encrypt, - - Import = 0x010, - Export = 0x020, // no gpgme_export_result_t, but nevertheless... - Delete = 0x040, // no gpgme_delete_result_t, but nevertheless... - - KeyGen = 0x080, - KeyList = 0x100, - KeyListWithImport = KeyList | Import, // gpgme_keylist_result_t and gpgme_import_result_t - TrustList = 0x200, // no gpgme_trustlist_result_t, but nevertheless... - - Edit = 0x400, // no gpgme_edit_result_t, but nevertheless... - CardEdit = 0x800, // no gpgme_card_edit_result_t, but nevertheless... - - GetAuditLog = 0x1000, // no gpgme_getauditlog_result_t, but nevertheless... - - AssuanTransact = 0x2000, - Passwd = 0x4000, // no gpgme_passwd_result_t, but nevertheless... - - CreateVFS = 0x4000, - MountVFS = 0x8000, - - EndMarker - }; - - Private(gpgme_ctx_t c = nullptr); - ~Private(); - - gpgme_ctx_t ctx; - gpgme_io_cbs *iocbs; - Operation lastop; - gpgme_error_t lasterr; - Data lastAssuanInquireData; - std::unique_ptr<AssuanTransaction> lastAssuanTransaction; - std::unique_ptr<EditInteractor> lastEditInteractor, lastCardEditInteractor; - DecryptionFlags decryptFlags; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_CONTEXT_P_H__ diff --git a/lang/cpp/src/context_vanilla.cpp b/lang/cpp/src/context_vanilla.cpp deleted file mode 100644 index 1d7d14d5..00000000 --- a/lang/cpp/src/context_vanilla.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - context_vanilla.cpp - wraps a gpgme key context, gpgme (vanilla)-specific functions - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <global.h> - -GIOChannel *GpgME::getGIOChannel(int) -{ - return nullptr; -} - -QIODevice *GpgME::getQIODevice(int) -{ - return nullptr; -} diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp deleted file mode 100644 index cf43b5bd..00000000 --- a/lang/cpp/src/data.cpp +++ /dev/null @@ -1,293 +0,0 @@ -/* - data.cpp - wraps a gpgme data object - Copyright (C) 2003 Klarälvdalens Datakonsult AB - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "data_p.h" -#include "context_p.h" -#include <error.h> -#include <interfaces/dataprovider.h> - -#include <gpgme.h> - -#ifndef NDEBUG -#include <iostream> -#endif - -GpgME::Data::Private::~Private() -{ - if (data) { - gpgme_data_release(data); - } -} - -const GpgME::Data::Null GpgME::Data::null; - -GpgME::Data::Data() -{ - gpgme_data_t data; - const gpgme_error_t e = gpgme_data_new(&data); - d.reset(new Private(e ? nullptr : data)); -} - -GpgME::Data::Data(const Null &) - : d(new Private(nullptr)) -{ - -} - -GpgME::Data::Data(gpgme_data_t data) - : d(new Private(data)) -{ - -} - -GpgME::Data::Data(const char *buffer, size_t size, bool copy) -{ - gpgme_data_t data; - const gpgme_error_t e = gpgme_data_new_from_mem(&data, buffer, size, int(copy)); - std::string sizestr = std::to_string(size); - // Ignore errors as this is optional - gpgme_data_set_flag(data, "size-hint", sizestr.c_str()); - d.reset(new Private(e ? nullptr : data)); -} - -GpgME::Data::Data(const char *filename) -{ - gpgme_data_t data; - const gpgme_error_t e = gpgme_data_new(&data); - d.reset(new Private(e ? nullptr : data)); - if (!e) { - setFileName(filename); - } -} - -GpgME::Data::Data(const char *filename, off_t offset, size_t length) -{ - gpgme_data_t data; - const gpgme_error_t e = gpgme_data_new_from_filepart(&data, filename, nullptr, offset, length); - d.reset(new Private(e ? nullptr : data)); -} - -GpgME::Data::Data(FILE *fp) -{ - gpgme_data_t data; - const gpgme_error_t e = gpgme_data_new_from_stream(&data, fp); - d.reset(new Private(e ? nullptr : data)); -} - -GpgME::Data::Data(FILE *fp, off_t offset, size_t length) -{ - gpgme_data_t data; - const gpgme_error_t e = gpgme_data_new_from_filepart(&data, nullptr, fp, offset, length); - d.reset(new Private(e ? nullptr : data)); -} - -GpgME::Data::Data(int fd) -{ - gpgme_data_t data; - const gpgme_error_t e = gpgme_data_new_from_fd(&data, fd); - d.reset(new Private(e ? nullptr : data)); -} - -GpgME::Data::Data(DataProvider *dp) -{ - d.reset(new Private); - if (!dp) { - return; - } - if (!dp->isSupported(DataProvider::Read)) { - d->cbs.read = nullptr; - } - if (!dp->isSupported(DataProvider::Write)) { - d->cbs.write = nullptr; - } - if (!dp->isSupported(DataProvider::Seek)) { - d->cbs.seek = nullptr; - } - if (!dp->isSupported(DataProvider::Release)) { - d->cbs.release = nullptr; - } - const gpgme_error_t e = gpgme_data_new_from_cbs(&d->data, &d->cbs, dp); - if (e) { - d->data = nullptr; - } - if (dp->isSupported(DataProvider::Seek)) { - off_t size = seek(0, SEEK_END); - seek(0, SEEK_SET); - std::string sizestr = std::to_string(size); - // Ignore errors as this is optional - gpgme_data_set_flag(d->data, "size-hint", sizestr.c_str()); - } -#ifndef NDEBUG - //std::cerr << "GpgME::Data(): DataProvider supports: " - // << ( d->cbs.read ? "read" : "no read" ) << ", " - // << ( d->cbs.write ? "write" : "no write" ) << ", " - // << ( d->cbs.seek ? "seek" : "no seek" ) << ", " - // << ( d->cbs.release ? "release" : "no release" ) << std::endl; -#endif -} - -bool GpgME::Data::isNull() const -{ - return !d || !d->data; -} - -GpgME::Data::Encoding GpgME::Data::encoding() const -{ - switch (gpgme_data_get_encoding(d->data)) { - case GPGME_DATA_ENCODING_NONE: return AutoEncoding; - case GPGME_DATA_ENCODING_BINARY: return BinaryEncoding; - case GPGME_DATA_ENCODING_BASE64: return Base64Encoding; - case GPGME_DATA_ENCODING_ARMOR: return ArmorEncoding; - case GPGME_DATA_ENCODING_MIME: return MimeEncoding; - case GPGME_DATA_ENCODING_URL: return UrlEncoding; - case GPGME_DATA_ENCODING_URLESC: return UrlEscEncoding; - case GPGME_DATA_ENCODING_URL0: return Url0Encoding; - } - return AutoEncoding; -} - -GpgME::Error GpgME::Data::setEncoding(Encoding enc) -{ - gpgme_data_encoding_t ge = GPGME_DATA_ENCODING_NONE; - switch (enc) { - case AutoEncoding: ge = GPGME_DATA_ENCODING_NONE; break; - case BinaryEncoding: ge = GPGME_DATA_ENCODING_BINARY; break; - case Base64Encoding: ge = GPGME_DATA_ENCODING_BASE64; break; - case ArmorEncoding: ge = GPGME_DATA_ENCODING_ARMOR; break; - case MimeEncoding: ge = GPGME_DATA_ENCODING_MIME; break; - case UrlEncoding: ge = GPGME_DATA_ENCODING_URL; break; - case UrlEscEncoding: ge = GPGME_DATA_ENCODING_URLESC; break; - case Url0Encoding: ge = GPGME_DATA_ENCODING_URL0; break; - } - return Error(gpgme_data_set_encoding(d->data, ge)); -} - -GpgME::Data::Type GpgME::Data::type() const -{ - if (isNull()) { - return Invalid; - } - switch (gpgme_data_identify(d->data, 0)) { - case GPGME_DATA_TYPE_INVALID: return Invalid; - case GPGME_DATA_TYPE_UNKNOWN: return Unknown; - case GPGME_DATA_TYPE_PGP_SIGNED: return PGPSigned; - case GPGME_DATA_TYPE_PGP_OTHER: return PGPOther; - case GPGME_DATA_TYPE_PGP_KEY: return PGPKey; - case GPGME_DATA_TYPE_CMS_SIGNED: return CMSSigned; - case GPGME_DATA_TYPE_CMS_ENCRYPTED: return CMSEncrypted; - case GPGME_DATA_TYPE_CMS_OTHER: return CMSOther; - case GPGME_DATA_TYPE_X509_CERT: return X509Cert; - case GPGME_DATA_TYPE_PKCS12: return PKCS12; - case GPGME_DATA_TYPE_PGP_ENCRYPTED: return PGPEncrypted; - case GPGME_DATA_TYPE_PGP_SIGNATURE: return PGPSignature; - } - return Invalid; -} - -char *GpgME::Data::fileName() const -{ - return gpgme_data_get_file_name(d->data); -} - -GpgME::Error GpgME::Data::setFileName(const char *name) -{ - return Error(gpgme_data_set_file_name(d->data, name)); -} - -GpgME::Error GpgME::Data::setFileName(const std::string &name) -{ - return Error(gpgme_data_set_file_name(d->data, name.c_str())); -} - -ssize_t GpgME::Data::read(void *buffer, size_t length) -{ - return gpgme_data_read(d->data, buffer, length); -} - -ssize_t GpgME::Data::write(const void *buffer, size_t length) -{ - return gpgme_data_write(d->data, buffer, length); -} - -off_t GpgME::Data::seek(off_t offset, int whence) -{ - return gpgme_data_seek(d->data, offset, whence); -} - -GpgME::Error GpgME::Data::rewind() -{ - return Error(gpgme_data_rewind(d->data)); -} - -std::vector<GpgME::Key> GpgME::Data::toKeys(Protocol proto) const -{ - std::vector<GpgME::Key> ret; - if (isNull()) { - return ret; - } - auto ctx = GpgME::Context::createForProtocol(proto); - if (!ctx) { - return ret; - } - - if (gpgme_op_keylist_from_data_start (ctx->impl()->ctx, d->data, 0)) { - return ret; - } - - gpgme_key_t key; - while (!gpgme_op_keylist_next (ctx->impl()->ctx, &key)) { - ret.push_back(GpgME::Key(key, false)); - } - gpgme_data_seek (d->data, 0, SEEK_SET); - - delete ctx; - return ret; -} - -std::string GpgME::Data::toString() -{ - std::string ret; - char buf[4096]; - size_t nread; - seek (0, SEEK_SET); - while ((nread = read (buf, 4096)) > 0) - { - ret += std::string (buf, nread); - } - seek (0, SEEK_SET); - return ret; -} - -GpgME::Error GpgME::Data::setFlag(const char *name, const char *value) -{ - return Error(gpgme_data_set_flag(d->data, name, value)); -} - -GpgME::Error GpgME::Data::setSizeHint(uint64_t size) -{ - const std::string val = std::to_string(size); - return Error(gpgme_data_set_flag(d->data, "size-hint", val.c_str())); -} diff --git a/lang/cpp/src/data.h b/lang/cpp/src/data.h deleted file mode 100644 index 178bc309..00000000 --- a/lang/cpp/src/data.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - data.h - wraps a gpgme data object - Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_DATA_H__ -#define __GPGMEPP_DATA_H__ - -#include "global.h" -#include "key.h" - -#include <sys/types.h> // for size_t, off_t -#include <cstdint> // unit64_t -#include <cstdio> // FILE -#include <algorithm> -#include <memory> - -namespace GpgME -{ - -class DataProvider; -class Error; - -class GPGMEPP_EXPORT Data -{ - struct Null { - Null() {} - }; -public: - /* implicit */ Data(const Null &); - Data(); - explicit Data(gpgme_data_t data); - - // Memory-Based Data Buffers: - Data(const char *buffer, size_t size, bool copy = true); - explicit Data(const char *filename); - Data(const char *filename, off_t offset, size_t length); - Data(std::FILE *fp, off_t offset, size_t length); - // File-Based Data Buffers: - explicit Data(std::FILE *fp); - explicit Data(int fd); - // Callback-Based Data Buffers: - explicit Data(DataProvider *provider); - - static const Null null; - - Data(const Data &other) = default; - const Data &operator=(Data other) - { - swap(other); - return *this; - } - - void swap(Data &other) - { - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - enum Encoding { - AutoEncoding, - BinaryEncoding, - Base64Encoding, - ArmorEncoding, - MimeEncoding, - UrlEncoding, - UrlEscEncoding, - Url0Encoding, - }; - Encoding encoding() const; - Error setEncoding(Encoding encoding); - - enum Type { - Invalid, - Unknown, - PGPSigned, - PGPOther, - PGPKey, - CMSSigned, - CMSEncrypted, - CMSOther, - X509Cert, - PKCS12, - PGPEncrypted, - PGPSignature, - }; - Type type() const; - - char *fileName() const; - Error setFileName(const char *name); - Error setFileName(const std::string &name); - - ssize_t read(void *buffer, size_t length); - ssize_t write(const void *buffer, size_t length); - off_t seek(off_t offset, int whence); - - /* Convenience function to do a seek (0, SEEK_SET). */ - Error rewind(); - - /** Try to parse the data to a key object using the - * Protocol proto. Returns an empty list on error.*/ - std::vector<Key> toKeys(const Protocol proto = Protocol::OpenPGP) const; - - /** Return a copy of the data as std::string. Sets seek pos to 0 */ - std::string toString(); - - /** See gpgme_data_set_flag */ - Error setFlag(const char *name, const char *value); - - /** Set a size hint for this data e.g. for progress calculations. */ - Error setSizeHint(uint64_t size); - - class Private; - Private *impl() - { - return d.get(); - } - const Private *impl() const - { - return d.get(); - } -private: - std::shared_ptr<Private> d; -}; - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Data) - -#endif // __GPGMEPP_DATA_H__ diff --git a/lang/cpp/src/data_p.h b/lang/cpp/src/data_p.h deleted file mode 100644 index b52940c6..00000000 --- a/lang/cpp/src/data_p.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - data_p.h - wraps a gpgme data object, private part -*- c++ -*- - Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_DATA_P_H__ -#define __GPGMEPP_DATA_P_H__ - -#include <data.h> -#include "callbacks.h" - -class GpgME::Data::Private -{ -public: - explicit Private(gpgme_data_t d = nullptr) - : data(d), cbs(data_provider_callbacks) {} - ~Private(); - - gpgme_data_t data; - gpgme_data_cbs cbs; -}; - -#endif // __GPGMEPP_DATA_P_H__ diff --git a/lang/cpp/src/decryptionresult.cpp b/lang/cpp/src/decryptionresult.cpp deleted file mode 100644 index dd515015..00000000 --- a/lang/cpp/src/decryptionresult.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* - decryptionresult.cpp - wraps a gpgme keygen result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <decryptionresult.h> -#include "result_p.h" -#include "util.h" - -#include <gpgme.h> - -#include <algorithm> -#include <iterator> -#include <cstring> -#include <cstdlib> -#include <istream> - -#include <string.h> - -class GpgME::DecryptionResult::Private -{ -public: - explicit Private(const _gpgme_op_decrypt_result &r) : res(r) - { - if (res.unsupported_algorithm) { - res.unsupported_algorithm = strdup(res.unsupported_algorithm); - } - if (res.file_name) { - res.file_name = strdup(res.file_name); - } - if (res.symkey_algo) { - res.symkey_algo = strdup(res.symkey_algo); - } - //FIXME: copying gpgme_recipient_t objects invalidates the keyid member, - //thus we use _keyid for now (internal API) - for (gpgme_recipient_t r = res.recipients ; r ; r = r->next) { - recipients.push_back(*r); - } - res.recipients = nullptr; - } - ~Private() - { - if (res.unsupported_algorithm) { - std::free(res.unsupported_algorithm); - } - res.unsupported_algorithm = nullptr; - if (res.file_name) { - std::free(res.file_name); - } - res.file_name = nullptr; - if (res.symkey_algo) { - std::free(res.symkey_algo); - } - res.symkey_algo = nullptr; - } - - _gpgme_op_decrypt_result res; - std::vector<_gpgme_recipient> recipients; -}; - -GpgME::DecryptionResult::DecryptionResult(gpgme_ctx_t ctx, int error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -GpgME::DecryptionResult::DecryptionResult(gpgme_ctx_t ctx, const Error &error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -void GpgME::DecryptionResult::init(gpgme_ctx_t ctx) -{ - if (!ctx) { - return; - } - gpgme_decrypt_result_t res = gpgme_op_decrypt_result(ctx); - if (!res) { - return; - } - d.reset(new Private(*res)); -} - -make_standard_stuff(DecryptionResult) - -const char *GpgME::DecryptionResult::unsupportedAlgorithm() const -{ - return d ? d->res.unsupported_algorithm : nullptr ; -} - -bool GpgME::DecryptionResult::isWrongKeyUsage() const -{ - return d && d->res.wrong_key_usage; -} - -bool GpgME::DecryptionResult::isDeVs() const -{ - return d && d->res.is_de_vs; -} - -bool GpgME::DecryptionResult::isBetaCompliance() const -{ - return d && d->res.beta_compliance; -} - -bool GpgME::DecryptionResult::isMime() const -{ - return d && d->res.is_mime; -} - -const char *GpgME::DecryptionResult::fileName() const -{ - return d ? d->res.file_name : nullptr ; -} - -unsigned int GpgME::DecryptionResult::numRecipients() const -{ - return d ? d->recipients.size() : 0 ; -} - -GpgME::DecryptionResult::Recipient GpgME::DecryptionResult::recipient(unsigned int idx) const -{ - if (d && idx < d->recipients.size()) { - return Recipient(&d->recipients[idx]); - } - return Recipient(); -} - -namespace -{ -struct make_recipient { - GpgME::DecryptionResult::Recipient operator()(_gpgme_recipient &t) - { - return GpgME::DecryptionResult::Recipient(&t); - } -}; -} - -std::vector<GpgME::DecryptionResult::Recipient> GpgME::DecryptionResult::recipients() const -{ - std::vector<Recipient> result; - if (d) { - result.reserve(d->recipients.size()); - std::transform(d->recipients.begin(), d->recipients.end(), - std::back_inserter(result), - make_recipient()); - } - return result; -} - -const char *GpgME::DecryptionResult::sessionKey() const -{ - return d ? d->res.session_key : nullptr; -} - -const char *GpgME::DecryptionResult::symkeyAlgo() const -{ - return d ? d->res.symkey_algo : nullptr; -} - -bool GpgME::DecryptionResult::isLegacyCipherNoMDC() const -{ - return d && d->res.legacy_cipher_nomdc; -} - -class GpgME::DecryptionResult::Recipient::Private : public _gpgme_recipient -{ -public: - Private(gpgme_recipient_t reci) : _gpgme_recipient(*reci) {} -}; - -GpgME::DecryptionResult::Recipient::Recipient() - : d() -{ - -} - -GpgME::DecryptionResult::Recipient::Recipient(gpgme_recipient_t r) - : d() -{ - if (r) { - d.reset(new Private(r)); - } -} - -bool GpgME::DecryptionResult::Recipient::isNull() const -{ - return !d; -} - -const char *GpgME::DecryptionResult::Recipient::keyID() const -{ - //_keyid is internal API, but the public keyid is invalid after copying (see above) - if (d) { - return d->_keyid; - } - return nullptr; -} - -const char *GpgME::DecryptionResult::Recipient::shortKeyID() const -{ - //_keyid is internal API, but the public keyid is invalid after copying (see above) - if (d) { - return d->_keyid + 8; - } - return nullptr; -} - -unsigned int GpgME::DecryptionResult::Recipient::publicKeyAlgorithm() const -{ - if (d) { - return d->pubkey_algo; - } - return 0; -} - -const char *GpgME::DecryptionResult::Recipient::publicKeyAlgorithmAsString() const -{ - if (d) { - return gpgme_pubkey_algo_name(d->pubkey_algo); - } - return nullptr; -} - -GpgME::Error GpgME::DecryptionResult::Recipient::status() const -{ - if (d) { - return Error(d->status); - } - return Error(); -} - -std::ostream &GpgME::operator<<(std::ostream &os, const DecryptionResult &result) -{ - os << "GpgME::DecryptionResult("; - if (!result.isNull()) { - os << "\n error: " << result.error() - << "\n fileName: " << protect(result.fileName()) - << "\n unsupportedAlgorithm: " << protect(result.unsupportedAlgorithm()) - << "\n isWrongKeyUsage: " << result.isWrongKeyUsage() - << "\n isDeVs: " << result.isDeVs() - << "\n isBetaCompliance: " << result.isBetaCompliance() - << "\n legacyCipherNoMDC: " << result.isLegacyCipherNoMDC() - << "\n symkeyAlgo: " << protect(result.symkeyAlgo()) - << "\n recipients:\n"; - const std::vector<DecryptionResult::Recipient> recipients = result.recipients(); - std::copy(recipients.begin(), recipients.end(), - std::ostream_iterator<DecryptionResult::Recipient>(os, "\n")); - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const DecryptionResult::Recipient &reci) -{ - os << "GpgME::DecryptionResult::Recipient("; - if (!reci.isNull()) { - os << "\n keyID: " << protect(reci.keyID()) - << "\n shortKeyID: " << protect(reci.shortKeyID()) - << "\n publicKeyAlgorithm: " << protect(reci.publicKeyAlgorithmAsString()) - << "\n status: " << reci.status(); - } - return os << ')'; -} diff --git a/lang/cpp/src/decryptionresult.h b/lang/cpp/src/decryptionresult.h deleted file mode 100644 index 3a87e181..00000000 --- a/lang/cpp/src/decryptionresult.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - decryptionresult.h - wraps a gpgme keygen result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_DECRYPTIONRESULT_H__ -#define __GPGMEPP_DECRYPTIONRESULT_H__ - -#include "gpgmefw.h" -#include "result.h" -#include "gpgmepp_export.h" - -#include <vector> -#include <algorithm> -#include <iosfwd> -#include <memory> - -namespace GpgME -{ - -class Error; - -class GPGMEPP_EXPORT DecryptionResult : public Result -{ -public: - DecryptionResult(); - DecryptionResult(gpgme_ctx_t ctx, int error); - DecryptionResult(gpgme_ctx_t ctx, const Error &err); - explicit DecryptionResult(const Error &err); - - DecryptionResult(const DecryptionResult &other) = default; - const DecryptionResult &operator=(DecryptionResult other) - { - swap(other); - return *this; - } - - void swap(DecryptionResult &other) - { - Result::swap(other); - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - GPGMEPP_DEPRECATED const char *unsupportedAlgortihm() const - { - return unsupportedAlgorithm(); - } - const char *unsupportedAlgorithm() const; - - GPGMEPP_DEPRECATED bool wrongKeyUsage() const - { - return isWrongKeyUsage(); - } - bool isWrongKeyUsage() const; - bool isDeVs() const; - bool isBetaCompliance() const; - bool isMime() const; - - const char *fileName() const; - - const char *sessionKey() const; - - const char *symkeyAlgo() const; - - class Recipient; - - unsigned int numRecipients() const; - Recipient recipient(unsigned int idx) const; - std::vector<Recipient> recipients() const; - - bool isLegacyCipherNoMDC() const; - -private: - class Private; - void init(gpgme_ctx_t ctx); - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const DecryptionResult &result); - -class GPGMEPP_EXPORT DecryptionResult::Recipient -{ -public: - Recipient(); - explicit Recipient(gpgme_recipient_t reci); - - Recipient(const Recipient &other) = default; - const Recipient &operator=(Recipient other) - { - swap(other); - return *this; - } - - void swap(Recipient &other) - { - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - const char *keyID() const; - const char *shortKeyID() const; - - unsigned int publicKeyAlgorithm() const; - const char *publicKeyAlgorithmAsString() const; - - Error status() const; - -private: - class Private; - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const DecryptionResult::Recipient &reci); - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(DecryptionResult) - -#endif // __GPGMEPP_DECRYPTIONRESULT_H__ diff --git a/lang/cpp/src/defaultassuantransaction.cpp b/lang/cpp/src/defaultassuantransaction.cpp deleted file mode 100644 index 7a52c153..00000000 --- a/lang/cpp/src/defaultassuantransaction.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - defaultassuantransaction.cpp - default Assuan Transaction that just stores data and status lines - Copyright (C) 2009 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "defaultassuantransaction.h" -#include "error.h" -#include "data.h" - -using namespace GpgME; - -DefaultAssuanTransaction::DefaultAssuanTransaction() - : AssuanTransaction(), - m_status(), - m_data() -{ - -} - -DefaultAssuanTransaction::~DefaultAssuanTransaction() {} - -Error DefaultAssuanTransaction::data(const char *data, size_t len) -{ - m_data.append(data, len); - return Error(); -} - -Data DefaultAssuanTransaction::inquire(const char *name, const char *args, Error &err) -{ - (void)name; (void)args; (void)err; - return Data::null; -} - -Error DefaultAssuanTransaction::status(const char *status, const char *args) -{ - m_status.push_back(std::pair<std::string, std::string>(status, args)); - return Error(); -} - -std::vector<std::string> DefaultAssuanTransaction::statusLine(const char *tag) const -{ - std::vector<std::string> result; - for (std::vector< std::pair<std::string, std::string> >::const_iterator it = m_status.begin(), end = m_status.end() ; it != end ; ++it) { - if (it->first == tag) { - result.push_back(it->second); - } - } - return result; -} - -std::string DefaultAssuanTransaction::firstStatusLine(const char *tag) const -{ - for (std::vector< std::pair<std::string, std::string> >::const_iterator it = m_status.begin(), end = m_status.end() ; it != end ; ++it) { - if (it->first == tag) { - return it->second; - } - } - return std::string(); -} diff --git a/lang/cpp/src/defaultassuantransaction.h b/lang/cpp/src/defaultassuantransaction.h deleted file mode 100644 index a7cac3c1..00000000 --- a/lang/cpp/src/defaultassuantransaction.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - defaultassuantransaction.h - default Assuan Transaction that just stores data and status lines - Copyright (C) 2009 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_DEFAULTASSUANTRANSACTION_H__ -#define __GPGMEPP_DEFAULTASSUANTRANSACTION_H__ - -#include "interfaces/assuantransaction.h" - -#include <string> -#include <vector> -#include <utility> - -namespace GpgME -{ - -class GPGMEPP_EXPORT DefaultAssuanTransaction : public AssuanTransaction -{ -public: - explicit DefaultAssuanTransaction(); - ~DefaultAssuanTransaction(); - - const std::vector< std::pair<std::string, std::string> > &statusLines() const - { - return m_status; - } - std::vector<std::string> statusLine(const char *tag) const; - std::string firstStatusLine(const char *tag) const; - - const std::string &data() const - { - return m_data; - } - -private: - Error data(const char *data, size_t datalen) override; - Data inquire(const char *name, const char *args, Error &err) override; - Error status(const char *status, const char *args) override; - -private: - std::vector< std::pair<std::string, std::string> > m_status; - std::string m_data; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_DEFAULTASSUANTRANSACTION_H__ diff --git a/lang/cpp/src/editinteractor.cpp b/lang/cpp/src/editinteractor.cpp deleted file mode 100644 index 5f9236cb..00000000 --- a/lang/cpp/src/editinteractor.cpp +++ /dev/null @@ -1,436 +0,0 @@ -/* - editinteractor.cpp - Interface for edit interactors - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "editinteractor.h" -#include "callbacks.h" -#include "error.h" -#include "util.h" - -#include <gpgme.h> - -#ifdef _WIN32 -# include <io.h> -#include <windows.h> -#else -# include <unistd.h> -#endif - -#include <cerrno> -#include <cstring> -#include <cstdlib> - -#ifndef GPG_ERR_ALREADY_SIGNED -# define GPG_ERR_ALREADY_SIGNED GPG_ERR_USER_1 -#endif - -using namespace GpgME; - -static const char *status_to_string(unsigned int status); -static Error status_to_error(unsigned int status); -static Error parse_sc_op_failure(const char *args); - -class EditInteractor::Private -{ - friend class ::GpgME::EditInteractor; - friend class ::GpgME::CallbackHelper; - EditInteractor *const q; -public: - explicit Private(EditInteractor *qq); - ~Private(); - -private: - unsigned int state = StartState; - Error error; - std::FILE *debug = nullptr; - bool debugNeedsClosing = false; -}; - -class GpgME::CallbackHelper -{ -private: - static int writeAll(int fd, const void *buf, size_t count) - { - size_t toWrite = count; - while (toWrite > 0) { - const int n = gpgme_io_write(fd, buf, toWrite); - if (n < 0) { - return n; - } - toWrite -= n; - } - return count; - } - -public: - static int edit_interactor_callback_impl(void *opaque, gpgme_status_code_t status, const char *args, int fd) - { - EditInteractor::Private *ei = (EditInteractor::Private *)opaque; - - Error err = status_to_error(status); - - if (!err) { - - // advance to next state based on input: - const unsigned int oldState = ei->state; - - if (ei->q->needsNoResponse(status)) { - // keep state - } else if (status == GPGME_STATUS_ERROR) { - err = ei->q->parseStatusError(args); - ei->state = EditInteractor::ErrorState; - } else if (status == GPGME_STATUS_SC_OP_FAILURE) { - err = parse_sc_op_failure(args); - ei->state = EditInteractor::ErrorState; - } else { - ei->state = ei->q->nextState(status, args, err); - } - - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: %u -> nextState( %s, %s ) -> %u\n", - oldState, status_to_string(status), args ? args : "<null>", ei->state); - } - if (err || err.isCanceled()) { - ei->state = oldState; - goto error; - } - - if (ei->state != oldState && - // if there was an error from before, we stop here (### this looks weird, can this happen at all?) - ei->error.code() == GPG_ERR_NO_ERROR) { - - // successful state change -> call action - if (const char *const result = ei->q->action(err)) { - if (err) { - goto error; - } - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: action result \"%s\"\n", result); - } - // if there's a result, write it: - if (*result) { - gpgme_err_set_errno(0); - const ssize_t len = std::strlen(result); - if (writeAll(fd, result, len) != len) { - err = Error::fromSystemError(); - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: Could not write to fd %d (%s)\n", fd, err.asStdString().c_str()); - } - goto error; - } - } - gpgme_err_set_errno(0); - if (writeAll(fd, "\n", 1) != 1) { - err = Error::fromSystemError(); - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: Could not write to fd %d (%s)\n", fd, err.asStdString().c_str()); - } - goto error; - } - } else { - if (err) { - goto error; - } - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: no action result\n"); - } - } - } else { - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: no action executed\n"); - } - } - } - - error: - if (err.code() == GPG_ERR_GENERAL) { - // gpg may have asked an unknown question; try to use the default answer - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: action result \"%s\" (go with the default answer)\n", ""); - } - if (writeAll(fd, "\n", 1) != 1) { - err = Error::fromSystemError(); - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: Could not write to fd %d (%s)\n", fd, err.asStdString().c_str()); - } - } else { - err = Error(); - } - } - if (err || err.isCanceled()) { - ei->error = err; - ei->state = EditInteractor::ErrorState; - } - - if (ei->debug) { - std::fprintf(ei->debug, "EditInteractor: error now %u (%s)\n", - ei->error.encodedError(), gpgme_strerror(ei->error.encodedError())); - } - - return ei->error.encodedError(); - } -}; - -static gpgme_error_t edit_interactor_callback(void *opaque, gpgme_status_code_t status, const char *args, int fd) -{ - return CallbackHelper::edit_interactor_callback_impl(opaque, status, args, fd); -} - -const gpgme_edit_cb_t GpgME::edit_interactor_callback = ::edit_interactor_callback; - -EditInteractor::Private::Private(EditInteractor *qq) - : q(qq) -{ - const char *debug_env = std::getenv("GPGMEPP_INTERACTOR_DEBUG"); - if (!debug_env) { - return; - } - if (!strcmp(debug_env, "stdout")) { - debug = stdout; - } else if (!strcmp(debug_env, "stderr")) { - debug = stderr; - } else if (debug_env) { - debug = std::fopen(debug_env, "a+"); - debugNeedsClosing = true; - } -} - -EditInteractor::Private::~Private() -{ - if (debug && debugNeedsClosing) { - std::fclose(debug); - } -} - -EditInteractor::EditInteractor() - : d(new Private(this)) -{ - -} - -EditInteractor::~EditInteractor() -{ - delete d; -} - -unsigned int EditInteractor::state() const -{ - return d->state; -} - -Error EditInteractor::lastError() const -{ - return d->error; -} - -bool EditInteractor::needsNoResponse(unsigned int status) const -{ - switch (status) { - case GPGME_STATUS_ALREADY_SIGNED: - case GPGME_STATUS_ERROR: - case GPGME_STATUS_GET_BOOL: - case GPGME_STATUS_GET_LINE: - case GPGME_STATUS_KEY_CREATED: - case GPGME_STATUS_NEED_PASSPHRASE_SYM: - case GPGME_STATUS_SC_OP_FAILURE: - case GPGME_STATUS_CARDCTRL: - case GPGME_STATUS_BACKUP_KEY_CREATED: - return false; - default: - return true; - } -} - -// static -Error status_to_error(unsigned int status) -{ - switch (status) { - case GPGME_STATUS_MISSING_PASSPHRASE: - return Error::fromCode(GPG_ERR_NO_PASSPHRASE); - case GPGME_STATUS_ALREADY_SIGNED: - return Error::fromCode(GPG_ERR_ALREADY_SIGNED); - case GPGME_STATUS_SIGEXPIRED: - return Error::fromCode(GPG_ERR_SIG_EXPIRED); - } - return Error(); -} - -void EditInteractor::setDebugChannel(std::FILE *debug) -{ - d->debug = debug; -} - -GpgME::Error EditInteractor::parseStatusError(const char *args) -{ - Error err; - - const auto fields = split(args, ' '); - if (fields.size() >= 2) { - err = Error{static_cast<unsigned int>(std::stoul(fields[1]))}; - } else { - err = Error::fromCode(GPG_ERR_GENERAL); - } - - return err; -} - -static Error sc_op_failure_to_error(unsigned int status) -{ - switch (status) { - case 1: - // GPG_ERR_CANCELED or GPG_ERR_FULLY_CANCELED - return Error::fromCode(GPG_ERR_CANCELED); - case 2: - // GPG_ERR_BAD_PIN or GPG_ERR_BAD_RESET_CODE [sic] - return Error::fromCode(GPG_ERR_BAD_PIN); - case 3: - return Error::fromCode(GPG_ERR_PIN_BLOCKED); - case 4: - return Error::fromCode(GPG_ERR_NO_RESET_CODE); - } - return Error::fromCode(GPG_ERR_CARD); -} - -// static -Error parse_sc_op_failure(const char *args) -{ - Error err; - - const auto fields = split(args, ' '); - if (fields.size() >= 1) { - err = sc_op_failure_to_error(static_cast<unsigned int>(std::stoul(fields[0]))); - } else { - err = Error::fromCode(GPG_ERR_CARD); - } - - return err; -} - -static const char *const status_strings[] = { - "EOF", - /* mkstatus processing starts here */ - "ENTER", - "LEAVE", - "ABORT", - - "GOODSIG", - "BADSIG", - "ERRSIG", - - "BADARMOR", - - "RSA_OR_IDEA", - "KEYEXPIRED", - "KEYREVOKED", - - "TRUST_UNDEFINED", - "TRUST_NEVER", - "TRUST_MARGINAL", - "TRUST_FULLY", - "TRUST_ULTIMATE", - - "SHM_INFO", - "SHM_GET", - "SHM_GET_BOOL", - "SHM_GET_HIDDEN", - - "NEED_PASSPHRASE", - "VALIDSIG", - "SIG_ID", - "ENC_TO", - "NODATA", - "BAD_PASSPHRASE", - "NO_PUBKEY", - "NO_SECKEY", - "NEED_PASSPHRASE_SYM", - "DECRYPTION_FAILED", - "DECRYPTION_OKAY", - "MISSING_PASSPHRASE", - "GOOD_PASSPHRASE", - "GOODMDC", - "BADMDC", - "ERRMDC", - "IMPORTED", - "IMPORT_OK", - "IMPORT_PROBLEM", - "IMPORT_RES", - "FILE_START", - "FILE_DONE", - "FILE_ERROR", - - "BEGIN_DECRYPTION", - "END_DECRYPTION", - "BEGIN_ENCRYPTION", - "END_ENCRYPTION", - - "DELETE_PROBLEM", - "GET_BOOL", - "GET_LINE", - "GET_HIDDEN", - "GOT_IT", - "PROGRESS", - "SIG_CREATED", - "SESSION_KEY", - "NOTATION_NAME", - "NOTATION_DATA", - "POLICY_URL", - "BEGIN_STREAM", - "END_STREAM", - "KEY_CREATED", - "USERID_HINT", - "UNEXPECTED", - "INV_RECP", - "NO_RECP", - "ALREADY_SIGNED", - "SIGEXPIRED", - "EXPSIG", - "EXPKEYSIG", - "TRUNCATED", - "ERROR", - "NEWSIG", - "REVKEYSIG", - "SIG_SUBPACKET", - "NEED_PASSPHRASE_PIN", - "SC_OP_FAILURE", - "SC_OP_SUCCESS", - "CARDCTRL", - "BACKUP_KEY_CREATED", - "PKA_TRUST_BAD", - "PKA_TRUST_GOOD", - - "PLAINTEXT", -}; -static const unsigned int num_status_strings = sizeof status_strings / sizeof * status_strings ; - -const char *status_to_string(unsigned int idx) -{ - if (idx < num_status_strings) { - return status_strings[idx]; - } else { - return "(unknown)"; - } -} diff --git a/lang/cpp/src/editinteractor.h b/lang/cpp/src/editinteractor.h deleted file mode 100644 index 2505b028..00000000 --- a/lang/cpp/src/editinteractor.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - editinteractor.h - Interface for edit interactors - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_EDITINTERACTOR_H__ -#define __GPGMEPP_EDITINTERACTOR_H__ - -#include "gpgmepp_export.h" - -#include <cstdio> - -namespace GpgME -{ - -class Error; -class Context; -class CallbackHelper; - -class GPGMEPP_EXPORT EditInteractor -{ - friend class ::GpgME::Context; - friend class ::GpgME::CallbackHelper; - EditInteractor(const EditInteractor &); - EditInteractor &operator=(const EditInteractor &); -public: - EditInteractor(); - virtual ~EditInteractor(); - - enum { - StartState = 0, - ErrorState = 0xFFFFFFFF - }; - - virtual const char *action(Error &err) const = 0; - virtual unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const = 0; - - unsigned int state() const; - Error lastError() const; - bool needsNoResponse(unsigned int statusCode) const; - - void setDebugChannel(std::FILE *file); - -protected: - Error parseStatusError(const char *args); - -private: - class Private; - Private *const d; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_EDITINTERACTOR_H__ diff --git a/lang/cpp/src/encryptionresult.cpp b/lang/cpp/src/encryptionresult.cpp deleted file mode 100644 index 95dcb22e..00000000 --- a/lang/cpp/src/encryptionresult.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - encryptionresult.cpp - wraps a gpgme verify result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <encryptionresult.h> -#include "result_p.h" -#include "util.h" - -#include <gpgme.h> - -#include <cstring> -#include <cstdlib> -#include <istream> -#include <algorithm> -#include <iterator> - -#include <string.h> - -class GpgME::EncryptionResult::Private -{ -public: - explicit Private(const gpgme_encrypt_result_t r) - { - if (!r) { - return; - } - for (gpgme_invalid_key_t ik = r->invalid_recipients ; ik ; ik = ik->next) { - gpgme_invalid_key_t copy = new _gpgme_invalid_key(*ik); - if (ik->fpr) { - copy->fpr = strdup(ik->fpr); - } - copy->next = nullptr; - invalid.push_back(copy); - } - } - ~Private() - { - for (std::vector<gpgme_invalid_key_t>::iterator it = invalid.begin() ; it != invalid.end() ; ++it) { - std::free((*it)->fpr); - delete *it; *it = nullptr; - } - } - - std::vector<gpgme_invalid_key_t> invalid; -}; - -GpgME::EncryptionResult::EncryptionResult(gpgme_ctx_t ctx, int error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -GpgME::EncryptionResult::EncryptionResult(gpgme_ctx_t ctx, const Error &error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -void GpgME::EncryptionResult::init(gpgme_ctx_t ctx) -{ - if (!ctx) { - return; - } - gpgme_encrypt_result_t res = gpgme_op_encrypt_result(ctx); - if (!res) { - return; - } - d.reset(new Private(res)); -} - -make_standard_stuff(EncryptionResult) - -unsigned int GpgME::EncryptionResult::numInvalidRecipients() const -{ - return d ? d->invalid.size() : 0 ; -} - -GpgME::InvalidRecipient GpgME::EncryptionResult::invalidEncryptionKey(unsigned int idx) const -{ - return InvalidRecipient(d, idx); -} - -std::vector<GpgME::InvalidRecipient> GpgME::EncryptionResult::invalidEncryptionKeys() const -{ - if (!d) { - return std::vector<GpgME::InvalidRecipient>(); - } - std::vector<GpgME::InvalidRecipient> result; - result.reserve(d->invalid.size()); - for (unsigned int i = 0 ; i < d->invalid.size() ; ++i) { - result.push_back(InvalidRecipient(d, i)); - } - return result; -} - -GpgME::InvalidRecipient::InvalidRecipient(const std::shared_ptr<EncryptionResult::Private> &parent, unsigned int i) - : d(parent), idx(i) -{ - -} - -GpgME::InvalidRecipient::InvalidRecipient() : d(), idx(0) {} - -bool GpgME::InvalidRecipient::isNull() const -{ - return !d || idx >= d->invalid.size() ; -} - -const char *GpgME::InvalidRecipient::fingerprint() const -{ - return isNull() ? nullptr : d->invalid[idx]->fpr ; -} - -GpgME::Error GpgME::InvalidRecipient::reason() const -{ - return Error(isNull() ? 0 : d->invalid[idx]->reason); -} - -std::ostream &GpgME::operator<<(std::ostream &os, const EncryptionResult &result) -{ - os << "GpgME::EncryptionResult("; - if (!result.isNull()) { - os << "\n error: " << result.error() - << "\n invalid recipients:\n"; - const std::vector<InvalidRecipient> ir = result.invalidEncryptionKeys(); - std::copy(ir.begin(), ir.end(), - std::ostream_iterator<InvalidRecipient>(os, "\n")); - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const InvalidRecipient &ir) -{ - os << "GpgME::InvalidRecipient("; - if (!ir.isNull()) { - os << "\n fingerprint: " << protect(ir.fingerprint()) - << "\n reason: " << ir.reason() - << '\n'; - } - return os << ')'; -} diff --git a/lang/cpp/src/encryptionresult.h b/lang/cpp/src/encryptionresult.h deleted file mode 100644 index 1aea6bb8..00000000 --- a/lang/cpp/src/encryptionresult.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - encryptionresult.h - wraps a gpgme sign result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_ENCRYPTIONRESULT_H__ -#define __GPGMEPP_ENCRYPTIONRESULT_H__ - -#include "gpgmefw.h" -#include "result.h" -#include "gpgmepp_export.h" - -#include <memory> - -#include <vector> -#include <iosfwd> - -namespace GpgME -{ - -class Error; -class InvalidRecipient; - -class GPGMEPP_EXPORT EncryptionResult : public Result -{ -public: - EncryptionResult(); - EncryptionResult(gpgme_ctx_t ctx, int error); - EncryptionResult(gpgme_ctx_t ctx, const Error &error); - EncryptionResult(const Error &err); - - EncryptionResult(const EncryptionResult &other) = default; - const EncryptionResult &operator=(EncryptionResult other) - { - swap(other); - return *this; - } - - void swap(EncryptionResult &other) - { - Result::swap(other); - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - unsigned int numInvalidRecipients() const; - - InvalidRecipient invalidEncryptionKey(unsigned int index) const; - std::vector<InvalidRecipient> invalidEncryptionKeys() const; - - class Private; -private: - void init(gpgme_ctx_t ctx); - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const EncryptionResult &result); - -class GPGMEPP_EXPORT InvalidRecipient -{ - friend class ::GpgME::EncryptionResult; - InvalidRecipient(const std::shared_ptr<EncryptionResult::Private> &parent, unsigned int index); -public: - InvalidRecipient(); - - InvalidRecipient(const InvalidRecipient &other) = default; - const InvalidRecipient &operator=(InvalidRecipient other) - { - swap(other); - return *this; - } - - void swap(InvalidRecipient &other) - { - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - const char *fingerprint() const; - Error reason() const; - -private: - std::shared_ptr<EncryptionResult::Private> d; - unsigned int idx; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const InvalidRecipient &recipient); - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(EncryptionResult) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(InvalidRecipient) - -#endif // __GPGMEPP_ENCRYPTIONRESULT_H__ diff --git a/lang/cpp/src/engineinfo.cpp b/lang/cpp/src/engineinfo.cpp deleted file mode 100644 index c4ad5300..00000000 --- a/lang/cpp/src/engineinfo.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - engineinfo.h - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "engineinfo.h" - -#include <gpgme.h> - -class GpgME::EngineInfo::Private -{ -public: - Private(gpgme_engine_info_t engine = nullptr) : info(engine) {} - ~Private() - { - info = nullptr; - } - - gpgme_engine_info_t info; -}; - -GpgME::EngineInfo::EngineInfo() : d() {} - -GpgME::EngineInfo::EngineInfo(gpgme_engine_info_t engine) - : d(new Private(engine)) -{ - -} - -bool GpgME::EngineInfo::isNull() const -{ - return !d || !d->info; -} - -GpgME::Protocol GpgME::EngineInfo::protocol() const -{ - if (isNull()) { - return UnknownProtocol; - } - switch (d->info->protocol) { - case GPGME_PROTOCOL_OpenPGP: return OpenPGP; - case GPGME_PROTOCOL_CMS: return CMS; - default: - return UnknownProtocol; - } -} - -const char *GpgME::EngineInfo::fileName() const -{ - return isNull() ? nullptr : d->info->file_name; -} - -const char *GpgME::EngineInfo::version() const -{ - return isNull() ? nullptr : d->info->version; -} - -GpgME::EngineInfo::Version GpgME::EngineInfo::engineVersion() const -{ - return Version(version()); -} - -const char *GpgME::EngineInfo::requiredVersion() const -{ - return isNull() ? nullptr : d->info->req_version; -} - -const char *GpgME::EngineInfo::homeDirectory() const -{ - return isNull() ? nullptr : d->info->home_dir; -} diff --git a/lang/cpp/src/engineinfo.h b/lang/cpp/src/engineinfo.h deleted file mode 100644 index 5dc5370c..00000000 --- a/lang/cpp/src/engineinfo.h +++ /dev/null @@ -1,255 +0,0 @@ -/* - engineinfo.h - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_ENGINEINFO_H__ -#define __GPGMEPP_ENGINEINFO_H__ - -#include "global.h" - -#include <memory> - -#include <algorithm> -#include <string> -#include <iostream> - -namespace GpgME -{ - -class GPGMEPP_EXPORT EngineInfo -{ -public: - struct Version - { - int major, minor, patch; - Version() - { - major = 0; - minor = 0; - patch = 0; - } - - Version(const std::string& version) - { - if (version.empty() || - std::sscanf(version.c_str(), "%d.%d.%d", &major, &minor, &patch) != 3) { - major = 0; - minor = 0; - patch = 0; - } - } - - Version(const char *version) - { - if (!version || - std::sscanf(version, "%d.%d.%d", &major, &minor, &patch) != 3) { - major = 0; - minor = 0; - patch = 0; - } - } - - bool operator < (const Version& other) const - { - if (major > other.major || - (major == other.major && minor > other.minor) || - (major == other.major && minor == other.minor && patch > other.patch) || - (major >= other.major && minor >= other.minor && patch >= other.patch)) { - return false; - } - return true; - } - - bool operator < (const char* other) const - { - return operator<(Version(other)); - } - - bool operator <= (const Version &other) const - { - return !operator>(other); - } - - bool operator <= (const char *other) const - { - return operator<=(Version(other)); - } - - bool operator > (const char* other) const - { - return operator>(Version(other)); - } - - bool operator > (const Version & other) const - { - return !operator<(other) && !operator==(other); - } - - bool operator >= (const Version &other) const - { - return !operator<(other); - } - - bool operator >= (const char *other) const - { - return operator>=(Version(other)); - } - - bool operator == (const Version& other) const - { - return major == other.major - && minor == other.minor - && patch == other.patch; - } - - bool operator == (const char* other) const - { - return operator==(Version(other)); - } - - bool operator != (const Version &other) const - { - return !operator==(other); - } - - bool operator != (const char *other) const - { - return operator!=(Version(other)); - } - - // the non-const overloads of the comparison operators are kept for - // binary compatibility - bool operator < (const Version& other) - { - if (major > other.major || - (major == other.major && minor > other.minor) || - (major == other.major && minor == other.minor && patch > other.patch) || - (major >= other.major && minor >= other.minor && patch >= other.patch)) { - return false; - } - return true; - } - - bool operator < (const char* other) - { - return operator<(Version(other)); - } - - bool operator <= (const Version &other) - { - return !operator>(other); - } - - bool operator <= (const char *other) - { - return operator<=(Version(other)); - } - - bool operator > (const char* other) - { - return operator>(Version(other)); - } - - bool operator > (const Version & other) - { - return !operator<(other) && !operator==(other); - } - - bool operator >= (const Version &other) - { - return !operator<(other); - } - - bool operator >= (const char *other) - { - return operator>=(Version(other)); - } - - bool operator == (const Version& other) - { - return major == other.major - && minor == other.minor - && patch == other.patch; - } - - bool operator == (const char* other) - { - return operator==(Version(other)); - } - - bool operator != (const Version &other) - { - return !operator==(other); - } - - bool operator != (const char *other) - { - return operator!=(Version(other)); - } - - friend std::ostream& operator << (std::ostream& stream, const Version& ver) - { - stream << ver.major; - stream << '.'; - stream << ver.minor; - stream << '.'; - stream << ver.patch; - return stream; - } - }; - - EngineInfo(); - explicit EngineInfo(gpgme_engine_info_t engine); - - EngineInfo(const EngineInfo &other) = default; - const EngineInfo &operator=(EngineInfo other) - { - swap(other); - return *this; - } - - void swap(EngineInfo &other) - { - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - Protocol protocol() const; - const char *fileName() const; - const char *version() const; - Version engineVersion() const; - const char *requiredVersion() const; - const char *homeDirectory() const; - -private: - class Private; - std::shared_ptr<Private> d; -}; - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(EngineInfo) - -#endif // __GPGMEPP_ENGINEINFO_H__ diff --git a/lang/cpp/src/error.h b/lang/cpp/src/error.h deleted file mode 100644 index 000b562b..00000000 --- a/lang/cpp/src/error.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - error.h - wraps a gpgme error - Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_ERROR_H__ -#define __GPGMEPP_ERROR_H__ - -#include "global.h" - -#include <string> -#include <iosfwd> - -#include <gpg-error.h> - -#ifndef GPGMEPP_ERR_SOURCE_DEFAULT -# define GPGMEPP_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1 -#endif - -namespace GpgME -{ - -class GPGMEPP_EXPORT Error -{ -public: - Error() : mErr(0), mMessage() {} - explicit Error(unsigned int e) : mErr(e), mMessage() {} - - const char *source() const; - /* This function is deprecated. Use asStdString() instead. asString() may - * return wrongly encoded (i.e. not UTF-8) results on Windows for the main - * thread if the function was first called from a secondary thread. */ - GPGMEPP_DEPRECATED const char *asString() const; - std::string asStdString() const; - - int code() const; - int sourceID() const; - - bool isCanceled() const; - - unsigned int encodedError() const - { - return mErr; - } - int toErrno() const; - - static bool hasSystemError(); - static Error fromSystemError(unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT); - static void setSystemError(gpg_err_code_t err); - static void setErrno(int err); - static Error fromErrno(int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT); - static Error fromCode(unsigned int err, unsigned int src = GPGMEPP_ERR_SOURCE_DEFAULT); - - GPGMEPP_MAKE_SAFE_BOOL_OPERATOR(mErr &&!isCanceled()) -private: - unsigned int mErr; - mutable std::string mMessage; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Error &err); - -} // namespace GpgME - -#endif /* __GPGMEPP_ERROR_H__ */ diff --git a/lang/cpp/src/eventloopinteractor.cpp b/lang/cpp/src/eventloopinteractor.cpp deleted file mode 100644 index 09710ad4..00000000 --- a/lang/cpp/src/eventloopinteractor.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - eventloopinteractor.cpp - Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <eventloopinteractor.h> - -#include <context.h> -#include "context_p.h" -#include <key.h> -#include <trustitem.h> - -#include <gpgme.h> - -#include <vector> -using std::vector; -#ifndef NDEBUG -# include <iostream> -#endif -#include <cassert> - -namespace GpgME -{ - -// -// EventLoopInteractor::Private Declaration -// - -class EventLoopInteractor::Private -{ -public: - struct OneFD { - OneFD(int aFd, int aDir, gpgme_io_cb_t aFnc, - void *aFncData, void *aExternalTag) - : fd(aFd), dir(aDir), fnc(aFnc), - fncData(aFncData), externalTag(aExternalTag) {} - int fd; - int dir; - gpgme_io_cb_t fnc; - void *fncData; - void *externalTag; - }; - - vector<OneFD *> mCallbacks; - - static void removeIOCb(void *tag); - static gpgme_error_t registerIOCb(void *data, int fd, int dir, - gpgme_io_cb_t fnc, void *fnc_data, - void **r_tag); - static void eventIOCb(void *, gpgme_event_io_t type, void *type_data); - - static const gpgme_io_cbs iocbs; -}; - -const gpgme_io_cbs EventLoopInteractor::Private::iocbs = { - &EventLoopInteractor::Private::registerIOCb, - nullptr, - &EventLoopInteractor::Private::removeIOCb, - &EventLoopInteractor::Private::eventIOCb, - nullptr -}; - -// -// EventLoopInteractor::Private IO Callback Implementations -// - -gpgme_error_t EventLoopInteractor::Private::registerIOCb(void *, int fd, int dir, - gpgme_io_cb_t fnc, void *fnc_data, - void **r_tag) -{ - assert(instance()); assert(instance()->d); - bool ok = false; - void *etag = instance()->registerWatcher(fd, dir ? Read : Write, ok); - if (!ok) { - return gpgme_error(GPG_ERR_GENERAL); - } - instance()->d->mCallbacks.push_back(new OneFD(fd, dir, fnc, fnc_data, etag)); - if (r_tag) { - *r_tag = instance()->d->mCallbacks.back(); - } - return GPG_ERR_NO_ERROR; -} - -void EventLoopInteractor::Private::removeIOCb(void *tag) -{ - - if (!instance() || !instance()->d) { - return; - } - for (vector<OneFD *>::iterator it = instance()->d->mCallbacks.begin(); - it != instance()->d->mCallbacks.end() ; ++it) { - if (*it == tag) { - instance()->unregisterWatcher((*it)->externalTag); - delete *it; *it = nullptr; - instance()->d->mCallbacks.erase(it); - return; - } - } -} - -void EventLoopInteractor::Private::eventIOCb(void *data, gpgme_event_io_t type, void *type_data) -{ - assert(instance()); - Context *ctx = static_cast<Context *>(data); - switch (type) { - case GPGME_EVENT_START: { - instance()->operationStartEvent(ctx); - // TODO: what's in type_data? - } - break; - case GPGME_EVENT_DONE: { - gpgme_error_t e = *static_cast<gpgme_error_t *>(type_data); - if (ctx && ctx->impl()) { - ctx->impl()->lasterr = e; - } - instance()->operationDoneEvent(ctx, Error(e)); - } - break; - case GPGME_EVENT_NEXT_KEY: { - gpgme_key_t key = static_cast<gpgme_key_t>(type_data); - instance()->nextKeyEvent(ctx, Key(key, false)); - } - break; - case GPGME_EVENT_NEXT_TRUSTITEM: { - gpgme_trust_item_t item = static_cast<gpgme_trust_item_t>(type_data); - instance()->nextTrustItemEvent(ctx, TrustItem(item)); - gpgme_trust_item_unref(item); - } - break; - default: // warn - ; - } -} - -// -// EventLoopInteractor Implementation -// - -EventLoopInteractor *EventLoopInteractor::mSelf = nullptr; - -EventLoopInteractor::EventLoopInteractor() : d(new Private) -{ - assert(!mSelf); - mSelf = this; -} - -EventLoopInteractor::~EventLoopInteractor() -{ - // warn if there are still callbacks registered - mSelf = nullptr; - delete d; -} - -void EventLoopInteractor::manage(Context *context) -{ - if (!context || context->managedByEventLoopInteractor()) { - return; - } - gpgme_io_cbs *iocbs = new gpgme_io_cbs(Private::iocbs); - iocbs->event_priv = context; - context->installIOCallbacks(iocbs); -} - -void EventLoopInteractor::unmanage(Context *context) -{ - if (context) { - context->uninstallIOCallbacks(); - } -} - -void EventLoopInteractor::actOn(int fd, Direction dir) -{ - for (vector<Private::OneFD *>::const_iterator it = d->mCallbacks.begin(); - it != d->mCallbacks.end() ; ++it) { - if ((*it)->fd == fd && ((*it)->dir ? Read : Write) == dir) { - (*((*it)->fnc))((*it)->fncData, fd); - break; - } - } -} - -} // namespace GpgME diff --git a/lang/cpp/src/eventloopinteractor.h b/lang/cpp/src/eventloopinteractor.h deleted file mode 100644 index 79f6b632..00000000 --- a/lang/cpp/src/eventloopinteractor.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - eventloopinteractor.h - Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_EVENTLOOPINTERACTOR_H__ -#define __GPGMEPP_EVENTLOOPINTERACTOR_H__ - -#include "gpgmepp_export.h" - -namespace GpgME -{ - -class Context; -class Error; -class TrustItem; -class Key; - -/*! \file eventloopinteractor.h - \brief Abstract base class for gpgme's external event loop support - - This class does most of the work involved with hooking GpgME++ - up with external event loops, such as the GTK or Qt ones. - - It actually provides two interfaces: An interface to the gpgme - IO Callback handling and one for gpgme events. The IO Callback - interface consists of the three methods \c actOn(), \c - registerWatcher() and \c unregisterWatcher(). The event - interface consists of the three methods \c nextTrustItemEvent(), - \c nextKeyEvent() and \c operationDoneEvent(). - - \sect General Usage - - \c EventLoopInteractor is designed to be used as a - singleton. However, in order to make any use of it, you have to - subclass it and reimplement it's pure virtual methods (see - below). We suggest you keep the constructor protected and - provide a static \c instance() method that returns the single - instance. Alternatively, you can create an instance on the - stack, e.g. in \c main(). - - If you want \c EventLoopInteractor to manage a particular \c - Context, just call \c manage() on the \c Context. OTOH, if you - want to disable IO callbacks for a \c Context, use \c unmanage(). - - \sect IO Callback Interface - - One part of this interface is represented by \c - registerWatcher() and \c unregisterWatcher(), both of which are - pure virtual. \c registerWatcher() should do anything necessary - to hook up watching of file descriptor \c fd for reading (\c dir - = \c Read) or writing (\c dir = Write) to the event loop you use - and return a tag identifying that particular watching process - uniquely. This could be the index into an array of objects you - use for that purpose or the address of such an object. E.g. in - Qt, you'd essentially just create a new \c QSocketNotifier: - - \verbatim - void * registerWatcher( int fd, Direction dir ) { - return new QSocketNotifier( fd, dir == Read ? QSocketNotifier::Read : QSocketNotifier::Write ); - // misses connecting to the activated() signal... - } - \endverbatim - - which uses the address of the created object as unique tag. The - tag returned by \c registerWatcher is stored by \c - EventLoopInteractor and passed as argument to \c - unregisterWatcher(). So, in the picture above, you'd implement \c - unregisterWatcher() like this: - - \verbatim - void unregisterWatcher( void * tag ) { - delete static_cast<QSocketNotifier*>( tag ); - } - \endverbatim - - The other part of the IO callback interface is \c actOn(), which - you should call if you receive notification from your event loop - about activity on file descriptor \c fd in direction \c dir. In - the picture above, you'd call this from the slot connected to - the socket notifier's \c activated() signal. - - \note \c registerWatcher() as well as \c unregisterWatcher() may - be called from within \c actOn(), so be careful with - e.g. locking in threaded environments and keep in mind that the - object you used to find the \c fd and \c dir fo the \c actOn() - call might be deleted when \c actOn() returns! - - \sect Event Handler Interface - -*/ -class GPGMEPP_EXPORT EventLoopInteractor -{ -protected: - EventLoopInteractor(); -public: - virtual ~EventLoopInteractor(); - - static EventLoopInteractor *instance() - { - return mSelf; - } - - void manage(Context *context); - void unmanage(Context *context); - - enum Direction { Read, Write }; -protected: - // - // IO Notification Interface - // - - /** Call this if your event loop detected activity on file - descriptor fd, with direction dir */ - void actOn(int fd, Direction dir); - - virtual void *registerWatcher(int fd, Direction dir, bool &ok) = 0; - virtual void unregisterWatcher(void *tag) = 0; - - // - // Event Handler Interface - // - - virtual void operationStartEvent(Context *context) = 0; - virtual void nextTrustItemEvent(Context *context, const TrustItem &item) = 0; - virtual void nextKeyEvent(Context *context, const Key &key) = 0; - virtual void operationDoneEvent(Context *context, const Error &e) = 0; - -private: - class Private; - friend class Private; - Private *const d; - static EventLoopInteractor *mSelf; -}; - -} - -#endif // __GPGMEPP_EVENTLOOPINTERACTOR_H__ diff --git a/lang/cpp/src/exception.cpp b/lang/cpp/src/exception.cpp deleted file mode 100644 index 7751c3ea..00000000 --- a/lang/cpp/src/exception.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - exception.cpp - exception wrapping a gpgme error - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "exception.h" - -#include <gpgme.h> - -#include <sstream> - -using namespace GpgME; -using namespace std; // only safe b/c it's so small a file! - -Exception::~Exception() throw() {} - -// static -string Exception::make_message(const Error &err, const string &msg) -{ - return make_message(err, msg, NoOptions); -} - -// static -string Exception::make_message(const Error &err, const string &msg, Options opt) -{ - if (opt & MessageOnly) { - return msg; - } - char error_string[128]; - error_string[0] = '\0'; - gpgme_strerror_r(err.encodedError(), error_string, sizeof error_string); - error_string[sizeof error_string - 1] = '\0'; - stringstream ss; - ss << gpgme_strsource(err.encodedError()) << ": "; - if (!msg.empty()) { - ss << msg << ": "; - } - ss << error_string << " (" << static_cast<unsigned long>(err.encodedError()) << ')'; - return ss.str(); -} diff --git a/lang/cpp/src/exception.h b/lang/cpp/src/exception.h deleted file mode 100644 index 85169d83..00000000 --- a/lang/cpp/src/exception.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - exception.h - exception wrapping a gpgme error - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_EXCEPTION_H__ -#define __GPGMEPP_EXCEPTION_H__ - -#include "error.h" - -#include <stdexcept> -#include <string> - -namespace GpgME -{ - -class GPGMEPP_EXPORT Exception : public std::runtime_error -{ -public: - enum Options { - NoOptions = 0x0, - MessageOnly = 0x1, - - AllOptions = MessageOnly - }; - - explicit Exception(const GpgME::Error &err, const std::string &msg = std::string(), Options opt = NoOptions) - : std::runtime_error(make_message(err, msg, opt)), m_error(err), m_message(msg) {} - - ~Exception() throw(); - - Error error() const - { - return m_error; - } - const std::string &message() const - { - return m_message; - } -private: - static std::string make_message(const GpgME::Error &err, const std::string &msg); - static std::string make_message(const GpgME::Error &err, const std::string &msg, Options opt); -private: - const GpgME::Error m_error; - const std::string m_message; -}; - -} // namespace GpgME - -#endif /* __GPGMEPP_EXCEPTION_H__ */ diff --git a/lang/cpp/src/global.h b/lang/cpp/src/global.h deleted file mode 100644 index d297defc..00000000 --- a/lang/cpp/src/global.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - global.h - global gpgme functions and enums - Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_GLOBAL_H__ -#define __GPGMEPP_GLOBAL_H__ - -#include "gpgmefw.h" -#include "gpgmepp_export.h" - -#include <iosfwd> -#include <cstring> - -namespace GpgME -{ -class Error; -class EngineInfo; -class Context; -} - -struct _GIOChannel; -typedef struct _GIOChannel GIOChannel; -class QIODevice; - -namespace GpgME -{ - -GPGMEPP_EXPORT void initializeLibrary(); -/*! - Initializes the library, returns Error::code() == - GPG_ERR_USER_1 if underlying gpgme is too old. -*/ -GPGMEPP_EXPORT Error initializeLibrary(int); - -enum Protocol { OpenPGP, CMS, UnknownProtocol }; - -enum Engine { GpgEngine, GpgSMEngine, GpgConfEngine, UnknownEngine, AssuanEngine, G13Engine, SpawnEngine }; - -enum KeyListMode { - Local = 0x1, - Extern = 0x2, - Locate = Local|Extern, - Signatures = 0x4, - SignatureNotations = 0x8, - Validate = 0x10, - Ephemeral = 0x20, - WithTofu = 0x40, - WithKeygrip = 0x80, - WithSecret = 0x100, - ForceExtern = 0x200, - LocateExternal = Locate|ForceExtern, - - KeyListModeMask = 0x3ff -}; - -enum SignatureMode { - NormalSignatureMode = 0, - Detached = 1, - Clearsigned = 2, - SignArchive = 4, - SignFile = 8, -}; - -enum class RevocationReason { - Unspecified = 0, - Compromised = 1, - Superseded = 2, - NoLongerUsed = 3 -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Protocol proto); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Engine eng); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, KeyListMode mode); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, SignatureMode mode); - -GPGMEPP_EXPORT Error setDefaultLocale(int category, const char *value); - -GPGMEPP_EXPORT Context *wait(Error &e, bool hang = true); -typedef void (*IdleFunction)(void); -GPGMEPP_EXPORT IdleFunction registerIdleFunction(IdleFunction idleFunction); - -typedef void (*IOCallback)(void *data, int fd); - -GPGMEPP_EXPORT EngineInfo engineInfo(Protocol proto); -GPGMEPP_EXPORT EngineInfo engineInfo(Engine engine); -/** Wrapper around gpgme_get_dirinfo. What can be: -homedir, sysconfdir, bindir, libexecdir, libdir, -datadir, localedir, agent-socket, agent-ssh-socket, -dirmngr-socket, uiserver-socket, gpgconf-name, gpg-name, -gpgsm-name, g13-name, keyboxd-name, agent-name, scdaemon-name, -dirmngr-name, pinentry-name, socketdir, gpg-wks-client-name, gpgtar-name. - -This may be extended in the future. -*/ -GPGMEPP_EXPORT const char *dirInfo(const char *what); - -GPGMEPP_EXPORT Error checkEngine(Protocol proto); -GPGMEPP_EXPORT Error checkEngine(Engine engine); - -/* Wrapper for gpgme_set_global_flag */ -GPGMEPP_EXPORT int setGlobalFlag(const char *name, const char *value); - -GPGMEPP_EXPORT GIOChannel *getGIOChannel(int fd); -GPGMEPP_EXPORT QIODevice *getQIODevice(int fd); - -enum Feature { - ValidatingKeylistModeFeature = 0x00000001, - CancelOperationFeature = 0x00000002, - WrongKeyUsageFeature = 0x00000004, - DefaultCertificateInclusionFeature = 0x00000008, - - GetSetEngineInfoFeature = 0x00000010, - EngineInfoHomeDirFeature = 0x00000020, - NoEncryptToEncryptionFlagFeature = 0x00000040, - EphemeralKeylistModeFeature = 0x00000080, - - SetDataFileNameFeeature = 0x00000100, - VerificationResultFileNameFeature = 0x00000200, - DecryptionResultFileNameFeature = 0x00000400, - DecryptionResultRecipientsFeature = 0x00000800, - - AuditLogFeature = 0x00001000, - GpgConfEngineFeature = 0x00002000, - CancelOperationAsyncFeature = 0x00004000, - AssuanEngineFeature = 0x00008000, - - ClearAddGetSignatureNotationsFeature = 0x00010000, - SignatureNotationsKeylistModeFeature = 0x00020000, - KeySignatureNotationsFeature = 0x00040000, - SignatureNotationsFlagsFeature = 0x00080000, - SignatureNotationsCriticalFlagFeature = 0x00100000, - SignatureNotationsHumanReadableFlagFeature = 0x00200000, - CardKeyFeature = 0x00400000, - ImportFromKeyserverFeature = 0x00800000, - - KeyIsQualifiedFeature = 0x01000200, - SubkeyIsQualifiedFeature = 0x02000000, - SignaturePkaFieldsFeature = 0x04000000, - SignatureAlgorithmFieldsFeature = 0x08000000, - - FdPointerFeature = 0x10000000, - G13VFSFeature = 0x20000000, - PasswdFeature = 0x40000000, // gpgme >= 1.3.0 - // unusable (max value) - - FeatureMaxValue = 0x80000000 -}; -enum Feature2 { - BinaryAndFineGrainedIdentify = 0x00000001, // gpgme >= 1.7.0 - Feature2MaxValue = 0x80000000 -}; - -// use hasFeature( unsigned long, unsigned long ) instead -GPGMEPP_DEPRECATED_EXPORT bool hasFeature(unsigned long feature); -GPGMEPP_EXPORT bool hasFeature(unsigned long feature, unsigned long feature2); - -} // namespace GpgME - -# ifndef GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION -# define GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION( Class ) \ - namespace std { template <> inline void swap< GpgME::Class >( GpgME::Class & lhs, GpgME::Class & rhs ) { lhs.swap( rhs ); } } -# endif - -# ifndef GPGMEPP_MAKE_SAFE_BOOL_OPERATOR -# define GPGMEPP_MAKE_SAFE_BOOL_OPERATOR( Cond ) \ - private: \ - struct __safe_bool_dummy__ { void nonnull() {} }; \ - typedef void ( __safe_bool_dummy__::*unspecified_bool_type )(); \ - public: \ - operator unspecified_bool_type() const { return ( Cond ) ? &__safe_bool_dummy__::nonnull : nullptr; } -# endif - -inline int _gpgmepp_strcmp(const char *s1, const char *s2) -{ - return s1 ? s2 ? std::strcmp(s1, s2) : 1 : s2 ? -1 : 0; -} - -#define _GPGMEPP_MAKE_STRCMP( Name, expr, cmp ) \ - template <template <typename U> class Op> \ - struct Name { \ - typedef bool result_type; \ - \ - bool operator()( const char * lhs, const char * rhs ) const { \ - return Op<int>()( cmp, 0 ); \ - } \ - \ - bool operator()( const std::string & lhs, const std::string & rhs ) const { \ - return operator()( lhs.c_str(), rhs.c_str() ); \ - } \ - bool operator()( const char * lhs, const std::string & rhs ) const { \ - return operator()( lhs, rhs.c_str() ); \ - } \ - bool operator()( const std::string & lhs, const char * rhs ) const { \ - return operator()( lhs.c_str(), rhs ); \ - } \ - \ - template <typename T> \ - bool operator()( const T & lhs, const T & rhs ) const { \ - return operator()( (lhs expr), (rhs expr) ); \ - } \ - template <typename T> \ - bool operator()( const T & lhs, const char * rhs ) const { \ - return operator()( (lhs expr), rhs ); \ - } \ - template <typename T> \ - bool operator()( const char * lhs, const T & rhs ) const { \ - return operator()( lhs, (rhs expr) ); \ - } \ - template <typename T> \ - bool operator()( const T & lhs, const std::string & rhs ) const { \ - return operator()( (lhs expr), rhs ); \ - } \ - template <typename T> \ - bool operator()( const std::string & lhs, const T & rhs ) const { \ - return operator()( lhs, (rhs expr) ); \ - } \ - } - -#define GPGMEPP_MAKE_STRCMP( Name, expr ) \ - _GPGMEPP_MAKE_STRCMP( Name, expr, _gpgmepp_strcmp( lhs, rhs ) ) - - -#endif // __GPGMEPP_GLOBAL_H__ diff --git a/lang/cpp/src/gpgaddexistingsubkeyeditinteractor.cpp b/lang/cpp/src/gpgaddexistingsubkeyeditinteractor.cpp deleted file mode 100644 index 49e98def..00000000 --- a/lang/cpp/src/gpgaddexistingsubkeyeditinteractor.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - gpgaddexistingsubkeyeditinteractor.cpp - Edit Interactor to add an existing subkey to an OpenPGP key - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "gpgaddexistingsubkeyeditinteractor.h" - -#include "error.h" - -#include <gpgme.h> - -// avoid conflict (msvc) -#ifdef ERROR -# undef ERROR -#endif - -using namespace GpgME; - -class GpgAddExistingSubkeyEditInteractor::Private -{ - enum { - START = EditInteractor::StartState, - COMMAND, - ADD_EXISTING_KEY, - KEYGRIP, - FLAGS, - VALID, - KEY_CREATED, - QUIT, - SAVE, - - ERROR = EditInteractor::ErrorState - }; - - GpgAddExistingSubkeyEditInteractor *const q = nullptr; - -public: - Private(GpgAddExistingSubkeyEditInteractor *q, const std::string &keygrip) - : q{q} - , keygrip{keygrip} - { - } - - const char *action(Error &err) const; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const; - - std::string keygrip; - std::string expiry; -}; - -const char *GpgAddExistingSubkeyEditInteractor::Private::action(Error &err) const -{ - switch (q->state()) { - case COMMAND: - return "addkey"; - case ADD_EXISTING_KEY: - return "keygrip"; - case KEYGRIP: - return keygrip.c_str(); - case FLAGS: - return "Q"; // do not toggle any usage flags - case VALID: - return expiry.empty() ? "0" : expiry.c_str(); - case QUIT: - return "quit"; - case SAVE: - return "Y"; - case START: - case KEY_CREATED: - case ERROR: - return nullptr; - default: - err = Error::fromCode(GPG_ERR_GENERAL); - return nullptr; - } -} - -unsigned int GpgAddExistingSubkeyEditInteractor::Private::nextState(unsigned int status, const char *args, Error &err) const -{ - using std::strcmp; - - static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); - static const Error NO_KEY_ERROR = Error::fromCode(GPG_ERR_NO_KEY); - static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME); - - switch (q->state()) { - case START: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case COMMAND: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.algo") == 0) { - return ADD_EXISTING_KEY; - } - err = GENERAL_ERROR; - return ERROR; - case ADD_EXISTING_KEY: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.keygrip") == 0) { - return KEYGRIP; - } - err = GENERAL_ERROR; - return ERROR; - case KEYGRIP: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.flags") == 0) { - return FLAGS; - } else if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.keygrip") == 0) { - err = NO_KEY_ERROR; - return ERROR; - } - err = GENERAL_ERROR; - return ERROR; - case FLAGS: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid") == 0) { - return VALID; - } - err = GENERAL_ERROR; - return ERROR; - case VALID: - if (status == GPGME_STATUS_KEY_CREATED) { - return KEY_CREATED; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } else if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid") == 0) { - err = INV_TIME_ERROR; - return ERROR; - } - err = GENERAL_ERROR; - return ERROR; - case KEY_CREATED: - return QUIT; - case QUIT: - if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "keyedit.save.okay") == 0) { - return SAVE; - } - err = GENERAL_ERROR; - return ERROR; - case ERROR: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = q->lastError(); - return ERROR; - default: - err = GENERAL_ERROR; - return ERROR; - } -} - -GpgAddExistingSubkeyEditInteractor::GpgAddExistingSubkeyEditInteractor(const std::string &keygrip) - : EditInteractor{} - , d{new Private{this, keygrip}} -{ -} - -GpgAddExistingSubkeyEditInteractor::~GpgAddExistingSubkeyEditInteractor() = default; - -void GpgAddExistingSubkeyEditInteractor::setExpiry(const std::string &timeString) -{ - d->expiry = timeString; -} - -const char *GpgAddExistingSubkeyEditInteractor::action(Error &err) const -{ - return d->action(err); -} - -unsigned int GpgAddExistingSubkeyEditInteractor::nextState(unsigned int status, const char *args, Error &err) const -{ - return d->nextState(status, args, err); -} diff --git a/lang/cpp/src/gpgaddexistingsubkeyeditinteractor.h b/lang/cpp/src/gpgaddexistingsubkeyeditinteractor.h deleted file mode 100644 index 2a580b6e..00000000 --- a/lang/cpp/src/gpgaddexistingsubkeyeditinteractor.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - gpgaddexistingsubkeyeditinteractor.h - Edit Interactor to add an existing subkey to an OpenPGP key - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__ -#define __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__ - -#include "editinteractor.h" - -#include <memory> -#include <string> - -namespace GpgME -{ - -class GPGMEPP_EXPORT GpgAddExistingSubkeyEditInteractor : public EditInteractor -{ -public: - /** Edit interactor to add the existing subkey with keygrip \a keygrip - * to the key a key edit operation is working on. - **/ - explicit GpgAddExistingSubkeyEditInteractor(const std::string &keygrip); - ~GpgAddExistingSubkeyEditInteractor() override; - - /** Sets the validity period of the added subkey. Use "0" for no expiration - * or a simplified ISO date string ("yyyymmddThhmmss") for setting an - * expiration date. */ - void setExpiry(const std::string &timeString); - -private: - const char *action(Error &err) const override; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; - -private: - class Private; - const std::unique_ptr<Private> d; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_GPGADDEXISTINGSUBKEYEDITINTERACTOR_H__ diff --git a/lang/cpp/src/gpgadduserideditinteractor.cpp b/lang/cpp/src/gpgadduserideditinteractor.cpp deleted file mode 100644 index 1f27c84f..00000000 --- a/lang/cpp/src/gpgadduserideditinteractor.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/* - gpgadduserideditinteractor.cpp - Edit Interactor to add a new UID to an OpenPGP key - Copyright (C) 2008 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "gpgadduserideditinteractor.h" - -#include "error.h" - -#include <gpgme.h> - -#include <cstring> - -using std::strcmp; - -// avoid conflict (msvc) -#ifdef ERROR -# undef ERROR -#endif - -using namespace GpgME; - -GpgAddUserIDEditInteractor::GpgAddUserIDEditInteractor() - : EditInteractor(), - m_name(), - m_email(), - m_comment() -{ - -} - -GpgAddUserIDEditInteractor::~GpgAddUserIDEditInteractor() {} - -void GpgAddUserIDEditInteractor::setNameUtf8(const std::string &name) -{ - m_name = name; -} - -void GpgAddUserIDEditInteractor::setEmailUtf8(const std::string &email) -{ - m_email = email; -} - -void GpgAddUserIDEditInteractor::setCommentUtf8(const std::string &comment) -{ - m_comment = comment; -} - -// work around --enable-final -namespace GpgAddUserIDEditInteractor_Private -{ -enum { - START = EditInteractor::StartState, - COMMAND, - NAME, - EMAIL, - COMMENT, - QUIT, - SAVE, - - ERROR = EditInteractor::ErrorState -}; -} - -const char *GpgAddUserIDEditInteractor::action(Error &err) const -{ - - using namespace GpgAddUserIDEditInteractor_Private; - - switch (state()) { - case COMMAND: - return "adduid"; - case NAME: - return m_name.c_str(); - case EMAIL: - return m_email.c_str(); - case COMMENT: - return m_comment.c_str(); - case QUIT: - return "quit"; - case SAVE: - return "Y"; - case START: - case ERROR: - return nullptr; - default: - err = Error::fromCode(GPG_ERR_GENERAL); - return nullptr; - } -} - -unsigned int GpgAddUserIDEditInteractor::nextState(unsigned int status, const char *args, Error &err) const -{ - - static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); - static const Error INV_NAME_ERROR = Error::fromCode(GPG_ERR_INV_NAME); - static const Error INV_EMAIL_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID); - static const Error INV_COMMENT_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID); - - using namespace GpgAddUserIDEditInteractor_Private; - - switch (state()) { - case START: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case COMMAND: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.name") == 0) { - return NAME; - } - err = GENERAL_ERROR; - return ERROR; - case NAME: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.email") == 0) { - return EMAIL; - } - err = GENERAL_ERROR; - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.name") == 0) { - err = INV_NAME_ERROR; - } - return ERROR; - case EMAIL: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.comment") == 0) { - return COMMENT; - } - err = GENERAL_ERROR; - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.email") == 0) { - err = INV_EMAIL_ERROR; - } - return ERROR; - case COMMENT: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = GENERAL_ERROR; - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.comment") == 0) { - err = INV_COMMENT_ERROR; - } - return ERROR; - case QUIT: - if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "keyedit.save.okay") == 0) { - return SAVE; - } - err = GENERAL_ERROR; - return ERROR; - case ERROR: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = lastError(); - return ERROR; - default: - err = GENERAL_ERROR; - return ERROR; - } -} diff --git a/lang/cpp/src/gpgadduserideditinteractor.h b/lang/cpp/src/gpgadduserideditinteractor.h deleted file mode 100644 index 68db32f2..00000000 --- a/lang/cpp/src/gpgadduserideditinteractor.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - gpgadduserideditinteractor.h - Edit Interactor to add a new UID to an OpenPGP key - Copyright (C) 2008 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGADDUSERIDEDITINTERACTOR_H__ -#define __GPGMEPP_GPGADDUSERIDEDITINTERACTOR_H__ - -#include "editinteractor.h" - -#include <string> - -namespace GpgME -{ - -class GPGMEPP_EXPORT GpgAddUserIDEditInteractor : public EditInteractor -{ -public: - explicit GpgAddUserIDEditInteractor(); - ~GpgAddUserIDEditInteractor(); - - void setNameUtf8(const std::string &name); - const std::string &nameUtf8() const - { - return m_name; - } - - void setEmailUtf8(const std::string &email); - const std::string &emailUtf8() const - { - return m_email; - } - - void setCommentUtf8(const std::string &comment); - const std::string &commentUtf8() const - { - return m_comment; - } - -private: - const char *action(Error &err) const override; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; - -private: - std::string m_name, m_email, m_comment; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_GPGADDUSERIDEDITINTERACTOR_H__ diff --git a/lang/cpp/src/gpgagentgetinfoassuantransaction.cpp b/lang/cpp/src/gpgagentgetinfoassuantransaction.cpp deleted file mode 100644 index e8524054..00000000 --- a/lang/cpp/src/gpgagentgetinfoassuantransaction.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - gpgagentgetinfoassuantransaction.cpp - Assuan Transaction to get information from gpg-agent - Copyright (C) 2009 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "gpgagentgetinfoassuantransaction.h" -#include "error.h" -#include "data.h" -#include "util.h" - -#include <assert.h> - -using namespace GpgME; - -GpgAgentGetInfoAssuanTransaction::GpgAgentGetInfoAssuanTransaction(InfoItem item) - : AssuanTransaction(), - m_item(item), - m_command(), - m_data() -{ - -} - -GpgAgentGetInfoAssuanTransaction::~GpgAgentGetInfoAssuanTransaction() {} - -std::string GpgAgentGetInfoAssuanTransaction::version() const -{ - if (m_item == Version) { - return m_data; - } else { - return std::string(); - } -} - -unsigned int GpgAgentGetInfoAssuanTransaction::pid() const -{ - if (m_item == Pid) { - return to_pid(m_data); - } else { - return 0U; - } -} - -std::string GpgAgentGetInfoAssuanTransaction::socketName() const -{ - if (m_item == SocketName) { - return m_data; - } else { - return std::string(); - } -} - -std::string GpgAgentGetInfoAssuanTransaction::sshSocketName() const -{ - if (m_item == SshSocketName) { - return m_data; - } else { - return std::string(); - } -} - -static const char *const gpgagent_getinfo_tokens[] = { - "version", - "pid", - "socket_name", - "ssh_socket_name", - "scd_running", -}; - -void GpgAgentGetInfoAssuanTransaction::makeCommand() const -{ - assert(m_item >= 0); - assert(m_item < LastInfoItem); - m_command = "GETINFO "; - m_command += gpgagent_getinfo_tokens[m_item]; -} - -const char *GpgAgentGetInfoAssuanTransaction::command() const -{ - makeCommand(); - return m_command.c_str(); -} - -Error GpgAgentGetInfoAssuanTransaction::data(const char *data, size_t len) -{ - m_data.append(data, len); - return Error(); -} - -Data GpgAgentGetInfoAssuanTransaction::inquire(const char *name, const char *args, Error &err) -{ - (void)name; (void)args; (void)err; - return Data::null; -} - -Error GpgAgentGetInfoAssuanTransaction::status(const char *status, const char *args) -{ - (void)status; (void)args; - return Error(); -} diff --git a/lang/cpp/src/gpgagentgetinfoassuantransaction.h b/lang/cpp/src/gpgagentgetinfoassuantransaction.h deleted file mode 100644 index b7178e42..00000000 --- a/lang/cpp/src/gpgagentgetinfoassuantransaction.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - gpgagentgetinfoassuantransaction.h - Assuan Transaction to get information from gpg-agent - Copyright (C) 2009 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGAGENTGETINFOASSUANTRANSACTION_H__ -#define __GPGMEPP_GPGAGENTGETINFOASSUANTRANSACTION_H__ - -#include "interfaces/assuantransaction.h" - -#include <string> -#include <vector> - -namespace GpgME -{ - -class GPGMEPP_EXPORT GpgAgentGetInfoAssuanTransaction : public AssuanTransaction -{ -public: - enum InfoItem { - Version, // string - Pid, // unsigned long - SocketName, // string (path) - SshSocketName, // string (path) - ScdRunning, // (none, returns GPG_ERR_GENERAL when scdaemon isn't running) - //CommandHasOption, // not supported - - LastInfoItem - }; - - explicit GpgAgentGetInfoAssuanTransaction(InfoItem item); - ~GpgAgentGetInfoAssuanTransaction(); - - std::string version() const; - unsigned int pid() const; - std::string socketName() const; - std::string sshSocketName() const; - -private: - const char *command() const; - Error data(const char *data, size_t datalen) override; - Data inquire(const char *name, const char *args, Error &err) override; - Error status(const char *status, const char *args) override; - -private: - void makeCommand() const; - -private: - InfoItem m_item; - mutable std::string m_command; - std::string m_data; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_GPGAGENTGETINFOASSUANTRANSACTION_H__ diff --git a/lang/cpp/src/gpggencardkeyinteractor.cpp b/lang/cpp/src/gpggencardkeyinteractor.cpp deleted file mode 100644 index cd226c27..00000000 --- a/lang/cpp/src/gpggencardkeyinteractor.cpp +++ /dev/null @@ -1,469 +0,0 @@ -/* - gpggencardkeyinteractor.cpp - Edit Interactor to generate a key on a card - Copyright (C) 2017 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "gpggencardkeyinteractor.h" - -#include "error.h" - -#include <gpgme.h> - -using namespace GpgME; - -class GpgGenCardKeyInteractor::Private -{ -public: - Private() : keysize("2048") - { - } - - std::string name, email, backupFileName, expiry, serial, keysize; - bool backup = false; - Algo algo = RSA; - std::string curve; -}; - -GpgGenCardKeyInteractor::~GpgGenCardKeyInteractor() = default; - -GpgGenCardKeyInteractor::GpgGenCardKeyInteractor(const std::string &serial): - d(new Private) -{ - d->serial = serial; -} - -void GpgGenCardKeyInteractor::setNameUtf8(const std::string &name) -{ - d->name = name; -} - -void GpgGenCardKeyInteractor::setEmailUtf8(const std::string &email) -{ - d->email = email; -} - -void GpgGenCardKeyInteractor::setDoBackup(bool value) -{ - d->backup = value; -} - -void GpgGenCardKeyInteractor::setKeySize(int value) -{ - d->keysize = std::to_string(value); -} - -void GpgGenCardKeyInteractor::setExpiry(const std::string &timeStr) -{ - d->expiry = timeStr; -} - -std::string GpgGenCardKeyInteractor::backupFileName() const -{ - return d->backupFileName; -} - -void GpgGenCardKeyInteractor::setAlgo(Algo algo) -{ - d->algo = algo; -} - -void GpgGenCardKeyInteractor::setCurve(Curve curve) -{ - if (curve == DefaultCurve) { - d->curve.clear(); - } else if (curve >= 1 && curve <= LastCurve) { - d->curve = std::to_string(static_cast<int>(curve)); - } -} - -namespace GpgGenCardKeyInteractor_Private -{ -enum { - START = EditInteractor::StartState, - DO_ADMIN, - EXPIRE, - - GOT_SERIAL, - COMMAND, - NAME, - EMAIL, - COMMENT, - BACKUP, - REPLACE, - SIZE, - SIZE2, - SIZE3, - BACKUP_KEY_CREATED, - KEY_CREATED, - QUIT, - SAVE, - - KEY_ATTR, - KEY_ALGO1, - KEY_ALGO2, - KEY_ALGO3, - KEY_CURVE1, - KEY_CURVE2, - KEY_CURVE3, - - ERROR = EditInteractor::ErrorState -}; -} - -const char *GpgGenCardKeyInteractor::action(Error &err) const -{ - - using namespace GpgGenCardKeyInteractor_Private; - - switch (state()) { - case DO_ADMIN: - return "admin"; - case COMMAND: - return "generate"; - case KEY_ATTR: - return "key-attr"; - case KEY_ALGO1: - case KEY_ALGO2: - case KEY_ALGO3: - return d->algo == RSA ? "1" : "2"; - case KEY_CURVE1: - case KEY_CURVE2: - case KEY_CURVE3: - return d->curve.empty() ? "1" : d->curve.c_str(); // default is Curve25519 - case NAME: - return d->name.c_str(); - case EMAIL: - return d->email.c_str(); - case EXPIRE: - return d->expiry.c_str(); - case BACKUP: - return d->backup ? "Y" : "N"; - case REPLACE: - return "Y"; - case SIZE: - case SIZE2: - case SIZE3: - return d->keysize.c_str(); - case COMMENT: - return ""; - case SAVE: - return "Y"; - case QUIT: - return "quit"; - case KEY_CREATED: - case START: - case GOT_SERIAL: - case BACKUP_KEY_CREATED: - case ERROR: - return nullptr; - default: - err = Error::fromCode(GPG_ERR_GENERAL); - return nullptr; - } -} - -unsigned int GpgGenCardKeyInteractor::nextState(unsigned int status, const char *args, Error &err) const -{ - - static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); - static const Error INV_NAME_ERROR = Error::fromCode(GPG_ERR_INV_NAME); - static const Error INV_EMAIL_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID); - static const Error INV_COMMENT_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID); - - using namespace GpgGenCardKeyInteractor_Private; - - switch (state()) { - case START: - if (status == GPGME_STATUS_CARDCTRL && - !d->serial.empty()) { - const std::string sArgs = args; - if (sArgs.find(d->serial) == std::string::npos) { - // Wrong smartcard - err = Error::fromCode(GPG_ERR_WRONG_CARD); - return ERROR; - } else { - printf("EditInteractor: Confirmed S/N: %s %s\n", - d->serial.c_str(), sArgs.c_str()); - } - return GOT_SERIAL; - } else if (d->serial.empty()) { - return GOT_SERIAL; - } - err = GENERAL_ERROR; - return ERROR; - case GOT_SERIAL: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return DO_ADMIN; - } - err = GENERAL_ERROR; - return ERROR; - case DO_ADMIN: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return KEY_ATTR; - } - err = GENERAL_ERROR; - return ERROR; - // Handling for key-attr subcommand - case KEY_ATTR: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - // Happens if key attr is not yet supported. - return COMMAND; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.algo") == 0) { - return KEY_ALGO1; - } - err = GENERAL_ERROR; - return ERROR; - case KEY_ALGO1: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.size") == 0) { - return SIZE; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.curve") == 0) { - return KEY_CURVE1; - } - err = GENERAL_ERROR; - return ERROR; - case KEY_ALGO2: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.size") == 0) { - return SIZE2; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.curve") == 0) { - return KEY_CURVE2; - } - err = GENERAL_ERROR; - return ERROR; - case KEY_ALGO3: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.size") == 0) { - return SIZE3; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.curve") == 0) { - return KEY_CURVE3; - } - err = GENERAL_ERROR; - return ERROR; - case KEY_CURVE1: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.algo") == 0) { - return KEY_ALGO2; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case KEY_CURVE2: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.algo") == 0) { - return KEY_ALGO3; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case KEY_CURVE3: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.algo") == 0) { - return KEY_ALGO3; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - // End key-attr handling - case COMMAND: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.backup_enc") == 0) { - return BACKUP; - } - err = GENERAL_ERROR; - return ERROR; - case BACKUP: - if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "cardedit.genkeys.replace_keys") == 0) { - return REPLACE; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.size") == 0) { - return SIZE; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid") == 0) { - return EXPIRE; - } - err = GENERAL_ERROR; - return ERROR; - case REPLACE: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.size") == 0) { - return SIZE; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid") == 0) { - return EXPIRE; - } - err = GENERAL_ERROR; - return ERROR; - case SIZE: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.size") == 0) { - return SIZE2; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid") == 0) { - return EXPIRE; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.algo") == 0) { - return KEY_ALGO2; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case SIZE2: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.size") == 0) { - return SIZE3; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid") == 0) { - return EXPIRE; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.genkeys.algo") == 0) { - return KEY_ALGO3; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case SIZE3: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid") == 0) { - return EXPIRE; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case EXPIRE: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.name") == 0) { - return NAME; - } - err = GENERAL_ERROR; - return ERROR; - case NAME: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.email") == 0) { - return EMAIL; - } - err = GENERAL_ERROR; - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.name") == 0) { - err = INV_NAME_ERROR; - } - return ERROR; - case EMAIL: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.comment") == 0) { - return COMMENT; - } - err = GENERAL_ERROR; - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.email") == 0) { - err = INV_EMAIL_ERROR; - } - return ERROR; - case COMMENT: - if (status == GPGME_STATUS_BACKUP_KEY_CREATED) { - std::string sArgs = args; - const auto pos = sArgs.rfind(" "); - if (pos != std::string::npos) { - d->backupFileName = sArgs.substr(pos + 1); - return BACKUP_KEY_CREATED; - } - } - if (status == GPGME_STATUS_KEY_CREATED) { - return KEY_CREATED; - } - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = GENERAL_ERROR; - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.comment") == 0) { - err = INV_COMMENT_ERROR; - } - return ERROR; - case BACKUP_KEY_CREATED: - if (status == GPGME_STATUS_KEY_CREATED) { - return KEY_CREATED; - } - err = GENERAL_ERROR; - return ERROR; - case KEY_CREATED: - return QUIT; - case QUIT: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "cardedit.prompt") == 0) { - return QUIT; - } - err = GENERAL_ERROR; - return ERROR; - case ERROR: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = lastError(); - return ERROR; - default: - err = GENERAL_ERROR; - return ERROR; - } -} diff --git a/lang/cpp/src/gpggencardkeyinteractor.h b/lang/cpp/src/gpggencardkeyinteractor.h deleted file mode 100644 index 25cfa6b1..00000000 --- a/lang/cpp/src/gpggencardkeyinteractor.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - gpggencardkeyinteractor.h - Edit Interactor to generate a key on a card - Copyright (C) 2017 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGGENCARDKEYEDITINTERACTOR_H__ -#define __GPGMEPP_GPGGENCARDKEYEDITINTERACTOR_H__ - -#include "editinteractor.h" - -#include <string> -#include <memory> - -namespace GpgME -{ - -class GPGMEPP_EXPORT GpgGenCardKeyInteractor: public EditInteractor -{ -public: - /** Edit interactor to generate a key on a smartcard. - * - * The \a serialnumber argument is intended to safeguard - * against accidentally working on the wrong smartcard. - * - * The edit interactor will fail if the card did not match. - * - * @param serialnumber: Serialnumber of the intended card. - **/ - explicit GpgGenCardKeyInteractor(const std::string &serialnumber); - ~GpgGenCardKeyInteractor(); - - /** Set the key sizes for the subkeys (default 2048) */ - void setKeySize(int size); - - void setNameUtf8(const std::string &name); - void setEmailUtf8(const std::string &email); - - void setDoBackup(bool value); - void setExpiry(const std::string &timeString); - - enum Algo { - RSA = 1, - ECC = 2, - }; - void setAlgo(Algo algo); - - // the enum values minus 1 have to match the indexes of the curves used by - // ask_curve() in gnupg's g10/keygen.c - enum Curve { - DefaultCurve = 0, // currently Curve25519 - Curve25519 = 1, - Curve448, - NISTP256, - NISTP384, - NISTP521, - BrainpoolP256, - BrainpoolP384, - BrainpoolP512, - Secp256k1, - LastCurve = Secp256k1, - }; - void setCurve(Curve curve); - - std::string backupFileName() const; - -private: - const char *action(Error &err) const override; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; - -private: - class Private; - std::shared_ptr<Private> d; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_GPGGENCARDKEYEDITINTERACTOR_H__ diff --git a/lang/cpp/src/gpgmefw.h b/lang/cpp/src/gpgmefw.h deleted file mode 100644 index c6166d2c..00000000 --- a/lang/cpp/src/gpgmefw.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - gpgmefw.h - Forwards declarations for gpgme (0.3 and 0.4) - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGMEFW_H__ -#define __GPGMEPP_GPGMEFW_H__ - -struct gpgme_context; -typedef gpgme_context *gpgme_ctx_t; - -struct gpgme_data; -typedef gpgme_data *gpgme_data_t; - -struct gpgme_io_cbs; - -struct _gpgme_key; -typedef struct _gpgme_key *gpgme_key_t; - -struct _gpgme_trust_item; -typedef struct _gpgme_trust_item *gpgme_trust_item_t; - -struct _gpgme_subkey; -typedef struct _gpgme_subkey *gpgme_sub_key_t; - -struct _gpgme_user_id; -typedef struct _gpgme_user_id *gpgme_user_id_t; - -struct _gpgme_key_sig; -typedef struct _gpgme_key_sig *gpgme_key_sig_t; - -struct _gpgme_sig_notation; -typedef struct _gpgme_sig_notation *gpgme_sig_notation_t; - -struct _gpgme_engine_info; -typedef struct _gpgme_engine_info *gpgme_engine_info_t; - -struct _gpgme_op_keylist_result; -typedef struct _gpgme_op_keylist_result *gpgme_keylist_result_t; - -struct _gpgme_recipient; -typedef struct _gpgme_recipient *gpgme_recipient_t; - -struct gpgme_conf_opt; -typedef struct gpgme_conf_opt *gpgme_conf_opt_t; - -struct gpgme_conf_comp; -typedef struct gpgme_conf_comp *gpgme_conf_comp_t; - -struct gpgme_conf_arg; -typedef struct gpgme_conf_arg *gpgme_conf_arg_t; - -struct _gpgme_tofu_info; -typedef struct _gpgme_tofu_info *gpgme_tofu_info_t; - -struct _gpgme_op_query_swdb_result; -typedef struct _gpgme_op_query_swdb_result *gpgme_query_swdb_result_t; - -struct _gpgme_revocation_key; -typedef struct _gpgme_revocation_key *gpgme_revocation_key_t; - -#endif // __GPGMEPP_GPGMEFW_H__ diff --git a/lang/cpp/src/gpgmepp.pc.in b/lang/cpp/src/gpgmepp.pc.in deleted file mode 100644 index 37c15357..00000000 --- a/lang/cpp/src/gpgmepp.pc.in +++ /dev/null @@ -1,13 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -includedir=@includedir@ -libdir=@libdir@ -host=@GPGMEPP_PKGCONFIG_HOST@ - -Name: gpgmepp -Description: GnuPG Made Easy (C++ binding) -Requires.private: gpg-error, gpgme -Version: @PACKAGE_VERSION@ -Cflags: @GPGMEPP_PKGCONFIG_CFLAGS@ -Libs: @GPGMEPP_PKGCONFIG_LIBS@ -URL: https://www.gnupg.org/software/gpgme/index.html diff --git a/lang/cpp/src/gpgmepp_export.h b/lang/cpp/src/gpgmepp_export.h deleted file mode 100644 index 0e5302f2..00000000 --- a/lang/cpp/src/gpgmepp_export.h +++ /dev/null @@ -1,74 +0,0 @@ -/*gpgmepp_export.h - Export macros for gpgmepp - Copyright (C) 2016, by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef GPGMEPP_EXPORT_H -#define GPGMEPP_EXPORT_H - -#ifdef GPGMEPP_STATIC_DEFINE -# define GPGMEPP_EXPORT -# define GPGMEPP_NO_EXPORT -#else -# ifndef GPGMEPP_EXPORT -# ifdef BUILDING_GPGMEPP - /* We are building this library */ -# ifdef WIN32 -# define GPGMEPP_EXPORT __declspec(dllexport) -# else -# define GPGMEPP_EXPORT __attribute__((visibility("default"))) -# endif -# else - /* We are using this library */ -# ifdef WIN32 -# define GPGMEPP_EXPORT __declspec(dllimport) -# else -# define GPGMEPP_EXPORT __attribute__((visibility("default"))) -# endif -# endif -# endif - -# ifndef GPGMEPP_NO_EXPORT -# ifdef WIN32 -# define GPGMEPP_NO_EXPORT -# else -# define GPGMEPP_NO_EXPORT __attribute__((visibility("hidden"))) -# endif -# endif -#endif - -#ifndef GPGMEPP_DEPRECATED -# define GPGMEPP_DEPRECATED __attribute__ ((__deprecated__)) -#endif - -#ifndef GPGMEPP_DEPRECATED_EXPORT -# define GPGMEPP_DEPRECATED_EXPORT GPGMEPP_EXPORT GPGMEPP_DEPRECATED -#endif - -#ifndef GPGMEPP_DEPRECATED_NO_EXPORT -# define GPGMEPP_DEPRECATED_NO_EXPORT GPGMEPP_NO_EXPORT GPGMEPP_DEPRECATED -#endif - -#define DEFINE_NO_DEPRECATED 0 -#if DEFINE_NO_DEPRECATED -# define GPGMEPP_NO_DEPRECATED -#endif - -#endif diff --git a/lang/cpp/src/gpgmepp_version.h.in b/lang/cpp/src/gpgmepp_version.h.in deleted file mode 100644 index 9cf6aeb0..00000000 --- a/lang/cpp/src/gpgmepp_version.h.in +++ /dev/null @@ -1,31 +0,0 @@ -/*gpgmepp_version.h - Version macros for gpgmepp - Copyright (C) 2016, Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - - -#ifndef GPGMEPP_VERSION_H -#define GPGMEPP_VERSION_H - -#define GPGMEPP_VERSION_STRING "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_MICRO@" -#define GPGMEPP_VERSION_MAJOR @VERSION_MAJOR@ -#define GPGMEPP_VERSION_MINOR @VERSION_MINOR@ -#define GPGMEPP_VERSION_PATCH @VERSION_MICRO@ -#define GPGMEPP_VERSION ((@VERSION_MAJOR@<<16)|(@VERSION_MINOR@<<8)|(@VERSION_MICRO@)) -#endif diff --git a/lang/cpp/src/gpgrevokekeyeditinteractor.cpp b/lang/cpp/src/gpgrevokekeyeditinteractor.cpp deleted file mode 100644 index dfa3be16..00000000 --- a/lang/cpp/src/gpgrevokekeyeditinteractor.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - gpgrevokekeyeditinteractor.cpp - Edit Interactor to revoke own OpenPGP keys - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "gpgrevokekeyeditinteractor.h" - -#include "error.h" - -#include <gpgme.h> - -#include <vector> - -// avoid conflict (msvc) -#ifdef ERROR -# undef ERROR -#endif - -using namespace GpgME; - -class GpgRevokeKeyEditInteractor::Private -{ - enum { - START = EditInteractor::StartState, - COMMAND, - CONFIRM_REVOKING_ENTIRE_KEY, - REASON_CODE, - REASON_TEXT, - // all these free slots belong to REASON_TEXT, too; we increase state() - // by one for each line of text, so that action() is called - REASON_TEXT_DONE = REASON_TEXT + 1000, - CONFIRM_REASON, - QUIT, - CONFIRM_SAVE, - - ERROR = EditInteractor::ErrorState - }; - - GpgRevokeKeyEditInteractor *const q = nullptr; - -public: - Private(GpgRevokeKeyEditInteractor *q) - : q{q} - , reasonCode{"0"} - { - } - - const char *action(Error &err) const; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err); - - std::string reasonCode; - std::vector<std::string> reasonLines; - int nextLine = -1; -}; - -const char *GpgRevokeKeyEditInteractor::Private::action(Error &err) const -{ - switch (const auto state = q->state()) { - case COMMAND: - return "revkey"; - case CONFIRM_REVOKING_ENTIRE_KEY: - return "Y"; - case REASON_CODE: - return reasonCode.c_str(); - case REASON_TEXT_DONE: - return ""; - case CONFIRM_REASON: - return "Y"; - case QUIT: - return "quit"; - case CONFIRM_SAVE: - return "Y"; - case START: - return nullptr; - default: - if (state >= REASON_TEXT && state < REASON_TEXT_DONE) { - return reasonLines[nextLine].c_str(); - } - // fall through - case ERROR: - err = Error::fromCode(GPG_ERR_GENERAL); - return nullptr; - } -} - -unsigned int GpgRevokeKeyEditInteractor::Private::nextState(unsigned int status, const char *args, Error &err) -{ - using std::strcmp; - - static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); - - switch (const auto state = q->state()) { - case START: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case COMMAND: - if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "keyedit.revoke.subkey.okay") == 0) { - return CONFIRM_REVOKING_ENTIRE_KEY; - } - err = GENERAL_ERROR; - return ERROR; - case CONFIRM_REVOKING_ENTIRE_KEY: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "ask_revocation_reason.code") == 0) { - return REASON_CODE; - } - err = GENERAL_ERROR; - return ERROR; - case REASON_CODE: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "ask_revocation_reason.text") == 0) { - nextLine++; - return static_cast<std::size_t>(nextLine) < reasonLines.size() ? REASON_TEXT : REASON_TEXT_DONE; - } - err = GENERAL_ERROR; - return ERROR; - default: - if (state >= REASON_TEXT && state < REASON_TEXT_DONE) { - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "ask_revocation_reason.text") == 0) { - nextLine++; - return static_cast<std::size_t>(nextLine) < reasonLines.size() ? state + 1 : REASON_TEXT_DONE; - } - } - err = GENERAL_ERROR; - return ERROR; - case REASON_TEXT_DONE: - if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "ask_revocation_reason.okay") == 0) { - return CONFIRM_REASON; - } - err = GENERAL_ERROR; - return ERROR; - case CONFIRM_REASON: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = GENERAL_ERROR; - return ERROR; - case QUIT: - if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "keyedit.save.okay") == 0) { - return CONFIRM_SAVE; - } - err = GENERAL_ERROR; - return ERROR; - case ERROR: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = q->lastError(); - return ERROR; - } -} - -GpgRevokeKeyEditInteractor::GpgRevokeKeyEditInteractor() - : EditInteractor{} - , d{new Private{this}} -{ -} - -GpgRevokeKeyEditInteractor::~GpgRevokeKeyEditInteractor() = default; - -void GpgRevokeKeyEditInteractor::setReason(RevocationReason reason, const std::vector<std::string> &description) -{ - d->reasonCode = std::to_string(static_cast<int>(reason)); - d->reasonLines = description; -} - -const char *GpgRevokeKeyEditInteractor::action(Error &err) const -{ - return d->action(err); -} - -unsigned int GpgRevokeKeyEditInteractor::nextState(unsigned int status, const char *args, Error &err) const -{ - return d->nextState(status, args, err); -} diff --git a/lang/cpp/src/gpgrevokekeyeditinteractor.h b/lang/cpp/src/gpgrevokekeyeditinteractor.h deleted file mode 100644 index 60c764d4..00000000 --- a/lang/cpp/src/gpgrevokekeyeditinteractor.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - gpgrevokekeyeditinteractor.h - Edit Interactor to revoke own OpenPGP keys - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGREVOKEKEYEDITINTERACTOR_H__ -#define __GPGMEPP_GPGREVOKEKEYEDITINTERACTOR_H__ - -#include "editinteractor.h" -#include "global.h" - -#include <memory> -#include <string> -#include <vector> - -namespace GpgME -{ - -/** Edit interactor to revoke the key a key edit operation is working on. - * Supports revocation of own keys only. */ -class GPGMEPP_EXPORT GpgRevokeKeyEditInteractor : public EditInteractor -{ -public: - GpgRevokeKeyEditInteractor(); - ~GpgRevokeKeyEditInteractor() override; - - /** Sets the reason for the revocation. The reason defaults to \c Unspecified. - * \a description can be used for adding a comment for the revocation. The - * individual elements of \a description must be non-empty strings and they - * must not contain any endline characters. - */ - void setReason(RevocationReason reason, const std::vector<std::string> &description = {}); - -private: - const char *action(Error &err) const override; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; - -private: - class GPGMEPP_NO_EXPORT Private; - const std::unique_ptr<Private> d; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_GPGREVOKEKEYEDITINTERACTOR_H__ diff --git a/lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp b/lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp deleted file mode 100644 index 2409ef19..00000000 --- a/lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - gpgsetexpirytimeeditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "gpgsetexpirytimeeditinteractor.h" -#include "error.h" - -#include <gpgme.h> - -#include <cstring> - -using std::strcmp; - -// avoid conflict (msvc) -#ifdef ERROR -# undef ERROR -#endif - -using namespace GpgME; - -GpgSetExpiryTimeEditInteractor::GpgSetExpiryTimeEditInteractor(const std::string &t) - : EditInteractor(), - m_strtime(t) -{ - -} - -GpgSetExpiryTimeEditInteractor::~GpgSetExpiryTimeEditInteractor() {} - -// work around --enable-final -namespace GpgSetExpiryTimeEditInteractor_Private -{ -enum { - START = EditInteractor::StartState, - COMMAND, - DATE, - QUIT, - SAVE, - - ERROR = EditInteractor::ErrorState -}; -} - -const char *GpgSetExpiryTimeEditInteractor::action(Error &err) const -{ - - using namespace GpgSetExpiryTimeEditInteractor_Private; - - switch (state()) { - case COMMAND: - return "expire"; - case DATE: - return m_strtime.c_str(); - case QUIT: - return "quit"; - case SAVE: - return "Y"; - case START: - case ERROR: - return nullptr; - default: - err = Error::fromCode(GPG_ERR_GENERAL); - return nullptr; - } -} - -unsigned int GpgSetExpiryTimeEditInteractor::nextState(unsigned int status, const char *args, Error &err) const -{ - - static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); - static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME); - - using namespace GpgSetExpiryTimeEditInteractor_Private; - - switch (state()) { - case START: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case COMMAND: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid") == 0) { - return DATE; - } - err = GENERAL_ERROR; - return ERROR; - case DATE: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } else if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keygen.valid")) { - err = INV_TIME_ERROR; - return ERROR; - } - err = GENERAL_ERROR; - return ERROR; - case QUIT: - if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "keyedit.save.okay") == 0) { - return SAVE; - } - err = GENERAL_ERROR; - return ERROR; - case ERROR: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = lastError(); - return ERROR; - default: - err = GENERAL_ERROR; - return ERROR; - } -} diff --git a/lang/cpp/src/gpgsetexpirytimeeditinteractor.h b/lang/cpp/src/gpgsetexpirytimeeditinteractor.h deleted file mode 100644 index c7221bad..00000000 --- a/lang/cpp/src/gpgsetexpirytimeeditinteractor.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - gpgsetexpirytimeeditinteractor.h - Edit Interactor to change the expiry time of an OpenPGP key - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H__ -#define __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H__ - -#include "editinteractor.h" - -#include <string> - -namespace GpgME -{ - -class GPGMEPP_EXPORT GpgSetExpiryTimeEditInteractor : public EditInteractor -{ -public: - explicit GpgSetExpiryTimeEditInteractor(const std::string &timeString = "0"); - ~GpgSetExpiryTimeEditInteractor(); - -private: - const char *action(Error &err) const override; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; - -private: - const std::string m_strtime; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_GPGSETEXPIRYTIMEEDITINTERACTOR_H___ diff --git a/lang/cpp/src/gpgsetownertrusteditinteractor.cpp b/lang/cpp/src/gpgsetownertrusteditinteractor.cpp deleted file mode 100644 index e28951ba..00000000 --- a/lang/cpp/src/gpgsetownertrusteditinteractor.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - gpgsetownertrusteditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "gpgsetownertrusteditinteractor.h" -#include "error.h" - -#include <gpgme.h> - -#include <cstring> - -using std::strcmp; - -// avoid conflict (msvc) -#ifdef ERROR -# undef ERROR -#endif - -using namespace GpgME; - -GpgSetOwnerTrustEditInteractor::GpgSetOwnerTrustEditInteractor(Key::OwnerTrust ot) - : EditInteractor(), - m_ownertrust(ot) -{ - -} - -GpgSetOwnerTrustEditInteractor::~GpgSetOwnerTrustEditInteractor() {} - -// work around --enable-final -namespace GpgSetOwnerTrustEditInteractor_Private -{ -enum { - START = EditInteractor::StartState, - COMMAND, - VALUE, - REALLY_ULTIMATE, - QUIT, - SAVE, - - ERROR = EditInteractor::ErrorState -}; -} - -const char *GpgSetOwnerTrustEditInteractor::action(Error &err) const -{ - static const char truststrings[][2] = { "1", "1", "2", "3", "4", "5" }; - - using namespace GpgSetOwnerTrustEditInteractor_Private; - - switch (state()) { - case COMMAND: - return "trust"; - case VALUE: - return truststrings[m_ownertrust]; - case REALLY_ULTIMATE: - return "Y"; - case QUIT: - return "quit"; - case SAVE: - return "Y"; - case START: - case ERROR: - return nullptr; - default: - err = Error::fromCode(GPG_ERR_GENERAL); - return nullptr; - } -} - -unsigned int GpgSetOwnerTrustEditInteractor::nextState(unsigned int status, const char *args, Error &err) const -{ - - static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); - //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME ); - - using namespace GpgSetOwnerTrustEditInteractor_Private; - - switch (state()) { - case START: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return COMMAND; - } - err = GENERAL_ERROR; - return ERROR; - case COMMAND: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "edit_ownertrust.value") == 0) { - return VALUE; - } - err = GENERAL_ERROR; - return ERROR; - case VALUE: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } else if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "edit_ownertrust.set_ultimate.okay") == 0) { - return REALLY_ULTIMATE; - } - err = GENERAL_ERROR; - return ERROR; - case REALLY_ULTIMATE: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = GENERAL_ERROR; - return ERROR; - case QUIT: - if (status == GPGME_STATUS_GET_BOOL && - strcmp(args, "keyedit.save.okay") == 0) { - return SAVE; - } - err = GENERAL_ERROR; - return ERROR; - case ERROR: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return QUIT; - } - err = lastError(); - return ERROR; - default: - err = GENERAL_ERROR; - return ERROR; - }; -} diff --git a/lang/cpp/src/gpgsetownertrusteditinteractor.h b/lang/cpp/src/gpgsetownertrusteditinteractor.h deleted file mode 100644 index a1ddb1ba..00000000 --- a/lang/cpp/src/gpgsetownertrusteditinteractor.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - gpgsetownertrusteditinteractor.h - Edit Interactor to change the owner trust of an OpenPGP key - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__ -#define __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__ - -#include "editinteractor.h" -#include "key.h" - -#include <string> - -namespace GpgME -{ - -class GPGMEPP_EXPORT GpgSetOwnerTrustEditInteractor : public EditInteractor -{ -public: - explicit GpgSetOwnerTrustEditInteractor(Key::OwnerTrust ownertrust); - ~GpgSetOwnerTrustEditInteractor(); - -private: - const char *action(Error &err) const override; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; - -private: - const Key::OwnerTrust m_ownertrust; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_GPGSETOWNERTRUSTEDITINTERACTOR_H__ diff --git a/lang/cpp/src/gpgsignkeyeditinteractor.cpp b/lang/cpp/src/gpgsignkeyeditinteractor.cpp deleted file mode 100644 index 164cfc03..00000000 --- a/lang/cpp/src/gpgsignkeyeditinteractor.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/* - gpgsignkeyeditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key - Copyright (C) 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "gpgsignkeyeditinteractor.h" -#include "error.h" -#include "key.h" - -#include <gpgme.h> - -#include <map> -#include <string> -#include <sstream> - -#include <cassert> -#include <cstring> - -using std::strcmp; - -// avoid conflict (msvc) -#ifdef ERROR -# undef ERROR -#endif - -#ifdef _MSC_VER -#undef snprintf -#define snprintf _snprintf -#endif - -using namespace GpgME; - -class GpgSignKeyEditInteractor::Private -{ -public: - Private(); - - std::string scratch; - bool started; - int options; - std::vector<unsigned int> userIDs; - std::vector<unsigned int>::const_iterator currentId, nextId; - unsigned int checkLevel; - bool dupeOk; - Key key; - struct { - TrustSignatureTrust trust; - std::string depth; - std::string scope; - } trustSignature; - - const char *command() const - { - const bool local = (options & Exportable) == 0; - const bool nonRevoc = options & NonRevocable; - const bool trust = options & Trust; - //TODO: check if all combinations are valid - if (local && nonRevoc && trust) { - return "ltnrsign"; - } - if (local && nonRevoc) { - return "lnrsign"; - } - if (local && trust) { - return "ltsign"; - } - if (local) { - return "lsign"; - } - if (nonRevoc && trust) { - return "tnrsign"; - } - if (nonRevoc) { - return "nrsign"; - } - if (trust) { - return "tsign"; - } - return "sign"; - } - - bool signAll() const - { - return userIDs.empty(); - } - unsigned int nextUserID() - { - assert(nextId != userIDs.end()); - currentId = nextId++; - return currentUserID(); - } - - bool allUserIDsListed() const - { - return nextId == userIDs.end(); - } - - unsigned int currentUserID() const - { - assert(currentId != userIDs.end()); - return *currentId + 1; - } - -}; - -GpgSignKeyEditInteractor::Private::Private() - : - started(false), - options(0), - userIDs(), - currentId(), - nextId(), - checkLevel(0), - dupeOk(false), - trustSignature{TrustSignatureTrust::None, "0", {}} -{ -} - -GpgSignKeyEditInteractor::GpgSignKeyEditInteractor() - : EditInteractor(), d(new Private) -{ - -} - -GpgSignKeyEditInteractor::~GpgSignKeyEditInteractor() -{ - delete d; -} - -// work around --enable-final -namespace GpgSignKeyEditInteractor_Private -{ -enum SignKeyState { - START = EditInteractor::StartState, - COMMAND, - UIDS_ANSWER_SIGN_ALL, - UIDS_LIST_SEPARATELY, - // all these free slots belong to UIDS_LIST_SEPARATELY, too - // (we increase state() by one for each UID, so that action() is called) - UIDS_LIST_SEPARATELY_DONE = 1000000, - SET_EXPIRE, - SET_CHECK_LEVEL, - SET_TRUST_VALUE, - SET_TRUST_DEPTH, - SET_TRUST_REGEXP, - CONFIRM, - CONFIRM2, - DUPE_OK, - DUPE_OK2, - REJECT_SIGN_EXPIRED, - QUIT, - SAVE, - ERROR = EditInteractor::ErrorState -}; - -typedef std::map<std::tuple<SignKeyState, unsigned int, std::string>, SignKeyState> TransitionMap; - -} - -static const char *answer(bool b) -{ - return b ? "Y" : "N"; -} - -static GpgSignKeyEditInteractor_Private::TransitionMap makeTable() -{ - using namespace GpgSignKeyEditInteractor_Private; - TransitionMap tab; - const unsigned int GET_BOOL = GPGME_STATUS_GET_BOOL; - const unsigned int GET_LINE = GPGME_STATUS_GET_LINE; -#define addEntry( s1, status, str, s2 ) tab[std::make_tuple( s1, status, str)] = s2 - addEntry(START, GET_LINE, "keyedit.prompt", COMMAND); - addEntry(COMMAND, GET_BOOL, "keyedit.sign_all.okay", UIDS_ANSWER_SIGN_ALL); - addEntry(COMMAND, GET_BOOL, "sign_uid.expired_okay", REJECT_SIGN_EXPIRED); - addEntry(COMMAND, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(COMMAND, GET_BOOL, "sign_uid.local_promote_okay", CONFIRM2); - addEntry(COMMAND, GET_BOOL, "sign_uid.dupe_okay", DUPE_OK); - addEntry(COMMAND, GET_LINE, "trustsig_prompt.trust_value", SET_TRUST_VALUE); - addEntry(UIDS_ANSWER_SIGN_ALL, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(UIDS_ANSWER_SIGN_ALL, GET_BOOL, "sign_uid.dupe_okay", DUPE_OK); - addEntry(UIDS_ANSWER_SIGN_ALL, GET_LINE, "sign_uid.expire", SET_EXPIRE); - addEntry(UIDS_ANSWER_SIGN_ALL, GET_LINE, "sign_uid.class", SET_CHECK_LEVEL); - addEntry(UIDS_ANSWER_SIGN_ALL, GET_LINE, "trustsig_prompt.trust_value", SET_TRUST_VALUE); - addEntry(SET_TRUST_VALUE, GET_LINE, "trustsig_prompt.trust_depth", SET_TRUST_DEPTH); - addEntry(SET_TRUST_DEPTH, GET_LINE, "trustsig_prompt.trust_regexp", SET_TRUST_REGEXP); - addEntry(SET_TRUST_REGEXP, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(SET_CHECK_LEVEL, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(SET_EXPIRE, GET_BOOL, "sign_uid.class", SET_CHECK_LEVEL); - addEntry(CONFIRM, GET_BOOL, "sign_uid.local_promote_okay", CONFIRM); - addEntry(DUPE_OK, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(DUPE_OK2, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(DUPE_OK, GET_LINE, "trustsig_prompt.trust_value", SET_TRUST_VALUE); - addEntry(DUPE_OK2, GET_LINE, "trustsig_prompt.trust_value", SET_TRUST_VALUE); - addEntry(CONFIRM, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(CONFIRM2, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(CONFIRM, GET_LINE, "keyedit.prompt", COMMAND); - addEntry(CONFIRM, GET_LINE, "trustsig_prompt.trust_value", SET_TRUST_VALUE); - addEntry(CONFIRM, GET_LINE, "sign_uid.expire", SET_EXPIRE); - addEntry(CONFIRM, GET_LINE, "sign_uid.class", SET_CHECK_LEVEL); - addEntry(UIDS_LIST_SEPARATELY_DONE, GET_BOOL, "sign_uid.local_promote_okay", CONFIRM); - addEntry(UIDS_LIST_SEPARATELY_DONE, GET_LINE, "keyedit.prompt", COMMAND); - addEntry(UIDS_LIST_SEPARATELY_DONE, GET_LINE, "trustsig_prompt.trust_value", SET_TRUST_VALUE); - addEntry(UIDS_LIST_SEPARATELY_DONE, GET_LINE, "sign_uid.expire", SET_EXPIRE); - addEntry(UIDS_LIST_SEPARATELY_DONE, GET_LINE, "sign_uid.class", SET_CHECK_LEVEL); - addEntry(UIDS_LIST_SEPARATELY_DONE, GET_BOOL, "sign_uid.okay", CONFIRM); - addEntry(UIDS_LIST_SEPARATELY_DONE, GET_BOOL, "sign_uid.dupe_okay", DUPE_OK); - addEntry(DUPE_OK, GET_BOOL, "sign_uid.dupe_okay", DUPE_OK2); - addEntry(DUPE_OK2, GET_BOOL, "sign_uid.dupe_okay", DUPE_OK); - addEntry(CONFIRM, GET_LINE, "keyedit.prompt", QUIT); - addEntry(REJECT_SIGN_EXPIRED, GET_LINE, "keyedit.prompt", QUIT); - addEntry(ERROR, GET_LINE, "keyedit.prompt", QUIT); - addEntry(QUIT, GET_BOOL, "keyedit.save.okay", SAVE); -#undef addEntry - return tab; -} - -const char *GpgSignKeyEditInteractor::action(Error &err) const -{ - static const char check_level_strings[][2] = { "0", "1", "2", "3" }; - using namespace GpgSignKeyEditInteractor_Private; - using namespace std; - - switch (const unsigned int st = state()) { - case COMMAND: - return d->command(); - case UIDS_ANSWER_SIGN_ALL: - return answer(d->signAll()); - case UIDS_LIST_SEPARATELY_DONE: - return d->command(); - case SET_EXPIRE: - return answer(true); - case SET_TRUST_VALUE: - return d->trustSignature.trust == TrustSignatureTrust::Partial ? "1" : "2"; - case SET_TRUST_DEPTH: - return d->trustSignature.depth.c_str(); - case SET_TRUST_REGEXP: - return d->trustSignature.scope.c_str(); - case SET_CHECK_LEVEL: - return check_level_strings[d->checkLevel]; - case DUPE_OK: - case DUPE_OK2: - return answer(d->dupeOk); - case CONFIRM2: - case CONFIRM: - return answer(true); - case REJECT_SIGN_EXPIRED: - err = Error::fromCode(GPG_ERR_KEY_EXPIRED); - return answer(false); - case QUIT: - return "quit"; - case SAVE: - return answer(true); - default: - if (st >= UIDS_LIST_SEPARATELY && st < UIDS_LIST_SEPARATELY_DONE) { - std::stringstream ss; - auto nextID = d->nextUserID(); - const char *hash; - assert (nextID); - if (!d->key.isNull() && (hash = d->key.userID(nextID - 1).uidhash())) { - /* Prefer uidhash if it is available as it might happen - * that uidattrs break the ordering of the uids in the - * edit-key interface */ - ss << "uid " << hash; - } else { - ss << nextID; - } - d->scratch = ss.str(); - return d->scratch.c_str(); - } - // fall through - case ERROR: - err = Error::fromCode(GPG_ERR_GENERAL); - return nullptr; - } -} - -unsigned int GpgSignKeyEditInteractor::nextState(unsigned int status, const char *args, Error &err) const -{ - d->started = true; - using namespace GpgSignKeyEditInteractor_Private; - static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL); - //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME ); - static const TransitionMap table(makeTable()); - - using namespace GpgSignKeyEditInteractor_Private; - - //lookup transition in map - const TransitionMap::const_iterator it = table.find(std::make_tuple(static_cast<SignKeyState>(state()), status, std::string(args))); - if (it != table.end()) { - return it->second; - } - - //handle cases that cannot be handled via the map - switch (const unsigned int st = state()) { - case UIDS_ANSWER_SIGN_ALL: - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - if (!d->signAll()) { - return UIDS_LIST_SEPARATELY; - } - err = Error::fromCode(GPG_ERR_UNUSABLE_PUBKEY); - return ERROR; - } - break; - default: - if (st >= UIDS_LIST_SEPARATELY && st < UIDS_LIST_SEPARATELY_DONE) { - if (status == GPGME_STATUS_GET_LINE && - strcmp(args, "keyedit.prompt") == 0) { - return d->allUserIDsListed() ? UIDS_LIST_SEPARATELY_DONE : st + 1 ; - } - } - break; - case CONFIRM: - case ERROR: - err = lastError(); - return ERROR; - } - - err = GENERAL_ERROR; - return ERROR; -} -void GpgSignKeyEditInteractor::setKey(const Key &key) -{ - d->key = key; -} - -void GpgSignKeyEditInteractor::setCheckLevel(unsigned int checkLevel) -{ - assert(!d->started); - assert(checkLevel <= 3); - d->checkLevel = checkLevel; -} - -void GpgSignKeyEditInteractor::setUserIDsToSign(const std::vector<unsigned int> &userIDsToSign) -{ - assert(!d->started); - d->userIDs = userIDsToSign; - d->nextId = d->userIDs.begin(); - d->currentId = d->userIDs.end(); - -} -void GpgSignKeyEditInteractor::setSigningOptions(int options) -{ - assert(!d->started); - d->options = options; -} - -void GpgSignKeyEditInteractor::setDupeOk(bool value) -{ - assert(!d->started); - d->dupeOk = value; -} - -void GpgSignKeyEditInteractor::setTrustSignatureTrust(GpgME::TrustSignatureTrust trust) -{ - assert(!d->started); - assert(trust != TrustSignatureTrust::None); - d->trustSignature.trust = trust; -} - -void GpgSignKeyEditInteractor::setTrustSignatureDepth(unsigned short depth) -{ - assert(!d->started); - assert(depth <= 255); - d->trustSignature.depth = std::to_string(depth); -} - -void GpgSignKeyEditInteractor::setTrustSignatureScope(const std::string &scope) -{ - assert(!d->started); - d->trustSignature.scope = scope; -} diff --git a/lang/cpp/src/gpgsignkeyeditinteractor.h b/lang/cpp/src/gpgsignkeyeditinteractor.h deleted file mode 100644 index 8b8a2b52..00000000 --- a/lang/cpp/src/gpgsignkeyeditinteractor.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - gpgsignkeyeditinteractor.h - Edit Interactor to change the owner trust of an OpenPGP key - Copyright (C) 2008 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_GPGSIGNKEYEDITINTERACTOR_H__ -#define __GPGMEPP_GPGSIGNKEYEDITINTERACTOR_H__ - -#include "editinteractor.h" - -#include <string> -#include <vector> - -namespace GpgME -{ - -class Key; -class UserID; -enum class TrustSignatureTrust : char; - -class GPGMEPP_EXPORT GpgSignKeyEditInteractor : public EditInteractor -{ -public: - enum SignOption { - Exportable = 0x1, - NonRevocable = 0x2, - Trust = 0x4 - }; - - GpgSignKeyEditInteractor(); - ~GpgSignKeyEditInteractor(); - - void setCheckLevel(unsigned int checkLevel); - void setUserIDsToSign(const std::vector<unsigned int> &userIDsToSign); - void setKey(const Key &key); - void setSigningOptions(int options); - - /* Set this if it is ok to overwrite an existing signature. In that - * case the context has to have the flag "extended-edit" set to 1 through - * Context::setFlag before calling edit.*/ - void setDupeOk(bool value); - - void setTrustSignatureTrust(TrustSignatureTrust trust); - void setTrustSignatureDepth(unsigned short depth); - void setTrustSignatureScope(const std::string &scope); - -private: - const char *action(Error &err) const override; - unsigned int nextState(unsigned int statusCode, const char *args, Error &err) const override; - -private: - class Private; - Private *const d; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_GPGSIGNKEYEDITINTERACTOR_H__ diff --git a/lang/cpp/src/importresult.cpp b/lang/cpp/src/importresult.cpp deleted file mode 100644 index 0a7ad03d..00000000 --- a/lang/cpp/src/importresult.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/* - importresult.cpp - wraps a gpgme import result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <importresult.h> -#include "result_p.h" - -#include <gpgme.h> -#include <cstdlib> -#include <cstring> - -#include <string.h> -#include <strings.h> -#include <istream> -#include <iterator> - -class GpgME::ImportResult::Private -{ -public: - Private(const _gpgme_op_import_result &r) : res(r) - { - // copy recursively, using compiler-generated copy ctor. - // We just need to handle the pointers in the structs: - for (gpgme_import_status_t is = r.imports ; is ; is = is->next) { - gpgme_import_status_t copy = new _gpgme_import_status(*is); - if (is->fpr) { - copy->fpr = strdup(is->fpr); - } - copy->next = nullptr; - imports.push_back(copy); - } - res.imports = nullptr; - } - ~Private() - { - for (std::vector<gpgme_import_status_t>::iterator it = imports.begin() ; it != imports.end() ; ++it) { - std::free((*it)->fpr); - delete *it; *it = nullptr; - } - } - - _gpgme_op_import_result res; - std::vector<gpgme_import_status_t> imports; -}; - -GpgME::ImportResult::ImportResult(gpgme_ctx_t ctx, int error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -GpgME::ImportResult::ImportResult(gpgme_ctx_t ctx, const Error &error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -void GpgME::ImportResult::init(gpgme_ctx_t ctx) -{ - if (!ctx) { - return; - } - gpgme_import_result_t res = gpgme_op_import_result(ctx); - if (!res) { - return; - } - d.reset(new Private(*res)); -} - -make_standard_stuff(ImportResult) - -void GpgME::ImportResult::mergeWith(const ImportResult &other) -{ - if (other.isNull()) { - return; - } - if (isNull()) { // just assign - operator=(other); - return; - } - - // Add the numbers of considered keys; the number will be corrected when - // merging the imports to account for duplicates - d->res.considered += other.d->res.considered; - // Add the numbers of keys without user ID; may count duplicates - d->res.no_user_id += other.d->res.no_user_id; - // Add the numbers of imported keys - d->res.imported += other.d->res.imported; - // Add the numbers of imported RSA keys - d->res.imported_rsa += other.d->res.imported_rsa; - // Add the numbers of unchanged keys; the number will be corrected when - // merging the imports to account for keys changed by this import - d->res.unchanged += other.d->res.unchanged; - // Add the numbers of new user IDs - d->res.new_user_ids += other.d->res.new_user_ids; - // Add the numbers of new subkeys - d->res.new_sub_keys += other.d->res.new_sub_keys; - // Add the numbers of new signatures - d->res.new_signatures += other.d->res.new_signatures; - // Add the numbers of new revocations - d->res.new_revocations += other.d->res.new_revocations; - - // Add the numbers of considered secret keys; the number will be corrected when - // merging the imports to account for duplicates - d->res.secret_read += other.d->res.secret_read; - // Add the numbers of imported secret keys - d->res.secret_imported += other.d->res.secret_imported; - // Add the numbers of unchanged secret keys; the number will be corrected when - // merging the imports to account for keys changed by this import - d->res.secret_unchanged += other.d->res.secret_unchanged; - - // Add the numbers of new keys that were skipped; may count duplicates - d->res.skipped_new_keys += other.d->res.skipped_new_keys; - // Add the numbers of keys that were not imported; may count duplicates - d->res.not_imported += other.d->res.not_imported; - // Add the numbers of v3 keys that were skipped; may count duplicates - d->res.skipped_v3_keys += other.d->res.skipped_v3_keys; - - // Look at the list of keys for which an import was attempted during the - // other import to correct some of the consolidated numbers - for (auto it = std::begin(other.d->imports), end = std::end(other.d->imports); it != end; ++it) { - const char *fpr = (*it)->fpr; - if (!fpr || !*fpr) { - // we cannot derive any useful information about an import if the - // fingerprint is null or empty - continue; - } - // was this key also considered during the first import - const auto consideredInFirstImports = - std::any_of(std::begin(d->imports), std::end(d->imports), [fpr](const gpgme_import_status_t i) { - return i->fpr && !strcmp(i->fpr, fpr); - }); - // did we see this key already in the list of keys of the other import - const auto consideredInPreviousOtherImports = - std::any_of(std::begin(other.d->imports), it, [fpr](const gpgme_import_status_t i) { - return i->fpr && !strcmp(i->fpr, fpr); - }); - // was anything added to this key during the other import - const auto changedInOtherImports = - std::any_of(std::begin(other.d->imports), std::end(other.d->imports), [fpr](const gpgme_import_status_t i) { - return i->fpr && !strcmp(i->fpr, fpr) && (i->status != 0); - }); - if (consideredInFirstImports && !consideredInPreviousOtherImports) { - // key was also considered during first import, but not before in the list of other imports - d->res.considered -= 1; - if (!changedInOtherImports) { - // key was (most likely) counted as unchanged in the second import; - // this needs to be corrected (regardless of whether it was changed in the first import) - d->res.unchanged -= 1; - } - } - - // now do the same for the secret key counts - const auto secretKeyConsideredInFirstImports = - std::any_of(std::begin(d->imports), std::end(d->imports), [fpr](const gpgme_import_status_t i) { - return i->fpr && !strcmp(i->fpr, fpr) && (i->status & GPGME_IMPORT_SECRET); - }); - const auto secretKeyConsideredInPreviousOtherImports = - std::any_of(std::begin(other.d->imports), it, [fpr](const gpgme_import_status_t i) { - return i->fpr && !strcmp(i->fpr, fpr) && (i->status & GPGME_IMPORT_SECRET); - }); - const auto secretKeyChangedInOtherImports = - std::any_of(std::begin(other.d->imports), std::end(other.d->imports), [fpr](const gpgme_import_status_t i) { - return i->fpr && !strcmp(i->fpr, fpr) && (i->status & GPGME_IMPORT_SECRET) && (i->status != GPGME_IMPORT_SECRET); - }); - if (secretKeyConsideredInFirstImports && !secretKeyConsideredInPreviousOtherImports) { - // key was also considered during first import, but not before in the list of other imports - d->res.secret_read -= 1; - if (!secretKeyChangedInOtherImports) { - // key was (most likely) counted as unchanged in the second import; - // this needs to be corrected (regardless of whether it was changed in the first import) - d->res.secret_unchanged -= 1; - } - } - } - - // Now append the list of keys for which an import was attempted during the - // other import - d->imports.reserve(d->imports.size() + other.d->imports.size()); - std::transform(std::begin(other.d->imports), std::end(other.d->imports), - std::back_inserter(d->imports), - [](const gpgme_import_status_t import) { - gpgme_import_status_t copy = new _gpgme_import_status{*import}; - if (import->fpr) { - copy->fpr = strdup(import->fpr); - } - copy->next = nullptr; // should already be null, but better safe than sorry - return copy; - }); - - // Finally, merge the error if there was none yet - if (!bool(error())) { - Result::operator=(other); - } -} - -int GpgME::ImportResult::numConsidered() const -{ - return d ? d->res.considered : 0 ; -} - -int GpgME::ImportResult::numKeysWithoutUserID() const -{ - return d ? d->res.no_user_id : 0 ; -} - -int GpgME::ImportResult::numImported() const -{ - return d ? d->res.imported : 0 ; -} - -int GpgME::ImportResult::numRSAImported() const -{ - return d ? d->res.imported_rsa : 0 ; -} - -int GpgME::ImportResult::numUnchanged() const -{ - return d ? d->res.unchanged : 0 ; -} - -int GpgME::ImportResult::newUserIDs() const -{ - return d ? d->res.new_user_ids : 0 ; -} - -int GpgME::ImportResult::newSubkeys() const -{ - return d ? d->res.new_sub_keys : 0 ; -} - -int GpgME::ImportResult::newSignatures() const -{ - return d ? d->res.new_signatures : 0 ; -} - -int GpgME::ImportResult::newRevocations() const -{ - return d ? d->res.new_revocations : 0 ; -} - -int GpgME::ImportResult::numSecretKeysConsidered() const -{ - return d ? d->res.secret_read : 0 ; -} - -int GpgME::ImportResult::numSecretKeysImported() const -{ - return d ? d->res.secret_imported : 0 ; -} - -int GpgME::ImportResult::numSecretKeysUnchanged() const -{ - return d ? d->res.secret_unchanged : 0 ; -} - -int GpgME::ImportResult::notImported() const -{ - return d ? d->res.not_imported : 0 ; -} - -int GpgME::ImportResult::numV3KeysSkipped() const -{ - return d ? d->res.skipped_v3_keys : 0 ; -} - -GpgME::Import GpgME::ImportResult::import(unsigned int idx) const -{ - return Import(d, idx); -} - -std::vector<GpgME::Import> GpgME::ImportResult::imports() const -{ - if (!d) { - return std::vector<Import>(); - } - std::vector<Import> result; - result.reserve(d->imports.size()); - for (unsigned int i = 0 ; i < d->imports.size() ; ++i) { - result.push_back(Import(d, i)); - } - return result; -} - -GpgME::Import::Import(const std::shared_ptr<ImportResult::Private> &parent, unsigned int i) - : d(parent), idx(i) -{ - -} - -GpgME::Import::Import() : d(), idx(0) {} - -bool GpgME::Import::isNull() const -{ - return !d || idx >= d->imports.size() ; -} - -const char *GpgME::Import::fingerprint() const -{ - return isNull() ? nullptr : d->imports[idx]->fpr ; -} - -GpgME::Error GpgME::Import::error() const -{ - return Error(isNull() ? 0 : d->imports[idx]->result); -} - -GpgME::Import::Status GpgME::Import::status() const -{ - if (isNull()) { - return Unknown; - } - const unsigned int s = d->imports[idx]->status; - unsigned int result = Unknown; - if (s & GPGME_IMPORT_NEW) { - result |= NewKey; - } - if (s & GPGME_IMPORT_UID) { - result |= NewUserIDs; - } - if (s & GPGME_IMPORT_SIG) { - result |= NewSignatures; - } - if (s & GPGME_IMPORT_SUBKEY) { - result |= NewSubkeys; - } - if (s & GPGME_IMPORT_SECRET) { - result |= ContainedSecretKey; - } - return static_cast<Status>(result); -} - -std::ostream &GpgME::operator<<(std::ostream &os, - const GpgME::ImportResult &result) -{ - os << "GpgME::ImportResult("; - if (!result.isNull()) { - os << "\n considered: " << result.numConsidered() - << "\n without UID: " << result.numKeysWithoutUserID() - << "\n imported: " << result.numImported() - << "\n RSA Imported: " << result.numRSAImported() - << "\n unchanged: " << result.numUnchanged() - << "\n newUserIDs: " << result.newUserIDs() - << "\n newSubkeys: " << result.newSubkeys() - << "\n newSignatures: " << result.newSignatures() - << "\n newRevocations: " << result.newRevocations() - << "\n numSecretKeysConsidered: " << result.numSecretKeysConsidered() - << "\n numSecretKeysImported: " << result.numSecretKeysImported() - << "\n numSecretKeysUnchanged: " << result.numSecretKeysUnchanged() - << "\n" - << "\n notImported: " << result.notImported() - << "\n numV3KeysSkipped: " << result.numV3KeysSkipped() - << "\n imports:\n"; - const std::vector<Import> imp = result.imports(); - std::copy(imp.begin(), imp.end(), - std::ostream_iterator<Import>(os, "\n")); - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const GpgME::Import &imp) -{ - os << "GpgME::Import("; - if (!imp.isNull()) { - os << "\n fpr: " << (imp.fingerprint() ? imp.fingerprint() : "null") - << "\n status: " << imp.status() - << "\n err: " << imp.error(); - } - return os << ')'; -} diff --git a/lang/cpp/src/importresult.h b/lang/cpp/src/importresult.h deleted file mode 100644 index a2749331..00000000 --- a/lang/cpp/src/importresult.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - importresult.h - wraps a gpgme import result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_IMPORTRESULT_H__ -#define __GPGMEPP_IMPORTRESULT_H__ - -#include "gpgmefw.h" -#include "result.h" -#include "gpgmepp_export.h" - -#include <memory> - -#include <vector> - -namespace GpgME -{ - -class Error; -class Import; - -class GPGMEPP_EXPORT ImportResult : public Result -{ -public: - ImportResult(); - ImportResult(gpgme_ctx_t ctx, int error); - ImportResult(gpgme_ctx_t ctx, const Error &error); - explicit ImportResult(const Error &error); - - ImportResult(const ImportResult &other) = default; - const ImportResult &operator=(ImportResult other) - { - swap(other); - return *this; - } - - void swap(ImportResult &other) - { - Result::swap(other); - using std::swap; - swap(this->d, other.d); - } - - /** - * Merges the result @p other into this result (and all of its copies). - * - * @note The merge algorithm assumes that @p other is the result of an - * import that was performed after the import of this result. - * @note Some numbers cannot be consolidated reliably, e.g. the number of - * keys without user ID. - */ - void mergeWith(const ImportResult &other); - - bool isNull() const; - - int numConsidered() const; - int numKeysWithoutUserID() const; - int numImported() const; - int numRSAImported() const; - int numUnchanged() const; - - int newUserIDs() const; - int newSubkeys() const; - int newSignatures() const; - int newRevocations() const; - - int numSecretKeysConsidered() const; - int numSecretKeysImported() const; - int numSecretKeysUnchanged() const; - - int notImported() const; - int numV3KeysSkipped() const; - - Import import(unsigned int idx) const; - std::vector<Import> imports() const; - - class Private; -private: - void init(gpgme_ctx_t ctx); - std::shared_ptr<Private> d; -}; - -class GPGMEPP_EXPORT Import -{ - friend class ::GpgME::ImportResult; - Import(const std::shared_ptr<ImportResult::Private> &parent, unsigned int idx); -public: - Import(); - - Import(const Import &other) = default; - const Import &operator=(Import other) - { - swap(other); - return *this; - } - - void swap(Import &other) - { - using std::swap; - swap(this->d, other.d); - swap(this->idx, other.idx); - } - - bool isNull() const; - - const char *fingerprint() const; - Error error() const; - - enum Status { - Unknown = 0x0, - NewKey = 0x1, - NewUserIDs = 0x2, - NewSignatures = 0x4, - NewSubkeys = 0x8, - ContainedSecretKey = 0x10 - }; - Status status() const; - -private: - std::shared_ptr<ImportResult::Private> d; - unsigned int idx; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const ImportResult &irs); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Import &imp); - -} // namespace GpgME - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(ImportResult) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Import) - -#endif // __GPGMEPP_IMPORTRESULT_H__ diff --git a/lang/cpp/src/interfaces/assuantransaction.h b/lang/cpp/src/interfaces/assuantransaction.h deleted file mode 100644 index 35682f55..00000000 --- a/lang/cpp/src/interfaces/assuantransaction.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - assuantransaction.h - Interface for ASSUAN transactions - Copyright (C) 2009 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH <[email protected]> - Author: Marc Mutz <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_INTERFACES_ASSUANTRANSACTION_H__ -#define __GPGMEPP_INTERFACES_ASSUANTRANSACTION_H__ - -#include "../gpgmepp_export.h" - -#include <stddef.h> - -namespace GpgME -{ - -class Error; -class Data; - -class GPGMEPP_EXPORT AssuanTransaction -{ -public: - virtual ~AssuanTransaction() {} - - virtual Error data(const char *data, size_t datalen) = 0; - virtual Data inquire(const char *name, const char *args, Error &err) = 0; - virtual Error status(const char *status, const char *args) = 0; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_INTERFACES_ASSUANTRANSACTION_H__ diff --git a/lang/cpp/src/interfaces/dataprovider.h b/lang/cpp/src/interfaces/dataprovider.h deleted file mode 100644 index 22dc459b..00000000 --- a/lang/cpp/src/interfaces/dataprovider.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - interface/dataprovider.h - Interface for data sources - Copyright (C) 2003 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_INTERFACES_DATAPROVIDER_H__ -#define __GPGMEPP_INTERFACES_DATAPROVIDER_H__ - -#include <sys/types.h> - -#include "../gpgmepp_export.h" - -#include <gpg-error.h> - -namespace GpgME -{ - -class GPGMEPP_EXPORT DataProvider -{ -public: - virtual ~DataProvider() {} - - enum Operation { - Read, Write, Seek, Release - }; - virtual bool isSupported(Operation op) const = 0; - - virtual ssize_t read(void *buffer, size_t bufSize) = 0; - virtual ssize_t write(const void *buffer, size_t bufSize) = 0; - virtual off_t seek(off_t offset, int whence) = 0; - virtual void release() = 0; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_INTERFACES_DATAPROVIDER_H__ diff --git a/lang/cpp/src/interfaces/passphraseprovider.h b/lang/cpp/src/interfaces/passphraseprovider.h deleted file mode 100644 index c97aa542..00000000 --- a/lang/cpp/src/interfaces/passphraseprovider.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - interface/passphraseprovider.h - Interface for passphrase callbacks - Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_INTERFACES_PASSPHRASEPROVIDER_H__ -#define __GPGMEPP_INTERFACES_PASSPHRASEPROVIDER_H__ - -namespace GpgME -{ - -class PassphraseProvider -{ -public: - virtual ~PassphraseProvider() {} - - virtual char *getPassphrase(const char *useridHint, const char *description, - bool previousWasBad, bool &canceled) = 0; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_INTERFACES_PASSPHRASEPROVIDER_H__ diff --git a/lang/cpp/src/interfaces/progressprovider.h b/lang/cpp/src/interfaces/progressprovider.h deleted file mode 100644 index ef4ca3cf..00000000 --- a/lang/cpp/src/interfaces/progressprovider.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - interface/progressprovider.h - Interface for progress reports - Copyright (C) 2003 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_INTERFACES_PROGRESSPROVIDER_H__ -#define __GPGMEPP_INTERFACES_PROGRESSPROVIDER_H__ - -namespace GpgME -{ - -class ProgressProvider -{ -public: - virtual ~ProgressProvider() {} - - virtual void showProgress(const char *what, int type, - int current, int total) = 0; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_INTERFACES_PROGRESSPROVIDER_H__ diff --git a/lang/cpp/src/interfaces/statusconsumer.h b/lang/cpp/src/interfaces/statusconsumer.h deleted file mode 100644 index 65e7ea4a..00000000 --- a/lang/cpp/src/interfaces/statusconsumer.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - statusconsumer.h - Interface for status callbacks - Copyright (c) 2020 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_INTERFACES_STATUSCONSUMER_H__ -#define __GPGMEPP_INTERFACES_STATUSCONSUMER_H__ - -#include "../gpgmepp_export.h" - -namespace GpgME -{ - -class GPGMEPP_EXPORT StatusConsumer -{ -public: - virtual ~StatusConsumer() {} - - virtual void status(const char *status, const char *details) = 0; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_INTERFACES_STATUSCONSUMER_H__ diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp deleted file mode 100644 index 42046aa0..00000000 --- a/lang/cpp/src/key.cpp +++ /dev/null @@ -1,1455 +0,0 @@ -/* - key.cpp - wraps a gpgme key - Copyright (C) 2003, 2005 Klarälvdalens Datakonsult AB - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <key.h> - -#include "util.h" -#include "tofuinfo.h" -#include "context.h" -#include "engineinfo.h" - -#include <gpgme.h> - -#include <string.h> -#include <strings.h> -#include <cassert> -#include <istream> -#include <iterator> - -const GpgME::Key::Null GpgME::Key::null; - -namespace GpgME -{ - -Key::Key() : key() {} - -Key::Key(const Null &) : key() {} - -Key::Key(const shared_gpgme_key_t &k) : key(k) {} - -Key::Key(gpgme_key_t k, bool ref) - : key(k - ? shared_gpgme_key_t(k, &gpgme_key_unref) - : shared_gpgme_key_t()) -{ - if (ref && impl()) { - gpgme_key_ref(impl()); - } -} - -UserID Key::userID(unsigned int index) const -{ - return UserID(key, index); -} - -Subkey Key::subkey(unsigned int index) const -{ - return Subkey(key, index); -} - -unsigned int Key::numUserIDs() const -{ - if (!key) { - return 0; - } - unsigned int count = 0; - for (gpgme_user_id_t uid = key->uids ; uid ; uid = uid->next) { - ++count; - } - return count; -} - -unsigned int Key::numSubkeys() const -{ - if (!key) { - return 0; - } - unsigned int count = 0; - for (gpgme_sub_key_t subkey = key->subkeys ; subkey ; subkey = subkey->next) { - ++count; - } - return count; -} - -std::vector<UserID> Key::userIDs() const -{ - if (!key) { - return std::vector<UserID>(); - } - - std::vector<UserID> v; - v.reserve(numUserIDs()); - for (gpgme_user_id_t uid = key->uids ; uid ; uid = uid->next) { - v.push_back(UserID(key, uid)); - } - return v; -} - -std::vector<Subkey> Key::subkeys() const -{ - if (!key) { - return std::vector<Subkey>(); - } - - std::vector<Subkey> v; - v.reserve(numSubkeys()); - for (gpgme_sub_key_t subkey = key->subkeys ; subkey ; subkey = subkey->next) { - v.push_back(Subkey(key, subkey)); - } - return v; -} - -RevocationKey Key::revocationKey(unsigned int index) const -{ - return RevocationKey(key, index); -} - -unsigned int Key::numRevocationKeys() const -{ - if (!key) { - return 0; - } - unsigned int count = 0; - for (auto revkey = key->revocation_keys; revkey; revkey = revkey->next) { - ++count; - } - return count; -} - -std::vector<RevocationKey> Key::revocationKeys() const -{ - if (!key) { - return std::vector<RevocationKey>(); - } - - std::vector<RevocationKey> v; - v.reserve(numRevocationKeys()); - for (auto revkey = key->revocation_keys; revkey; revkey = revkey->next) { - v.push_back(RevocationKey(key, revkey)); - } - return v; -} - -Key::OwnerTrust Key::ownerTrust() const -{ - if (!key) { - return Unknown; - } - switch (key->owner_trust) { - default: - case GPGME_VALIDITY_UNKNOWN: return Unknown; - case GPGME_VALIDITY_UNDEFINED: return Undefined; - case GPGME_VALIDITY_NEVER: return Never; - case GPGME_VALIDITY_MARGINAL: return Marginal; - case GPGME_VALIDITY_FULL: return Full; - case GPGME_VALIDITY_ULTIMATE: return Ultimate; - } -} -char Key::ownerTrustAsString() const -{ - if (!key) { - return '?'; - } - switch (key->owner_trust) { - default: - case GPGME_VALIDITY_UNKNOWN: return '?'; - case GPGME_VALIDITY_UNDEFINED: return 'q'; - case GPGME_VALIDITY_NEVER: return 'n'; - case GPGME_VALIDITY_MARGINAL: return 'm'; - case GPGME_VALIDITY_FULL: return 'f'; - case GPGME_VALIDITY_ULTIMATE: return 'u'; - } -} - -Protocol Key::protocol() const -{ - if (!key) { - return UnknownProtocol; - } - switch (key->protocol) { - case GPGME_PROTOCOL_CMS: return CMS; - case GPGME_PROTOCOL_OpenPGP: return OpenPGP; - default: return UnknownProtocol; - } -} - -const char *Key::protocolAsString() const -{ - return key ? gpgme_get_protocol_name(key->protocol) : nullptr ; -} - -bool Key::isRevoked() const -{ - return key && key->revoked; -} - -bool Key::isExpired() const -{ - return key && key->expired; -} - -bool Key::isDisabled() const -{ - return key && key->disabled; -} - -bool Key::isInvalid() const -{ - return key && key->invalid; -} - -bool Key::hasSecret() const -{ - return key && key->secret; -} - -bool Key::isRoot() const -{ - return key && key->subkeys && key->subkeys->fpr && key->chain_id && - strcasecmp(key->subkeys->fpr, key->chain_id) == 0; -} - -bool Key::canEncrypt() const -{ - return key && key->can_encrypt; -} - -bool Key::canSign() const -{ - return key && key->can_sign; -} - -bool Key::canReallySign() const -{ - return canSign(); -} - -bool Key::canCertify() const -{ - return key && key->can_certify; -} - -bool Key::canAuthenticate() const -{ - return key && key->can_authenticate; -} - -bool Key::isQualified() const -{ - return key && key->is_qualified; -} - -bool Key::isDeVs() const -{ - if (!key || !key->subkeys) { - return false; - } - for (gpgme_sub_key_t subkey = key->subkeys ; subkey ; subkey = subkey->next) { - if (!subkey->is_de_vs) { - return false; - } - } - return true; -} - -bool Key::isBetaCompliance() const -{ - if (!key || !key->subkeys) { - return false; - } - for (gpgme_sub_key_t subkey = key->subkeys ; subkey ; subkey = subkey->next) { - if (!subkey->beta_compliance) { - return false; - } - } - return true; -} - -bool Key::hasCertify() const -{ - return key && key->has_certify; -} - -bool Key::hasSign() const -{ - return key && key->has_sign; -} - -bool Key::hasEncrypt() const -{ - return key && key->has_encrypt; -} - -bool Key::hasAuthenticate() const -{ - return key && key->has_authenticate; -} - -const char *Key::issuerSerial() const -{ - return key ? key->issuer_serial : nullptr ; -} -const char *Key::issuerName() const -{ - return key ? key->issuer_name : nullptr ; -} -const char *Key::chainID() const -{ - return key ? key->chain_id : nullptr ; -} - -const char *Key::keyID() const -{ - return key && key->subkeys ? key->subkeys->keyid : nullptr ; -} - -const char *Key::shortKeyID() const -{ - if (!key || !key->subkeys || !key->subkeys->keyid) { - return nullptr; - } - const int len = strlen(key->subkeys->keyid); - if (len > 8) { - return key->subkeys->keyid + len - 8; // return the last 8 bytes (in hex notation) - } else { - return key->subkeys->keyid; - } -} - -const char *Key::primaryFingerprint() const -{ - if (!key) { - return nullptr; - } - if (key->fpr) { - /* Return what gpgme thinks is the primary fingerprint */ - return key->fpr; - } - if (key->subkeys) { - /* Return the first subkeys fingerprint */ - return key->subkeys->fpr; - } - return nullptr; -} - -unsigned int Key::keyListMode() const -{ - return key ? convert_from_gpgme_keylist_mode_t(key->keylist_mode) : 0; -} - -const Key &Key::mergeWith(const Key &other) -{ - // ### incomplete. Just merges has* and can*, nothing else atm - // ### detach also missing - - if (!this->primaryFingerprint() || - !other.primaryFingerprint() || - strcasecmp(this->primaryFingerprint(), other.primaryFingerprint()) != 0) { - return *this; // only merge the Key object which describe the same key - } - - const gpgme_key_t me = impl(); - const gpgme_key_t him = other.impl(); - - if (!me || !him) { - return *this; - } - - me->revoked |= him->revoked; - me->expired |= him->expired; - me->disabled |= him->disabled; - me->invalid |= him->invalid; - me->can_encrypt |= him->can_encrypt; - me->can_sign |= him->can_sign; - me->can_certify |= him->can_certify; - me->secret |= him->secret; - me->can_authenticate |= him->can_authenticate; - me->is_qualified |= him->is_qualified; - me->keylist_mode |= him->keylist_mode; - - // make sure the gpgme_sub_key_t::is_cardkey flag isn't lost: - for (gpgme_sub_key_t mysk = me->subkeys ; mysk ; mysk = mysk->next) { - for (gpgme_sub_key_t hissk = him->subkeys ; hissk ; hissk = hissk->next) { - if (strcmp(mysk->fpr, hissk->fpr) == 0) { - mysk->is_cardkey |= hissk->is_cardkey; - mysk->secret |= hissk->secret; - if (hissk->keygrip && !mysk->keygrip) { - mysk->keygrip = strdup(hissk->keygrip); - } - break; - } - } - } - - return *this; -} - -void Key::update() -{ - if (isNull() || !primaryFingerprint()) { - return; - } - auto ctx = Context::createForProtocol(protocol()); - if (!ctx) { - return; - } - ctx->setKeyListMode(KeyListMode::Local | - KeyListMode::Signatures | - KeyListMode::SignatureNotations | - KeyListMode::Validate | - KeyListMode::WithTofu | - KeyListMode::WithKeygrip | - KeyListMode::WithSecret); - Error err; - Key newKey; - if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.0") { - newKey = ctx->key(primaryFingerprint(), err, true); - // Not secret so we get the information from the pubring. - if (newKey.isNull()) { - newKey = ctx->key(primaryFingerprint(), err, false); - } - } else { - newKey = ctx->key(primaryFingerprint(), err, false); - } - delete ctx; - if (err) { - return; - } - swap(newKey); -} - -// static -Key Key::locate(const char *mbox) -{ - if (!mbox) { - return Key(); - } - - auto ctx = Context::createForProtocol(OpenPGP); - if (!ctx) { - return Key(); - } - - ctx->setKeyListMode (Extern | Local); - - Error e = ctx->startKeyListing (mbox); - auto ret = ctx->nextKey (e); - delete ctx; - - return ret; -} - -// -// -// class Subkey -// -// - -static gpgme_sub_key_t find_subkey(const shared_gpgme_key_t &key, unsigned int idx) -{ - if (key) { - for (gpgme_sub_key_t s = key->subkeys ; s ; s = s->next, --idx) { - if (idx == 0) { - return s; - } - } - } - return nullptr; -} - -static gpgme_sub_key_t verify_subkey(const shared_gpgme_key_t &key, gpgme_sub_key_t subkey) -{ - if (key) { - for (gpgme_sub_key_t s = key->subkeys ; s ; s = s->next) { - if (s == subkey) { - return subkey; - } - } - } - return nullptr; -} - -Subkey::Subkey() : key(), subkey(nullptr) {} - -Subkey::Subkey(const shared_gpgme_key_t &k, unsigned int idx) - : key(k), subkey(find_subkey(k, idx)) -{ - -} - -Subkey::Subkey(const shared_gpgme_key_t &k, gpgme_sub_key_t sk) - : key(k), subkey(verify_subkey(k, sk)) -{ - -} - -Key Subkey::parent() const -{ - return Key(key); -} - -const char *Subkey::keyID() const -{ - return subkey ? subkey->keyid : nullptr ; -} - -const char *Subkey::fingerprint() const -{ - return subkey ? subkey->fpr : nullptr ; -} - -Subkey::PubkeyAlgo Subkey::publicKeyAlgorithm() const -{ - return subkey ? static_cast<PubkeyAlgo>(subkey->pubkey_algo) : AlgoUnknown; -} - -const char *Subkey::publicKeyAlgorithmAsString() const -{ - return gpgme_pubkey_algo_name(subkey ? subkey->pubkey_algo : (gpgme_pubkey_algo_t)0); -} - -/* static */ -const char *Subkey::publicKeyAlgorithmAsString(PubkeyAlgo algo) -{ - if (algo == AlgoUnknown) { - return NULL; - } - return gpgme_pubkey_algo_name(static_cast<gpgme_pubkey_algo_t>(algo)); -} - -std::string Subkey::algoName() const -{ - char *gpgmeStr; - if (subkey && (gpgmeStr = gpgme_pubkey_algo_string(subkey))) { - std::string ret = std::string(gpgmeStr); - gpgme_free(gpgmeStr); - return ret; - } - return std::string(); -} - -bool Subkey::canEncrypt() const -{ - return subkey && subkey->can_encrypt; -} - -bool Subkey::canSign() const -{ - return subkey && subkey->can_sign; -} - -bool Subkey::canCertify() const -{ - return subkey && subkey->can_certify; -} - -bool Subkey::canAuthenticate() const -{ - return subkey && subkey->can_authenticate; -} - -bool Subkey::canRenc() const -{ - return subkey && subkey->can_renc; -} - -bool Subkey::canTimestamp() const -{ - return subkey && subkey->can_timestamp; -} - -bool Subkey::isGroupOwned() const -{ - return subkey && subkey->is_group_owned; -} - -bool Subkey::isQualified() const -{ - return subkey && subkey->is_qualified; -} - -bool Subkey::isDeVs() const -{ - return subkey && subkey->is_de_vs; -} - -bool Subkey::isBetaCompliance() const -{ - return subkey && subkey->beta_compliance; -} - -bool Subkey::isCardKey() const -{ - return subkey && subkey->is_cardkey; -} - -const char *Subkey::cardSerialNumber() const -{ - return subkey ? subkey->card_number : nullptr; -} - -const char *Subkey::keyGrip() const -{ - return subkey ? subkey->keygrip : nullptr; -} - -bool Subkey::isSecret() const -{ - return subkey && subkey->secret; -} - -unsigned int Subkey::length() const -{ - return subkey ? subkey->length : 0 ; -} - -time_t Subkey::creationTime() const -{ - return static_cast<time_t>(subkey ? subkey->timestamp : 0); -} - -time_t Subkey::expirationTime() const -{ - return static_cast<time_t>(subkey ? subkey->expires : 0); -} - -bool Subkey::neverExpires() const -{ - return expirationTime() == time_t(0); -} - -bool Subkey::isRevoked() const -{ - return subkey && subkey->revoked; -} - -bool Subkey::isInvalid() const -{ - return subkey && subkey->invalid; -} - -bool Subkey::isExpired() const -{ - return subkey && subkey->expired; -} - -bool Subkey::isDisabled() const -{ - return subkey && subkey->disabled; -} - -// -// -// class UserID -// -// - -static gpgme_user_id_t find_uid(const shared_gpgme_key_t &key, unsigned int idx) -{ - if (key) { - for (gpgme_user_id_t u = key->uids ; u ; u = u->next, --idx) { - if (idx == 0) { - return u; - } - } - } - return nullptr; -} - -static gpgme_user_id_t verify_uid(const shared_gpgme_key_t &key, gpgme_user_id_t uid) -{ - if (key) { - for (gpgme_user_id_t u = key->uids ; u ; u = u->next) { - if (u == uid) { - return uid; - } - } - } - return nullptr; -} - -UserID::UserID() : key(), uid(nullptr) {} - -UserID::UserID(const shared_gpgme_key_t &k, gpgme_user_id_t u) - : key(k), uid(verify_uid(k, u)) -{ - -} - -UserID::UserID(const shared_gpgme_key_t &k, unsigned int idx) - : key(k), uid(find_uid(k, idx)) -{ - -} - -Key UserID::parent() const -{ - return Key(key); -} - -UserID::Signature UserID::signature(unsigned int index) const -{ - return Signature(key, uid, index); -} - -unsigned int UserID::numSignatures() const -{ - if (!uid) { - return 0; - } - unsigned int count = 0; - for (gpgme_key_sig_t sig = uid->signatures ; sig ; sig = sig->next) { - ++count; - } - return count; -} - -std::vector<UserID::Signature> UserID::signatures() const -{ - if (!uid) { - return std::vector<Signature>(); - } - - std::vector<Signature> v; - v.reserve(numSignatures()); - for (gpgme_key_sig_t sig = uid->signatures ; sig ; sig = sig->next) { - v.push_back(Signature(key, uid, sig)); - } - return v; -} - -const char *UserID::id() const -{ - return uid ? uid->uid : nullptr ; -} - -const char *UserID::name() const -{ - return uid ? uid->name : nullptr ; -} - -const char *UserID::email() const -{ - return uid ? uid->email : nullptr ; -} - -const char *UserID::comment() const -{ - return uid ? uid->comment : nullptr ; -} - -const char *UserID::uidhash() const -{ - return uid ? uid->uidhash : nullptr ; -} - -UserID::Validity UserID::validity() const -{ - if (!uid) { - return Unknown; - } - switch (uid->validity) { - default: - case GPGME_VALIDITY_UNKNOWN: return Unknown; - case GPGME_VALIDITY_UNDEFINED: return Undefined; - case GPGME_VALIDITY_NEVER: return Never; - case GPGME_VALIDITY_MARGINAL: return Marginal; - case GPGME_VALIDITY_FULL: return Full; - case GPGME_VALIDITY_ULTIMATE: return Ultimate; - } -} - -char UserID::validityAsString() const -{ - if (!uid) { - return '?'; - } - switch (uid->validity) { - default: - case GPGME_VALIDITY_UNKNOWN: return '?'; - case GPGME_VALIDITY_UNDEFINED: return 'q'; - case GPGME_VALIDITY_NEVER: return 'n'; - case GPGME_VALIDITY_MARGINAL: return 'm'; - case GPGME_VALIDITY_FULL: return 'f'; - case GPGME_VALIDITY_ULTIMATE: return 'u'; - } -} - -bool UserID::isRevoked() const -{ - return uid && uid->revoked; -} - -bool UserID::isInvalid() const -{ - return uid && uid->invalid; -} - -TofuInfo UserID::tofuInfo() const -{ - if (!uid) { - return TofuInfo(); - } - return TofuInfo(uid->tofu); -} - -static gpgme_key_sig_t find_last_valid_sig_for_keyid (gpgme_user_id_t uid, - const char *keyid) -{ - if (!keyid) { - return nullptr; - } - gpgme_key_sig_t ret = NULL; - for (gpgme_key_sig_t s = uid->signatures ; s ; s = s->next) { - if (s->keyid && !strcmp(keyid, s->keyid)) { - if (!s->expired && !s->revoked && !s->invalid && !s->status) { - if (!ret) { - ret = s; - } else if (ret && ret->timestamp <= s->timestamp) { - /* Equals because when the timestamps are the same we prefer - the last in the list */ - ret = s; - } - } - } - } - return ret; -} - -const char *UserID::remark(const Key &remarker, Error &err) const -{ - if (!uid || remarker.isNull()) { - err = Error::fromCode(GPG_ERR_GENERAL); - return nullptr; - } - - if (key->protocol != GPGME_PROTOCOL_OpenPGP) { - return nullptr; - } - - if (!(key->keylist_mode & GPGME_KEYLIST_MODE_SIG_NOTATIONS) || - !(key->keylist_mode & GPGME_KEYLIST_MODE_SIGS)) { - err = Error::fromCode(GPG_ERR_NO_DATA); - return nullptr; - } - - gpgme_key_sig_t s = find_last_valid_sig_for_keyid(uid, remarker.keyID()); - - if (!s) { - return nullptr; - } - - for (gpgme_sig_notation_t n = s->notations; n ; n = n->next) { - if (n->name && !strcmp(n->name, "[email protected]")) { - return n->value; - } - } - return nullptr; -} - -std::vector<std::string> UserID::remarks(std::vector<Key> keys, Error &err) const -{ - std::vector<std::string> ret; - - for (const auto &key: keys) { - const char *rem = remark(key, err); - if (err) { - return ret; - } - if (rem) { - ret.push_back(rem); - } - } - return ret; -} - -// -// -// class Signature -// -// - -static gpgme_key_sig_t find_signature(gpgme_user_id_t uid, unsigned int idx) -{ - if (uid) { - for (gpgme_key_sig_t s = uid->signatures ; s ; s = s->next, --idx) { - if (idx == 0) { - return s; - } - } - } - return nullptr; -} - -static gpgme_key_sig_t verify_signature(gpgme_user_id_t uid, gpgme_key_sig_t sig) -{ - if (uid) { - for (gpgme_key_sig_t s = uid->signatures ; s ; s = s->next) { - if (s == sig) { - return sig; - } - } - } - return nullptr; -} - -static int signature_index(gpgme_user_id_t uid, gpgme_key_sig_t sig) -{ - if (uid) { - int i = 0; - for (gpgme_key_sig_t s = uid->signatures ; s ; s = s->next, ++i) { - if (s == sig) { - return i; - } - } - } - return -1; -} - -UserID::Signature::Signature() : key(), uid(nullptr), sig(nullptr) {} - -UserID::Signature::Signature(const shared_gpgme_key_t &k, gpgme_user_id_t u, unsigned int idx) - : key(k), uid(verify_uid(k, u)), sig(find_signature(uid, idx)) -{ -} - -UserID::Signature::Signature(const shared_gpgme_key_t &k, gpgme_user_id_t u, gpgme_key_sig_t s) - : key(k), uid(verify_uid(k, u)), sig(verify_signature(uid, s)) -{ -} - -bool UserID::Signature::operator<(const Signature &other) -{ - // kept for binary compatibility - return static_cast<const UserID::Signature *>(this)->operator<(other); -} - -bool UserID::Signature::operator<(const Signature &other) const -{ - // based on cmp_signodes() in g10/keylist.c - - // both signatures must belong to the same user ID - assert(uid == other.uid); - - // self-signatures are ordered first - const char *primaryKeyId = parent().parent().keyID(); - const bool thisIsSelfSignature = strcmp(signerKeyID(), primaryKeyId) == 0; - const bool otherIsSelfSignature = strcmp(other.signerKeyID(), primaryKeyId) == 0; - if (thisIsSelfSignature && !otherIsSelfSignature) { - return true; - } - if (otherIsSelfSignature && !thisIsSelfSignature) { - return false; - } - - // then sort by signer key ID (which are or course the same for self-sigs) - const int keyIdComparison = strcmp(signerKeyID(), other.signerKeyID()); - if (keyIdComparison < 0) { - return true; - } - if (keyIdComparison > 0) { - return false; - } - - // followed by creation time - if (creationTime() < other.creationTime()) { - return true; - } - if (creationTime() > other.creationTime()) { - return false; - } - - // followed by the class in a way that a rev comes first - if (certClass() < other.certClass()) { - return true; - } - if (certClass() > other.certClass()) { - return false; - } - - // to make the sort stable we compare the indexes of the signatures as last resort - return signature_index(uid, sig) < signature_index(uid, other.sig); -} - -UserID UserID::Signature::parent() const -{ - return UserID(key, uid); -} - -const char *UserID::Signature::signerKeyID() const -{ - return sig ? sig->keyid : nullptr ; -} - -const char *UserID::Signature::algorithmAsString() const -{ - return gpgme_pubkey_algo_name(sig ? sig->pubkey_algo : (gpgme_pubkey_algo_t)0); -} - -unsigned int UserID::Signature::algorithm() const -{ - return sig ? sig->pubkey_algo : 0 ; -} - -time_t UserID::Signature::creationTime() const -{ - return static_cast<time_t>(sig ? sig->timestamp : 0); -} - -time_t UserID::Signature::expirationTime() const -{ - return static_cast<time_t>(sig ? sig->expires : 0); -} - -bool UserID::Signature::neverExpires() const -{ - return expirationTime() == time_t(0); -} - -bool UserID::Signature::isRevokation() const -{ - return sig && sig->revoked; -} - -bool UserID::Signature::isInvalid() const -{ - return sig && sig->invalid; -} - -bool UserID::Signature::isExpired() const -{ - return sig && sig->expired; -} - -bool UserID::Signature::isExportable() const -{ - return sig && sig->exportable; -} - -const char *UserID::Signature::signerUserID() const -{ - return sig ? sig->uid : nullptr ; -} - -const char *UserID::Signature::signerName() const -{ - return sig ? sig->name : nullptr ; -} - -const char *UserID::Signature::signerEmail() const -{ - return sig ? sig->email : nullptr ; -} - -const char *UserID::Signature::signerComment() const -{ - return sig ? sig->comment : nullptr ; -} - -unsigned int UserID::Signature::certClass() const -{ - return sig ? sig->sig_class : 0 ; -} - -UserID::Signature::Status UserID::Signature::status() const -{ - if (!sig) { - return GeneralError; - } - - switch (gpgme_err_code(sig->status)) { - case GPG_ERR_NO_ERROR: return NoError; - case GPG_ERR_SIG_EXPIRED: return SigExpired; - case GPG_ERR_KEY_EXPIRED: return KeyExpired; - case GPG_ERR_BAD_SIGNATURE: return BadSignature; - case GPG_ERR_NO_PUBKEY: return NoPublicKey; - default: - case GPG_ERR_GENERAL: return GeneralError; - } -} - -std::string UserID::Signature::statusAsString() const -{ - if (!sig) { - return std::string(); - } - char buf[ 1024 ]; - gpgme_strerror_r(sig->status, buf, sizeof buf); - buf[ sizeof buf - 1 ] = '\0'; - return std::string(buf); -} - -GpgME::Notation UserID::Signature::notation(unsigned int idx) const -{ - if (!sig) { - return GpgME::Notation(); - } - for (gpgme_sig_notation_t nota = sig->notations ; nota ; nota = nota->next) { - if (nota->name) { - if (idx-- == 0) { - return GpgME::Notation(nota); - } - } - } - return GpgME::Notation(); -} - -unsigned int UserID::Signature::numNotations() const -{ - if (!sig) { - return 0; - } - unsigned int count = 0; - for (gpgme_sig_notation_t nota = sig->notations ; nota ; nota = nota->next) { - if (nota->name) { - ++count; // others are policy URLs... - } - } - return count; -} - -std::vector<Notation> UserID::Signature::notations() const -{ - if (!sig) { - return std::vector<GpgME::Notation>(); - } - std::vector<GpgME::Notation> v; - v.reserve(numNotations()); - for (gpgme_sig_notation_t nota = sig->notations ; nota ; nota = nota->next) { - if (nota->name) { - v.push_back(GpgME::Notation(nota)); - } - } - return v; -} - -const char *UserID::Signature::policyURL() const -{ - if (!sig) { - return nullptr; - } - for (gpgme_sig_notation_t nota = sig->notations ; nota ; nota = nota->next) { - if (!nota->name) { - return nota->value; - } - } - return nullptr; -} - -bool UserID::Signature::isTrustSignature() const -{ - return sig && sig->trust_depth > 0; -} - -TrustSignatureTrust UserID::Signature::trustValue() const -{ - if (!sig || !isTrustSignature()) { - return TrustSignatureTrust::None; - } - return sig->trust_value >= 120 ? TrustSignatureTrust::Complete : TrustSignatureTrust::Partial; -} - -unsigned int UserID::Signature::trustDepth() const -{ - return sig ? sig->trust_depth : 0; -} - -const char *UserID::Signature::trustScope() const -{ - return sig ? sig->trust_scope : nullptr; -} - -std::string UserID::addrSpecFromString(const char *userid) -{ - if (!userid) { - return std::string(); - } - char *normalized = gpgme_addrspec_from_uid (userid); - if (normalized) { - std::string ret(normalized); - gpgme_free(normalized); - return ret; - } - return std::string(); -} - -std::string UserID::addrSpec() const -{ - if (!uid || !uid->address) { - return std::string(); - } - - return uid->address; -} - -Error UserID::revoke() -{ - if (isNull()) { - return Error::fromCode(GPG_ERR_GENERAL); - } - auto ctx = Context::createForProtocol(parent().protocol()); - if (!ctx) { - return Error::fromCode(GPG_ERR_INV_ENGINE); - } - Error ret = ctx->revUid(key, id()); - delete ctx; - return ret; -} - -static Key::Origin gpgme_origin_to_pp_origin (const unsigned int origin) -{ - switch (origin) { - case GPGME_KEYORG_KS: - return Key::OriginKS; - case GPGME_KEYORG_DANE: - return Key::OriginDane; - case GPGME_KEYORG_WKD: - return Key::OriginWKD; - case GPGME_KEYORG_URL: - return Key::OriginURL; - case GPGME_KEYORG_FILE: - return Key::OriginFile; - case GPGME_KEYORG_SELF: - return Key::OriginSelf; - case GPGME_KEYORG_OTHER: - return Key::OriginOther; - case GPGME_KEYORG_UNKNOWN: - default: - return Key::OriginUnknown; - } -} - -Key::Origin UserID::origin() const -{ - if (isNull()) { - return Key::OriginUnknown; - } - return gpgme_origin_to_pp_origin(uid->origin); -} - -time_t UserID::lastUpdate() const -{ - return static_cast<time_t>(uid ? uid->last_update : 0); -} - -Error Key::addUid(const char *uid) -{ - if (isNull()) { - return Error::fromCode(GPG_ERR_GENERAL); - } - auto ctx = Context::createForProtocol(protocol()); - if (!ctx) { - return Error::fromCode(GPG_ERR_INV_ENGINE); - } - Error ret = ctx->addUid(key, uid); - delete ctx; - return ret; -} - -Key::Origin Key::origin() const -{ - if (isNull()) { - return OriginUnknown; - } - return gpgme_origin_to_pp_origin(key->origin); -} - -time_t Key::lastUpdate() const -{ - return static_cast<time_t>(key ? key->last_update : 0); -} - -bool Key::isBad() const -{ - return isNull() || isRevoked() || isExpired() || isDisabled() || isInvalid(); -} - -bool Subkey::isBad() const -{ - return isNull() || isRevoked() || isExpired() || isDisabled() || isInvalid(); -} - -bool UserID::isBad() const -{ - return isNull() || isRevoked() || isInvalid(); -} - -bool UserID::Signature::isBad() const -{ - return isNull() || isExpired() || isInvalid(); -} - -// -// -// class RevocationKey -// -// - -static gpgme_revocation_key_t find_revkey(const shared_gpgme_key_t &key, unsigned int idx) -{ - if (key) { - for (gpgme_revocation_key_t s = key->revocation_keys; s; s = s->next, --idx) { - if (idx == 0) { - return s; - } - } - } - return nullptr; -} - -static gpgme_revocation_key_t verify_revkey(const shared_gpgme_key_t &key, gpgme_revocation_key_t revkey) -{ - if (key) { - for (gpgme_revocation_key_t s = key->revocation_keys; s; s = s->next) { - if (s == revkey) { - return revkey; - } - } - } - return nullptr; -} - -RevocationKey::RevocationKey() : key(), revkey(nullptr) {} - -RevocationKey::RevocationKey(const shared_gpgme_key_t &k, unsigned int idx) - : key(k), revkey(find_revkey(k, idx)) -{ -} - -RevocationKey::RevocationKey(const shared_gpgme_key_t &k, gpgme_revocation_key_t sk) - : key(k), revkey(verify_revkey(k, sk)) -{ -} - -Key RevocationKey::parent() const -{ - return Key(key); -} - -const char *RevocationKey::fingerprint() const -{ - return revkey ? revkey->fpr : nullptr; -} - -bool RevocationKey::isSensitive() const -{ - return revkey ? revkey->sensitive : false; -} - -int RevocationKey::algorithm() const -{ - return revkey ? revkey->pubkey_algo : 0; -} - -std::ostream &operator<<(std::ostream &os, const UserID &uid) -{ - os << "GpgME::UserID("; - if (!uid.isNull()) { - os << "\n name: " << protect(uid.name()) - << "\n email: " << protect(uid.email()) - << "\n mbox: " << uid.addrSpec() - << "\n comment: " << protect(uid.comment()) - << "\n validity: " << uid.validityAsString() - << "\n revoked: " << uid.isRevoked() - << "\n invalid: " << uid.isInvalid() - << "\n numsigs: " << uid.numSignatures() - << "\n origin: " << uid.origin() - << "\n updated: " << uid.lastUpdate() - << "\n tofuinfo:\n" << uid.tofuInfo(); - } - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, const Subkey &subkey) -{ - os << "GpgME::Subkey("; - if (!subkey.isNull()) { - os << "\n fingerprint: " << protect(subkey.fingerprint()) - << "\n keyGrip: " << protect(subkey.keyGrip()) - << "\n creationTime: " << subkey.creationTime() - << "\n expirationTime:" << subkey.expirationTime() - << "\n isRevoked: " << subkey.isRevoked() - << "\n isExpired: " << subkey.isExpired() - << "\n isInvalid: " << subkey.isInvalid() - << "\n isDisabled: " << subkey.isDisabled() - << "\n canSign: " << subkey.canSign() - << "\n canEncrypt: " << subkey.canEncrypt() - << "\n canCertify: " << subkey.canCertify() - << "\n canAuth: " << subkey.canAuthenticate() - << "\n canRenc: " << subkey.canRenc() - << "\n canTimestanp: " << subkey.canTimestamp() - << "\n isSecret: " << subkey.isSecret() - << "\n isGroupOwned: " << subkey.isGroupOwned() - << "\n isQualified: " << subkey.isQualified() - << "\n isDeVs: " << subkey.isDeVs() - << "\n isBetaCompliance:" << subkey.isBetaCompliance() - << "\n isCardKey: " << subkey.isCardKey() - << "\n cardSerialNumber:" << protect(subkey.cardSerialNumber()); - } - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, const Key &key) -{ - os << "GpgME::Key("; - if (!key.isNull()) { - os << "\n protocol: " << protect(key.protocolAsString()) - << "\n ownertrust: " << key.ownerTrustAsString() - << "\n issuer: " << protect(key.issuerName()) - << "\n fingerprint:" << protect(key.primaryFingerprint()) - << "\n listmode: " << key.keyListMode() - << "\n canSign: " << key.canSign() - << "\n canEncrypt: " << key.canEncrypt() - << "\n canCertify: " << key.canCertify() - << "\n canAuth: " << key.canAuthenticate() - << "\n origin: " << key.origin() - << "\n updated: " << key.lastUpdate() - << "\n uids:\n"; - const std::vector<UserID> uids = key.userIDs(); - std::copy(uids.begin(), uids.end(), - std::ostream_iterator<UserID>(os, "\n")); - const std::vector<Subkey> subkeys = key.subkeys(); - std::copy(subkeys.begin(), subkeys.end(), - std::ostream_iterator<Subkey>(os, "\n")); - os << " revocationKeys:\n"; - const std::vector<RevocationKey> revkeys = key.revocationKeys(); - std::copy(revkeys.begin(), revkeys.end(), - std::ostream_iterator<RevocationKey>(os, "\n")); - } - return os << ')'; -} - -std::ostream &operator<<(std::ostream &os, const RevocationKey &revkey) -{ - os << "GpgME::RevocationKey("; - if (!revkey.isNull()) { - os << "\n fingerprint: " << protect(revkey.fingerprint()) - << "\n isSensitive: " << revkey.isSensitive(); - } - return os << ')'; -} - -} // namespace GpgME diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h deleted file mode 100644 index ddcd3bb8..00000000 --- a/lang/cpp/src/key.h +++ /dev/null @@ -1,618 +0,0 @@ -/* - key.h - wraps a gpgme key - Copyright (C) 2003, 2005 Klarälvdalens Datakonsult AB - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_KEY_H__ -#define __GPGMEPP_KEY_H__ - -#include "global.h" -#include "notation.h" - -#include "gpgmefw.h" - -#include <algorithm> -#include <memory> -#include <string> -#include <vector> - -#include <ctime> - -namespace GpgME -{ - -class Context; - -class Subkey; -class UserID; -class TofuInfo; -class RevocationKey; - -typedef std::shared_ptr< std::remove_pointer<gpgme_key_t>::type > shared_gpgme_key_t; - -enum class TrustSignatureTrust : char { - None = 0, - Partial, - Complete, -}; - -// -// class Key -// - -class GPGMEPP_EXPORT Key -{ - friend class ::GpgME::Context; - struct Null { - Null() {} - }; -public: - Key(); - /* implicit */ Key(const Null &); - Key(const shared_gpgme_key_t &key); - Key(gpgme_key_t key, bool acquireRef); - - static const Null null; - - Key(const Key &other) = default; - const Key &operator=(Key other) - { - swap(other); - return *this; - } - - const Key &mergeWith(const Key &other); - - void swap(Key &other) - { - using std::swap; - swap(this->key, other.key); - } - - bool isNull() const - { - return !key; - } - - UserID userID(unsigned int index) const; - Subkey subkey(unsigned int index) const; - - unsigned int numUserIDs() const; - unsigned int numSubkeys() const; - - std::vector<UserID> userIDs() const; - std::vector<Subkey> subkeys() const; - - RevocationKey revocationKey(unsigned int index) const; - unsigned int numRevocationKeys() const; - std::vector<RevocationKey> revocationKeys() const; - - bool isRevoked() const; - bool isExpired() const; - bool isDisabled() const; - bool isInvalid() const; - - /*! Shorthand for isNull || isRevoked || isExpired || - * isDisabled || isInvalid */ - bool isBad() const; - - /** Returns true, if the key can be used for encryption (i.e. it's not bad - * and has an encryption subkey) or if the primary subkey can encrypt. */ - bool canEncrypt() const; - /** Returns true, if the key can be used for signing (i.e. it's not bad - * and has a signing subkey) or if the primary subkey can sign. */ - bool canSign() const; - GPGMEPP_DEPRECATED bool canReallySign() const; - /** Returns true, if the key can be used for certification (i.e. it's not bad - * and has a certification subkey) or if the primary subkey can certify. */ - bool canCertify() const; - /** Returns true, if the key can be used for authentication (i.e. it's not bad - * and has a authentication subkey) or if the primary subkey can authenticate. */ - bool canAuthenticate() const; - bool isQualified() const; - bool isDeVs() const; - bool isBetaCompliance() const; - - /** Returns true, if the key has a certification subkey. */ - bool hasCertify() const; - /** Returns true, if the key has a signing subkey. */ - bool hasSign() const; - /** Returns true, if the key has an encryption subkey. */ - bool hasEncrypt() const; - /** Returns true, if the key has an authentication subkey. */ - bool hasAuthenticate() const; - - bool hasSecret() const; - GPGMEPP_DEPRECATED bool isSecret() const - { - return hasSecret(); - } - - /*! - @return true if this is a X.509 root certificate (currently - equivalent to something like - strcmp( chainID(), subkey(0).fingerprint() ) == 0 ) - */ - bool isRoot() const; - - enum OwnerTrust { Unknown = 0, Undefined = 1, Never = 2, - Marginal = 3, Full = 4, Ultimate = 5 - }; - - OwnerTrust ownerTrust() const; - char ownerTrustAsString() const; - - Protocol protocol() const; - const char *protocolAsString() const; - - const char *issuerSerial() const; - const char *issuerName() const; - const char *chainID() const; - - const char *keyID() const; - const char *shortKeyID() const; - const char *primaryFingerprint() const; - - unsigned int keyListMode() const; - - /*! Update information about this key. - * Starts a keylisting for this key with validity - * and tofu information gathering. Blocks for - * how long the keylisting takes.*/ - void update(); - - /** - * @brief Add a user id to this key. - * - * Needs gnupg 2.1.13 and the key needs to be updated - * afterwards to see the new uid. - * - * @param uid should be fully formatted and UTF-8 encoded. - * - * @returns a possible error. - **/ - Error addUid(const char *uid); - - /** - * @brief try to locate the best pgp key for a given mailbox. - * - * Boils down to gpg --locate-key <mbox> - * This may take some time if remote sources are also - * used. - * - * @param mbox should be a mail address does not need to be normalized. - * - * @returns The best key for a mailbox or a null key. - */ - static Key locate(const char *mbox); - - /* @enum Origin - * @brief The Origin of the key. */ - enum Origin : unsigned int { - OriginUnknown = 0, - OriginKS = 1, - OriginDane = 3, - OriginWKD = 4, - OriginURL = 5, - OriginFile = 6, - OriginSelf = 7, - OriginOther = 31, - }; - /*! Get the origin of the key. - * - * @returns the Origin. */ - Origin origin() const; - - /*! Get the last update time. - * - * @returns the last update time. */ - time_t lastUpdate() const; -private: - gpgme_key_t impl() const - { - return key.get(); - } - shared_gpgme_key_t key; -}; - -// -// class Subkey -// - -class GPGMEPP_EXPORT Subkey -{ -public: - Subkey(); - Subkey(const shared_gpgme_key_t &key, gpgme_sub_key_t subkey); - Subkey(const shared_gpgme_key_t &key, unsigned int idx); - - Subkey(const Subkey &other) = default; - const Subkey &operator=(Subkey other) - { - swap(other); - return *this; - } - - void swap(Subkey &other) - { - using std::swap; - swap(this->key, other.key); - swap(this->subkey, other.subkey); - } - - bool isNull() const - { - return !key || !subkey; - } - - Key parent() const; - - const char *keyID() const; - const char *fingerprint() const; - - time_t creationTime() const; - time_t expirationTime() const; - bool neverExpires() const; - - bool isRevoked() const; - bool isExpired() const; - bool isInvalid() const; - bool isDisabled() const; - - /*! Shorthand for isNull || isRevoked || isExpired || - * isDisabled || isInvalid */ - bool isBad() const; - - bool canEncrypt() const; - bool canSign() const; - bool canCertify() const; - bool canAuthenticate() const; - bool canRenc() const; - bool canTimestamp() const; - bool isGroupOwned() const; - bool isQualified() const; - bool isDeVs() const; - bool isBetaCompliance() const; - bool isCardKey() const; - - bool isSecret() const; - - /** Same as gpgme_pubkey_algo_t */ - enum PubkeyAlgo { - AlgoUnknown = 0, - AlgoRSA = 1, - AlgoRSA_E = 2, - AlgoRSA_S = 3, - AlgoKyber = 8, - AlgoELG_E = 16, - AlgoDSA = 17, - AlgoECC = 18, - AlgoELG = 20, - AlgoECDSA = 301, - AlgoECDH = 302, - AlgoEDDSA = 303, - AlgoMax = 1 << 31 - }; - - PubkeyAlgo publicKeyAlgorithm() const; - - /** - @brief Get the public key algorithm name. - - This only works for the pre 2.1 algorithms for ECC NULL is returned. - - @returns a statically allocated string with the name of the public - key algorithm, or NULL if that name is not known. - */ - const char *publicKeyAlgorithmAsString() const; - - /** @brief Same as publicKeyAlgorithmAsString but static. */ - static const char *publicKeyAlgorithmAsString(PubkeyAlgo algo); - - /** - @brief Get the key algo string like GnuPG 2.1 prints it. - - This returns combinations of size and algorithm. Like - bp512 or rsa2048. Misnamed because publicKeyAlgorithmAsString - already used the older pubkey_algo_name. - Actually uses gpgme_pubkey_algo_string. - - @returns the key algorithm as string. Empty string on error. - */ - std::string algoName() const; - - unsigned int length() const; - - const char *cardSerialNumber() const; - - const char *keyGrip() const; - -private: - shared_gpgme_key_t key; - gpgme_sub_key_t subkey; -}; - -// -// class UserID -// - -class GPGMEPP_EXPORT UserID -{ -public: - class Signature; - - UserID(); - UserID(const shared_gpgme_key_t &key, gpgme_user_id_t uid); - UserID(const shared_gpgme_key_t &key, unsigned int idx); - - UserID(const UserID &other) = default; - const UserID &operator=(UserID other) - { - swap(other); - return *this; - } - - void swap(UserID &other) - { - using std::swap; - swap(this->key, other.key); - swap(this->uid, other.uid); - } - - bool isNull() const - { - return !key || !uid; - } - - Key parent() const; - - unsigned int numSignatures() const; - Signature signature(unsigned int index) const; - std::vector<Signature> signatures() const; - - const char *id() const; - const char *name() const; - const char *email() const; - const char *comment() const; - const char *uidhash() const; - - enum Validity { Unknown = 0, Undefined = 1, Never = 2, - Marginal = 3, Full = 4, Ultimate = 5 - }; - - Validity validity() const; - char validityAsString() const; - - bool isRevoked() const; - bool isInvalid() const; - - /*! Shorthand for isNull || isRevoked || isInvalid */ - bool isBad() const; - - /** TOFU info for this userid. - * @returns The TOFU stats or a null TofuInfo. - */ - GpgME::TofuInfo tofuInfo() const; - - /*! Wrapper around gpgme_addrspec_from_uid. - * - * The input string should match the format of - * a user id string. - * - * @returns a normalized mail address if found - * or an empty string. */ - static std::string addrSpecFromString(const char *uid); - - /*! Wrapper around gpgme_addrspec_from_uid. - * - * @returns a normalized mail address for this userid - * or an empty string. */ - std::string addrSpec() const; - - /*! Revoke the user id. - * - * Key needs update afterwards. - * - * @returns an error on error.*/ - Error revoke(); - - /*! Get the origin of the key. - * - * @returns the Origin. */ - Key::Origin origin() const; - - /*! Get the last update time. - * - * @returns the last update time. */ - time_t lastUpdate() const; - - /*! Get a remark made by the key provided. - * A remark is a signature notation on - * this user id made by the key with the - * name "[email protected]". Returns an error if the - * parent key of this user id was not listed with the - * keylist mode flags for signatures and signature notations. - * - * @param key The key for which comments should be searched. - * @param error Set to GPG_ERR_NO_DATA if the keylist did - * not include signature notations. - * - * @returns The value of the comment or NULL if none exists. - **/ - const char *remark(const Key &key, - Error &error) const; - - /*! Get multiple remarks made by potentially multiple keys. */ - std::vector <std::string> remarks(std::vector<GpgME::Key> remarkers, - Error &error) const; - -private: - shared_gpgme_key_t key; - gpgme_user_id_t uid; -}; - -// -// class UserID::Signature -// - -class GPGMEPP_EXPORT UserID::Signature -{ -public: - GPGMEPP_DEPRECATED typedef GpgME::Notation Notation; - - Signature(); - Signature(const shared_gpgme_key_t &key, gpgme_user_id_t uid, gpgme_key_sig_t sig); - Signature(const shared_gpgme_key_t &key, gpgme_user_id_t uid, unsigned int idx); - - Signature(const Signature &other) = default; - const Signature &operator=(Signature other) - { - swap(other); - return *this; - } - - void swap(Signature &other) - { - using std::swap; - swap(this->key, other.key); - swap(this->uid, other.uid); - swap(this->sig, other.sig); - } - - /*! Defines a canonical sort order for signatures of the same user ID. */ - bool operator<(const Signature &other) const; - - GPGMEPP_DEPRECATED bool operator<(const Signature &other); - - bool isNull() const - { - return !sig || !uid || !key ; - } - - UserID parent() const; - - const char *signerKeyID() const; - - const char *algorithmAsString() const; - unsigned int algorithm() const; - time_t creationTime() const; - time_t expirationTime() const; - bool neverExpires() const; - - bool isRevokation() const; - bool isInvalid() const; - bool isExpired() const; - bool isExportable() const; - - /*! Shorthand for isNull || isExpired || isInvalid */ - bool isBad() const; - - const char *signerUserID() const; - const char *signerName() const; - const char *signerEmail() const; - const char *signerComment() const; - - unsigned int certClass() const; - - enum Status { NoError = 0, SigExpired, KeyExpired, - BadSignature, NoPublicKey, GeneralError - }; - Status status() const; - std::string statusAsString() const; - - const char *policyURL() const; - - unsigned int numNotations() const; - GpgME::Notation notation(unsigned int idx) const; - std::vector<GpgME::Notation> notations() const; - - bool isTrustSignature() const; - TrustSignatureTrust trustValue() const; - unsigned int trustDepth() const; - const char *trustScope() const; - -private: - shared_gpgme_key_t key; - gpgme_user_id_t uid; - gpgme_key_sig_t sig; -}; - -// -// class RevocationKey -// - -class GPGMEPP_EXPORT RevocationKey -{ -public: - RevocationKey(); - RevocationKey(const shared_gpgme_key_t &key, gpgme_revocation_key_t revkey); - RevocationKey(const shared_gpgme_key_t &key, unsigned int idx); - - // Rule of Zero - - void swap(RevocationKey &other) - { - using std::swap; - swap(this->key, other.key); - swap(this->revkey, other.revkey); - } - - bool isNull() const - { - return !key || !revkey; - } - - Key parent() const; - - const char *fingerprint() const; - - bool isSensitive() const; - - int algorithm() const; - -private: - shared_gpgme_key_t key; - gpgme_revocation_key_t revkey; -}; - -inline void swap(RevocationKey& v1, RevocationKey& v2) -{ - v1.swap(v2); -} - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const UserID &uid); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Subkey &subkey); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Key &key); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const RevocationKey &revkey); - -} // namespace GpgME - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Key) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Subkey) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(UserID) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(UserID::Signature) - -GPGMEPP_MAKE_STRCMP(ByFingerprint, .primaryFingerprint()); -GPGMEPP_MAKE_STRCMP(ByKeyID, .keyID()); -GPGMEPP_MAKE_STRCMP(ByShortKeyID, .shortKeyID()); -GPGMEPP_MAKE_STRCMP(ByChainID, .chainID()); - -#endif // __GPGMEPP_KEY_H__ diff --git a/lang/cpp/src/keygenerationresult.cpp b/lang/cpp/src/keygenerationresult.cpp deleted file mode 100644 index 49342f42..00000000 --- a/lang/cpp/src/keygenerationresult.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - keygenerationresult.cpp - wraps a gpgme keygen result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <keygenerationresult.h> -#include "result_p.h" - -#include <gpgme.h> - -#include <cstring> -#include <cstdlib> - -#include <string.h> - -class GpgME::KeyGenerationResult::Private -{ -public: - Private(const _gpgme_op_genkey_result &r) : res(r) - { - if (res.fpr) { - res.fpr = strdup(res.fpr); - } - } - ~Private() - { - if (res.fpr) { - std::free(res.fpr); - } - res.fpr = nullptr; - } - - _gpgme_op_genkey_result res; -}; - -GpgME::KeyGenerationResult::KeyGenerationResult(gpgme_ctx_t ctx, int error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -GpgME::KeyGenerationResult::KeyGenerationResult(gpgme_ctx_t ctx, const Error &error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -void GpgME::KeyGenerationResult::init(gpgme_ctx_t ctx) -{ - if (!ctx) { - return; - } - gpgme_genkey_result_t res = gpgme_op_genkey_result(ctx); - if (!res) { - return; - } - d.reset(new Private(*res)); -} - -make_standard_stuff(KeyGenerationResult) - -bool GpgME::KeyGenerationResult::isPrimaryKeyGenerated() const -{ - return d && d->res.primary; -} - -bool GpgME::KeyGenerationResult::isSubkeyGenerated() const -{ - return d && d->res.sub; -} - -const char *GpgME::KeyGenerationResult::fingerprint() const -{ - return d ? d->res.fpr : nullptr ; -} diff --git a/lang/cpp/src/keygenerationresult.h b/lang/cpp/src/keygenerationresult.h deleted file mode 100644 index 1cbc9dd3..00000000 --- a/lang/cpp/src/keygenerationresult.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - keygenerationresult.h - wraps a gpgme keygen result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_KEYGENERATIONRESULT_H__ -#define __GPGMEPP_KEYGENERATIONRESULT_H__ - -#include "gpgmefw.h" -#include "result.h" -#include "gpgmepp_export.h" - -#include <memory> - -namespace GpgME -{ - -class Error; - -class GPGMEPP_EXPORT KeyGenerationResult : public Result -{ -public: - KeyGenerationResult(); - KeyGenerationResult(gpgme_ctx_t ctx, int error); - KeyGenerationResult(gpgme_ctx_t ctx, const Error &error); - explicit KeyGenerationResult(const Error &err); - - KeyGenerationResult(const KeyGenerationResult &other) = default; - const KeyGenerationResult &operator=(KeyGenerationResult other) - { - swap(other); - return *this; - } - - void swap(KeyGenerationResult &other) - { - Result::swap(other); - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - GPGMEPP_DEPRECATED bool primaryKeyGenerated() const - { - return isPrimaryKeyGenerated(); - } - GPGMEPP_DEPRECATED bool subkeyGenerated() const - { - return isSubkeyGenerated(); - } - bool isPrimaryKeyGenerated() const; - bool isSubkeyGenerated() const; - const char *fingerprint() const; - -private: - class Private; - void init(gpgme_ctx_t ctx); - std::shared_ptr<Private> d; -}; - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(KeyGenerationResult) - -#endif // __GPGMEPP_KEYGENERATIONRESULT_H__ diff --git a/lang/cpp/src/keylistresult.cpp b/lang/cpp/src/keylistresult.cpp deleted file mode 100644 index 6e6b001b..00000000 --- a/lang/cpp/src/keylistresult.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - keylistresult.cpp - wraps a gpgme keylist result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <keylistresult.h> -#include "result_p.h" - -#include <gpgme.h> - -#include <cstring> -#include <cassert> - -class GpgME::KeyListResult::Private -{ -public: - Private(const _gpgme_op_keylist_result &r) : res(r) {} - Private(const Private &other) : res(other.res) {} - - _gpgme_op_keylist_result res; -}; - -GpgME::KeyListResult::KeyListResult(gpgme_ctx_t ctx, int error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -GpgME::KeyListResult::KeyListResult(gpgme_ctx_t ctx, const Error &error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -void GpgME::KeyListResult::init(gpgme_ctx_t ctx) -{ - if (!ctx) { - return; - } - gpgme_keylist_result_t res = gpgme_op_keylist_result(ctx); - if (!res) { - return; - } - d.reset(new Private(*res)); -} - -GpgME::KeyListResult::KeyListResult(const Error &error, const _gpgme_op_keylist_result &res) - : GpgME::Result(error), d(new Private(res)) -{ - -} - -make_standard_stuff(KeyListResult) - -void GpgME::KeyListResult::detach() -{ - if (!d || d.unique()) { - return; - } - d.reset(new Private(*d)); -} - -void GpgME::KeyListResult::mergeWith(const KeyListResult &other) -{ - if (other.isNull()) { - return; - } - if (isNull()) { // just assign - operator=(other); - return; - } - // merge the truncated flag (try to keep detaching to a minimum): - if (other.isTruncated() && !this->isTruncated()) { - assert(other.d); - detach(); - if (!d) { - d.reset(new Private(*other.d)); - } else { - d->res.truncated = true; - } - } - if (! bool(error())) { // only merge the error when there was none yet. - Result::operator=(other); - } -} - -bool GpgME::KeyListResult::isTruncated() const -{ - return d && d->res.truncated; -} diff --git a/lang/cpp/src/keylistresult.h b/lang/cpp/src/keylistresult.h deleted file mode 100644 index 68e2a17b..00000000 --- a/lang/cpp/src/keylistresult.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - keylistresult.h - wraps a gpgme keylist result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_KEYLISTRESULT_H__ -#define __GPGMEPP_KEYLISTRESULT_H__ - -#include "gpgmefw.h" -#include "result.h" -#include "gpgmepp_export.h" - -#include <memory> - -namespace GpgME -{ - -class Error; - -class GPGMEPP_EXPORT KeyListResult : public Result -{ -public: - KeyListResult(); - KeyListResult(gpgme_ctx_t ctx, int error); - KeyListResult(gpgme_ctx_t ctx, const Error &error); - explicit KeyListResult(const Error &err); - KeyListResult(const Error &err, const _gpgme_op_keylist_result &res); - - KeyListResult(const KeyListResult &other) = default; - const KeyListResult &operator=(KeyListResult other) - { - swap(other); - return *this; - } - void swap(KeyListResult &other) - { - Result::swap(other); - using std::swap; - swap(this->d, other.d); - } - - const KeyListResult &operator+=(const KeyListResult &other) - { - mergeWith(other); - return *this; - } - - void mergeWith(const KeyListResult &other); - - bool isNull() const; - - bool isTruncated() const; - -private: - void detach(); - void init(gpgme_ctx_t ctx); - class Private; - std::shared_ptr<Private> d; -}; - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(KeyListResult) - -#endif // __GPGMEPP_KEYLISTRESULT_H__ diff --git a/lang/cpp/src/notation.h b/lang/cpp/src/notation.h deleted file mode 100644 index b1ff2d50..00000000 --- a/lang/cpp/src/notation.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - notation.h - wraps a gpgme verify result - Copyright (C) 2004, 2007 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_NOTATION_H__ -#define __GPGMEPP_NOTATION_H__ - -#include "gpgmefw.h" -#include "verificationresult.h" -#include "gpgmepp_export.h" - -#include <memory> - -#include <iosfwd> - -namespace GpgME -{ - -class GPGMEPP_EXPORT Notation -{ - friend class ::GpgME::Signature; - Notation(const std::shared_ptr<VerificationResult::Private> &parent, unsigned int sindex, unsigned int nindex); -public: - Notation(); - explicit Notation(gpgme_sig_notation_t nota); - - Notation(const Notation &other) = default; - const Notation &operator=(Notation other) - { - swap(other); - return *this; - } - - void swap(Notation &other) - { - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - const char *name() const; - const char *value() const; - - enum Flags { - NoFlags = 0, - HumanReadable = 1, - Critical = 2 - }; - Flags flags() const; - - bool isHumanReadable() const; - bool isCritical() const; - -private: - class Private; - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Notation ¬a); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Notation::Flags flags); - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Notation) - -#endif // __GPGMEPP_NOTATION_H__ diff --git a/lang/cpp/src/result.h b/lang/cpp/src/result.h deleted file mode 100644 index a587afbe..00000000 --- a/lang/cpp/src/result.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - result.h - base class for results - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_RESULT_H__ -#define __GPGMEPP_RESULT_H__ - -#include "gpgmefw.h" -#include "error.h" - -#include <algorithm> // std::swap - -namespace GpgME -{ - -class GPGMEPP_EXPORT Result -{ -protected: - explicit Result() : mError() {} - explicit Result(int err) : mError(err) {} - explicit Result(const Error &err) : mError(err) {} - - void swap(Result &other) - { - std::swap(other.mError, mError); - } - -public: - const Error &error() const - { - return mError; - } - /** - * Replaces the error set during construction with \p error. - * Use with care, e.g. to set a more suitable error. - */ - void setError(const Error &error) - { - mError = error; - } - -protected: - Error mError; -}; - -} - -#endif // __GPGMEPP_RESULT_H__ diff --git a/lang/cpp/src/result_p.h b/lang/cpp/src/result_p.h deleted file mode 100644 index 70c45c47..00000000 --- a/lang/cpp/src/result_p.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - result.h - base class for results - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_RESULT_P_H__ -#define __GPGMEPP_RESULT_P_H__ - -#define make_default_ctor(x) \ - GpgME::x::x() : GpgME::Result(), d() {} - -#define make_error_ctor(x) \ - GpgME::x::x( const Error & error ) \ - : GpgME::Result( error ), d() \ - { \ - \ - } - -#define make_isNull(x) bool GpgME::x::isNull() const { return !d && !bool(error()); } - -#define make_standard_stuff(x) \ - make_default_ctor(x) \ - make_error_ctor(x) \ - make_isNull(x) - -#endif // __GPGMEPP_RESULT_P_H__ diff --git a/lang/cpp/src/scdgetinfoassuantransaction.cpp b/lang/cpp/src/scdgetinfoassuantransaction.cpp deleted file mode 100644 index 4a024905..00000000 --- a/lang/cpp/src/scdgetinfoassuantransaction.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - scdgetinfoassuantransaction.cpp - Assuan Transaction to get information from scdaemon - Copyright (C) 2009 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "scdgetinfoassuantransaction.h" -#include "error.h" -#include "data.h" -#include "util.h" - -#include <assert.h> - -using namespace GpgME; - -ScdGetInfoAssuanTransaction::ScdGetInfoAssuanTransaction(InfoItem item) - : AssuanTransaction(), - m_item(item), - m_command(), - m_data() -{ - -} - -ScdGetInfoAssuanTransaction::~ScdGetInfoAssuanTransaction() {} - -static std::vector<std::string> to_reader_list(const std::string &s) -{ - std::vector<std::string> result; - std::stringstream ss(s); - std::string tok; - while (std::getline(ss, tok, '\n')) { - result.push_back(tok); - } - return result; -} - -static std::vector<std::string> to_app_list(const std::string &s) -{ - return to_reader_list(s); -} - -std::string ScdGetInfoAssuanTransaction::version() const -{ - if (m_item == Version) { - return m_data; - } else { - return std::string(); - } -} - -unsigned int ScdGetInfoAssuanTransaction::pid() const -{ - if (m_item == Pid) { - return to_pid(m_data); - } else { - return 0U; - } -} - -std::string ScdGetInfoAssuanTransaction::socketName() const -{ - if (m_item == SocketName) { - return m_data; - } else { - return std::string(); - } -} - -char ScdGetInfoAssuanTransaction::status() const -{ - if (m_item == Status && !m_data.empty()) { - return m_data[0]; - } else { - return '\0'; - } -} - -std::vector<std::string> ScdGetInfoAssuanTransaction::readerList() const -{ - if (m_item == ReaderList) { - return to_reader_list(m_data); - } else { - return std::vector<std::string>(); - } -} - -std::vector<std::string> ScdGetInfoAssuanTransaction::applicationList() const -{ - if (m_item == ApplicationList) { - return to_app_list(m_data); - } else { - return std::vector<std::string>(); - } -} - -static const char *const scd_getinfo_tokens[] = { - "version", - "pid", - "socket_name", - "status", - "reader_list", - "deny_admin", - "app_list", -}; -static_assert((sizeof scd_getinfo_tokens / sizeof * scd_getinfo_tokens == ScdGetInfoAssuanTransaction::LastInfoItem), - "getinfo_tokens size mismatch"); - -void ScdGetInfoAssuanTransaction::makeCommand() const -{ - assert(m_item >= 0); - assert(m_item < LastInfoItem); - m_command = "SCD GETINFO "; - m_command += scd_getinfo_tokens[m_item]; -} - -const char *ScdGetInfoAssuanTransaction::command() const -{ - makeCommand(); - return m_command.c_str(); -} - -Error ScdGetInfoAssuanTransaction::data(const char *data, size_t len) -{ - m_data.append(data, len); - return Error(); -} - -Data ScdGetInfoAssuanTransaction::inquire(const char *name, const char *args, Error &err) -{ - (void)name; (void)args; (void)err; - return Data::null; -} - -Error ScdGetInfoAssuanTransaction::status(const char *status, const char *args) -{ - (void)status; (void)args; - return Error(); -} diff --git a/lang/cpp/src/scdgetinfoassuantransaction.h b/lang/cpp/src/scdgetinfoassuantransaction.h deleted file mode 100644 index d1ff0987..00000000 --- a/lang/cpp/src/scdgetinfoassuantransaction.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - scdgetinfoassuantransaction.h - Assuan Transaction to get information from scdaemon - Copyright (C) 2009 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_SCDGETINFOASSUANTRANSACTION_H__ -#define __GPGMEPP_SCDGETINFOASSUANTRANSACTION_H__ - -#include "interfaces/assuantransaction.h" - -#include <string> -#include <vector> - -namespace GpgME -{ - -class GPGMEPP_EXPORT ScdGetInfoAssuanTransaction : public AssuanTransaction -{ -public: - enum InfoItem { - Version, // string - Pid, // unsigned long - SocketName, // string (path) - Status, // char (status) - ReaderList, // string list - DenyAdmin, // (none, returns GPG_ERR_GENERAL when admin commands are allowed) - ApplicationList, // string list - - LastInfoItem - }; - - explicit ScdGetInfoAssuanTransaction(InfoItem item); - ~ScdGetInfoAssuanTransaction(); - - std::string version() const; - unsigned int pid() const; - std::string socketName() const; - char status() const; - std::vector<std::string> readerList() const; - std::vector<std::string> applicationList() const; - -private: - const char *command() const; - Error data(const char *data, size_t datalen) override; - Data inquire(const char *name, const char *args, Error &err) override; - Error status(const char *status, const char *args) override; - -private: - void makeCommand() const; - -private: - InfoItem m_item; - mutable std::string m_command; - std::string m_data; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_SCDGETINFOASSUANTRANSACTION_H__ diff --git a/lang/cpp/src/signingresult.cpp b/lang/cpp/src/signingresult.cpp deleted file mode 100644 index c92a6e3e..00000000 --- a/lang/cpp/src/signingresult.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* - signingresult.cpp - wraps a gpgme verify result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <signingresult.h> -#include "result_p.h" -#include "util.h" - -#include <gpgme.h> - -#include <cstring> -#include <cstdlib> -#include <algorithm> -#include <istream> -#include <iterator> - -#include <string.h> - -class GpgME::SigningResult::Private -{ -public: - Private(const gpgme_sign_result_t r) - { - if (!r) { - return; - } - for (gpgme_new_signature_t is = r->signatures ; is ; is = is->next) { - gpgme_new_signature_t copy = new _gpgme_new_signature(*is); - if (is->fpr) { - copy->fpr = strdup(is->fpr); - } - copy->next = nullptr; - created.push_back(copy); - } - for (gpgme_invalid_key_t ik = r->invalid_signers ; ik ; ik = ik->next) { - gpgme_invalid_key_t copy = new _gpgme_invalid_key(*ik); - if (ik->fpr) { - copy->fpr = strdup(ik->fpr); - } - copy->next = nullptr; - invalid.push_back(copy); - } - } - ~Private() - { - for (std::vector<gpgme_new_signature_t>::iterator it = created.begin() ; it != created.end() ; ++it) { - std::free((*it)->fpr); - delete *it; *it = nullptr; - } - for (std::vector<gpgme_invalid_key_t>::iterator it = invalid.begin() ; it != invalid.end() ; ++it) { - std::free((*it)->fpr); - delete *it; *it = nullptr; - } - } - - std::vector<gpgme_new_signature_t> created; - std::vector<gpgme_invalid_key_t> invalid; -}; - -GpgME::SigningResult::SigningResult(gpgme_ctx_t ctx, int error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -GpgME::SigningResult::SigningResult(gpgme_ctx_t ctx, const Error &error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -void GpgME::SigningResult::init(gpgme_ctx_t ctx) -{ - if (!ctx) { - return; - } - gpgme_sign_result_t res = gpgme_op_sign_result(ctx); - if (!res) { - return; - } - d.reset(new Private(res)); -} - -make_standard_stuff(SigningResult) - -GpgME::CreatedSignature GpgME::SigningResult::createdSignature(unsigned int idx) const -{ - return CreatedSignature(d, idx); -} - -std::vector<GpgME::CreatedSignature> GpgME::SigningResult::createdSignatures() const -{ - if (!d) { - return std::vector<CreatedSignature>(); - } - std::vector<CreatedSignature> result; - result.reserve(d->created.size()); - for (unsigned int i = 0 ; i < d->created.size() ; ++i) { - result.push_back(CreatedSignature(d, i)); - } - return result; -} - -GpgME::InvalidSigningKey GpgME::SigningResult::invalidSigningKey(unsigned int idx) const -{ - return InvalidSigningKey(d, idx); -} - -std::vector<GpgME::InvalidSigningKey> GpgME::SigningResult::invalidSigningKeys() const -{ - if (!d) { - return std::vector<GpgME::InvalidSigningKey>(); - } - std::vector<GpgME::InvalidSigningKey> result; - result.reserve(d->invalid.size()); - for (unsigned int i = 0 ; i < d->invalid.size() ; ++i) { - result.push_back(InvalidSigningKey(d, i)); - } - return result; -} - -GpgME::InvalidSigningKey::InvalidSigningKey(const std::shared_ptr<SigningResult::Private> &parent, unsigned int i) - : d(parent), idx(i) -{ - -} - -GpgME::InvalidSigningKey::InvalidSigningKey() : d(), idx(0) {} - -bool GpgME::InvalidSigningKey::isNull() const -{ - return !d || idx >= d->invalid.size() ; -} - -const char *GpgME::InvalidSigningKey::fingerprint() const -{ - return isNull() ? nullptr : d->invalid[idx]->fpr ; -} - -GpgME::Error GpgME::InvalidSigningKey::reason() const -{ - return Error(isNull() ? 0 : d->invalid[idx]->reason); -} - -GpgME::CreatedSignature::CreatedSignature(const std::shared_ptr<SigningResult::Private> &parent, unsigned int i) - : d(parent), idx(i) -{ - -} - -GpgME::CreatedSignature::CreatedSignature() : d(), idx(0) {} - -bool GpgME::CreatedSignature::isNull() const -{ - return !d || idx >= d->created.size() ; -} - -const char *GpgME::CreatedSignature::fingerprint() const -{ - return isNull() ? nullptr : d->created[idx]->fpr ; -} - -time_t GpgME::CreatedSignature::creationTime() const -{ - return static_cast<time_t>(isNull() ? 0 : d->created[idx]->timestamp); -} - -GpgME::SignatureMode GpgME::CreatedSignature::mode() const -{ - if (isNull()) { - return NormalSignatureMode; - } - switch (d->created[idx]->type) { - default: - case GPGME_SIG_MODE_NORMAL: return NormalSignatureMode; - case GPGME_SIG_MODE_DETACH: return Detached; - case GPGME_SIG_MODE_CLEAR: return Clearsigned; - case GPGME_SIG_MODE_ARCHIVE: return SignArchive; // cannot happen - case GPGME_SIG_MODE_FILE: return SignFile; // cannot happen - } -} - -unsigned int GpgME::CreatedSignature::publicKeyAlgorithm() const -{ - return isNull() ? 0 : d->created[idx]->pubkey_algo ; -} - -const char *GpgME::CreatedSignature::publicKeyAlgorithmAsString() const -{ - return gpgme_pubkey_algo_name(isNull() ? (gpgme_pubkey_algo_t)0 : d->created[idx]->pubkey_algo); -} - -unsigned int GpgME::CreatedSignature::hashAlgorithm() const -{ - return isNull() ? 0 : d->created[idx]->hash_algo ; -} - -const char *GpgME::CreatedSignature::hashAlgorithmAsString() const -{ - return gpgme_hash_algo_name(isNull() ? (gpgme_hash_algo_t)0 : d->created[idx]->hash_algo); -} - -unsigned int GpgME::CreatedSignature::signatureClass() const -{ - return isNull() ? 0 : d->created[idx]->sig_class ; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const SigningResult &result) -{ - os << "GpgME::SigningResult("; - if (!result.isNull()) { - os << "\n error: " << result.error() - << "\n createdSignatures:\n"; - const std::vector<CreatedSignature> cs = result.createdSignatures(); - std::copy(cs.begin(), cs.end(), - std::ostream_iterator<CreatedSignature>(os, "\n")); - os << " invalidSigningKeys:\n"; - const std::vector<InvalidSigningKey> isk = result.invalidSigningKeys(); - std::copy(isk.begin(), isk.end(), - std::ostream_iterator<InvalidSigningKey>(os, "\n")); - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const CreatedSignature &sig) -{ - os << "GpgME::CreatedSignature("; - if (!sig.isNull()) { - os << "\n fingerprint: " << protect(sig.fingerprint()) - << "\n creationTime: " << sig.creationTime() - << "\n mode: " << sig.mode() - << "\n publicKeyAlgorithm: " << protect(sig.publicKeyAlgorithmAsString()) - << "\n hashAlgorithm: " << protect(sig.hashAlgorithmAsString()) - << "\n signatureClass: " << sig.signatureClass() - << '\n'; - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const InvalidSigningKey &key) -{ - os << "GpgME::InvalidSigningKey("; - if (!key.isNull()) { - os << "\n fingerprint: " << protect(key.fingerprint()) - << "\n reason: " << key.reason() - << '\n'; - } - return os << ')'; -} diff --git a/lang/cpp/src/signingresult.h b/lang/cpp/src/signingresult.h deleted file mode 100644 index 0c2994c7..00000000 --- a/lang/cpp/src/signingresult.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - signingresult.h - wraps a gpgme sign result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_SIGNINGRESULT_H__ -#define __GPGMEPP_SIGNINGRESULT_H__ - -#include "global.h" -#include "result.h" - -#include <time.h> - -#include <memory> - -#include <vector> -#include <iosfwd> - -namespace GpgME -{ - -class Error; -class CreatedSignature; -class InvalidSigningKey; - -class GPGMEPP_EXPORT SigningResult : public Result -{ -public: - SigningResult(); - SigningResult(gpgme_ctx_t ctx, int error); - SigningResult(gpgme_ctx_t ctx, const Error &error); - explicit SigningResult(const Error &err); - - SigningResult(const SigningResult &other) = default; - const SigningResult &operator=(SigningResult other) - { - swap(other); - return *this; - } - - void swap(SigningResult &other) - { - Result::swap(other); - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - CreatedSignature createdSignature(unsigned int index) const; - std::vector<CreatedSignature> createdSignatures() const; - - InvalidSigningKey invalidSigningKey(unsigned int index) const; - std::vector<InvalidSigningKey> invalidSigningKeys() const; - - class Private; -private: - void init(gpgme_ctx_t ctx); - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const SigningResult &result); - -class GPGMEPP_EXPORT InvalidSigningKey -{ - friend class ::GpgME::SigningResult; - InvalidSigningKey(const std::shared_ptr<SigningResult::Private> &parent, unsigned int index); -public: - InvalidSigningKey(); - - InvalidSigningKey(const InvalidSigningKey &other) = default; - const InvalidSigningKey &operator=(InvalidSigningKey other) - { - swap(other); - return *this; - } - - void swap(InvalidSigningKey &other) - { - using std::swap; - swap(this->d, other.d); - swap(this->idx, other.idx); - } - - bool isNull() const; - - const char *fingerprint() const; - Error reason() const; - -private: - std::shared_ptr<SigningResult::Private> d; - unsigned int idx; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const InvalidSigningKey &key); - -class GPGMEPP_EXPORT CreatedSignature -{ - friend class ::GpgME::SigningResult; - CreatedSignature(const std::shared_ptr<SigningResult::Private> &parent, unsigned int index); -public: - - CreatedSignature(); - - CreatedSignature(const CreatedSignature &other) = default; - const CreatedSignature &operator=(CreatedSignature other) - { - swap(other); - return *this; - } - - void swap(CreatedSignature &other) - { - using std::swap; - swap(this->d, other.d); - swap(this->idx, other.idx); - } - - bool isNull() const; - - const char *fingerprint() const; - - time_t creationTime() const; - - SignatureMode mode() const; - - unsigned int publicKeyAlgorithm() const; - const char *publicKeyAlgorithmAsString() const; - - unsigned int hashAlgorithm() const; - const char *hashAlgorithmAsString() const; - - unsigned int signatureClass() const; - -private: - std::shared_ptr<SigningResult::Private> d; - unsigned int idx; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const CreatedSignature &sig); - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(SigningResult) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(InvalidSigningKey) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(CreatedSignature) - -#endif // __GPGMEPP_SIGNINGRESULT_H__ diff --git a/lang/cpp/src/statusconsumerassuantransaction.cpp b/lang/cpp/src/statusconsumerassuantransaction.cpp deleted file mode 100644 index 7adfac03..00000000 --- a/lang/cpp/src/statusconsumerassuantransaction.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - statusconsumerassuantransaction.cpp - Copyright (c) 2020 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "statusconsumerassuantransaction.h" - -#include "data.h" -#include "error.h" - -#include "interfaces/statusconsumer.h" - -using namespace GpgME; - -StatusConsumerAssuanTransaction::StatusConsumerAssuanTransaction(StatusConsumer *statusConsumer) - : AssuanTransaction() - , m_consumer(statusConsumer) -{ -} - -StatusConsumerAssuanTransaction::~StatusConsumerAssuanTransaction() -{ -} - -Error StatusConsumerAssuanTransaction::data(const char *data, size_t datalen) -{ - (void) data; - (void) datalen; - return Error(); -} - -Data StatusConsumerAssuanTransaction::inquire(const char *name, const char *args, Error &err) -{ - (void)name; - (void)args; - (void)err; - return Data::null; -} - -Error StatusConsumerAssuanTransaction::status(const char *status, const char *args) -{ - m_consumer->status(status, args); - - return Error(); -} diff --git a/lang/cpp/src/statusconsumerassuantransaction.h b/lang/cpp/src/statusconsumerassuantransaction.h deleted file mode 100644 index 0724069d..00000000 --- a/lang/cpp/src/statusconsumerassuantransaction.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - statusconsumerassuantransaction.h - Assuan transaction that forwards status lines to a consumer - Copyright (c) 2020 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_STATUSCONSUMERASSUANTRANSACTION_H__ -#define __GPGMEPP_STATUSCONSUMERASSUANTRANSACTION_H__ - -#include "interfaces/assuantransaction.h" - -namespace GpgME -{ - -class StatusConsumer; - -class GPGMEPP_EXPORT StatusConsumerAssuanTransaction: public AssuanTransaction -{ -public: - explicit StatusConsumerAssuanTransaction(StatusConsumer *statusConsumer); - ~StatusConsumerAssuanTransaction(); - -private: - Error data(const char *data, size_t datalen) override; - Data inquire(const char *name, const char *args, Error &err) override; - Error status(const char *status, const char *args) override; - -private: - StatusConsumer *m_consumer; -}; - -} // namespace GpgME - -#endif // __GPGMEPP_STATUSCONSUMERASSUANTRANSACTION_H__ diff --git a/lang/cpp/src/swdbresult.cpp b/lang/cpp/src/swdbresult.cpp deleted file mode 100644 index 202a107f..00000000 --- a/lang/cpp/src/swdbresult.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/* swdbresult.cpp - wraps gpgme swdb result / query - Copyright (C) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "swdbresult.h" - -#include <istream> - -#include "error.h" - -#include "gpgme.h" - -class GpgME::SwdbResult::Private -{ -public: - Private() {} - Private(gpgme_query_swdb_result_t result) - : mResult(result ? new _gpgme_op_query_swdb_result (*result) : nullptr) - { - if (!result) { - mResult->name = nullptr; - return; - } - if (result->name) { - mResult->name = strdup(result->name); - } - if (result->version) { - mVersion = result->version; - } - if (result->iversion) { - mIVersion = result->iversion; - } - } - - Private(const Private &other) - : mResult(other.mResult) - { - if (mResult && mResult->name) { - mResult->name = strdup(mResult->name); - } - mVersion = other.mVersion; - mIVersion = other.mIVersion; - } - - ~Private() - { - if (mResult) { - std::free(mResult->name); - delete mResult; - } - } - - GpgME::EngineInfo::Version mVersion; - GpgME::EngineInfo::Version mIVersion; - gpgme_query_swdb_result_t mResult; -}; - -GpgME::SwdbResult::SwdbResult(gpgme_query_swdb_result_t result) - : d(new Private(result)) -{ -} - -GpgME::SwdbResult::SwdbResult() : d() -{ -} - -bool GpgME::SwdbResult::isNull() const -{ - return !d || !d->mResult; -} - -std::string GpgME::SwdbResult::name() const -{ - if (isNull() || !d->mResult->name) { - return std::string(); - } - return d->mResult->name; -} - -GpgME::EngineInfo::Version GpgME::SwdbResult::version() const -{ - if (isNull()) { - return GpgME::EngineInfo::Version(); - } - return d->mVersion; -} - -GpgME::EngineInfo::Version GpgME::SwdbResult::installedVersion() const -{ - if (isNull()) { - return GpgME::EngineInfo::Version(); - } - return d->mIVersion; -} - -unsigned long GpgME::SwdbResult::created() const -{ - return isNull() ? 0 : d->mResult->created; -} - -unsigned long GpgME::SwdbResult::retrieved() const -{ - return isNull() ? 0 : d->mResult->retrieved; -} - -unsigned long GpgME::SwdbResult::releaseDate() const -{ - return isNull() ? 0 : d->mResult->reldate; -} - -bool GpgME::SwdbResult::warning() const -{ - return isNull() ? 0 : d->mResult->warning; -} - -bool GpgME::SwdbResult::update() const -{ - return isNull() ? 0 : d->mResult->update; -} - -bool GpgME::SwdbResult::noinfo() const -{ - return isNull() ? 0 : d->mResult->noinfo; -} - -bool GpgME::SwdbResult::unknown() const -{ - return isNull() ? 0 : d->mResult->unknown; -} - -bool GpgME::SwdbResult::error() const -{ - return isNull() ? 0 : d->mResult->error; -} - -bool GpgME::SwdbResult::tooOld() const -{ - return isNull() ? 0 : d->mResult->tooold; -} - -bool GpgME::SwdbResult::urgent() const -{ - return isNull() ? 0 : d->mResult->urgent; -} - -std::vector<GpgME::SwdbResult> GpgME::SwdbResult::query(const char *name, - const char *iversion, - Error *err) -{ - std::vector <GpgME::SwdbResult> ret; - gpgme_ctx_t ctx; - gpgme_error_t gpgerr = gpgme_new(&ctx); - - if (gpgerr) { - if (err) { - *err = Error (gpgerr); - } - return ret; - } - - gpgerr = gpgme_set_protocol(ctx, GPGME_PROTOCOL_GPGCONF); - - if (gpgerr) { - if (err) { - *err = Error(gpgerr); - } - gpgme_release(ctx); - return ret; - } - - gpgerr = gpgme_op_query_swdb(ctx, name, iversion, 0); - - if (gpgerr) { - if (err) { - *err = Error(gpgerr); - } - gpgme_release(ctx); - return ret; - } - gpgme_query_swdb_result_t result = gpgme_op_query_swdb_result(ctx); - while (result) { - ret.push_back(SwdbResult(result)); - result = result->next; - } - - gpgme_release(ctx); - return ret; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const GpgME::SwdbResult &result) -{ - os << "GpgME::SwdbResult("; - if (!result.isNull()) { - os << "\n name: " << result.name() - << "\n version: " << result.version() - << "\n installed: "<< result.installedVersion() - << "\n created: " << result.created() - << "\n retrieved: "<< result.retrieved() - << "\n warning: " << result.warning() - << "\n update: " << result.update() - << "\n urgent: " << result.urgent() - << "\n noinfo: " << result.noinfo() - << "\n unknown: " << result.unknown() - << "\n tooOld: " << result.tooOld() - << "\n error: " << result.error() - << "\n reldate: " << result.releaseDate() - << '\n'; - } - return os << ")\n"; -} diff --git a/lang/cpp/src/swdbresult.h b/lang/cpp/src/swdbresult.h deleted file mode 100644 index d4340fe1..00000000 --- a/lang/cpp/src/swdbresult.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - swdbresult.h - wraps a gpgme swdb query / rsult - Copyright (C) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef __GPGMEPP_SWDB_H__ -#define __GPGMEPP_SWDB_H__ - -#include "gpgmepp_export.h" - -#include "global.h" -#include "engineinfo.h" - -#include <vector> -#include <string> -#include <iostream> -#include <ostream> - -namespace GpgME -{ - -class GPGMEPP_EXPORT SwdbResult -{ -public: - /* Obtain swdb results through query() */ - SwdbResult(); - explicit SwdbResult(gpgme_query_swdb_result_t result); - - /** Query the swdb to get information about updates. - * - * Runs gpgconf --query-swdb through gpgme and - * returns a list of results. - * If iversion is given as NULL a check is only done if GPGME - * can figure out the version by itself (for example when using - * "gpgme" or "gnupg"). - * - * If NULL is used for name the current gpgme version is - * checked. - * - * @param name: Name of the component to query. - * @param iversion: Optionally the installed version. - * @param err: Optional error. - */ - static std::vector<SwdbResult> query(const char *name, - const char *iversion = NULL, - Error *err = NULL); - - SwdbResult(const SwdbResult &other) = default; - const SwdbResult &operator=(SwdbResult other) - { - swap(other); - return *this; - } - - void swap(SwdbResult &other) - { - using std::swap; - swap(this->d, other.d); - } - bool isNull() const; - - /* The name of the package (e.g. "gpgme", "gnupg") */ - std::string name() const; - - /* The version of the installed version. */ - EngineInfo::Version installedVersion() const; - - /* The time the online info was created. */ - unsigned long created() const; - - /* The time the online info was retrieved. */ - unsigned long retrieved() const; - - /* This bit is set if an error occurred or some of the information - * in this structure may not be set. */ - bool warning() const; - - /* An update is available. */ - bool update() const; - - /* The update is important. */ - bool urgent() const; - - /* No information at all available. */ - bool noinfo() const; - - /* The package name is not known. */ - bool unknown() const; - - /* The information here is too old. */ - bool tooOld() const; - - /* Other error. */ - bool error() const; - - /* The version of the latest released version. */ - EngineInfo::Version version() const; - - /* The release date of that version. */ - unsigned long releaseDate() const; - -private: - class Private; - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const SwdbResult &info); - -} // namespace GpgME - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(SwdbResult) - -#endif diff --git a/lang/cpp/src/tofuinfo.cpp b/lang/cpp/src/tofuinfo.cpp deleted file mode 100644 index f0132f7b..00000000 --- a/lang/cpp/src/tofuinfo.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* tofuinfo.cpp - wraps gpgme tofu info - Copyright (C) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "tofuinfo.h" - -#include <istream> -#include "util.h" - -class GpgME::TofuInfo::Private -{ -public: - Private() {} - Private(gpgme_tofu_info_t info) - : mInfo(info ? new _gpgme_tofu_info(*info) : nullptr) - { - if (mInfo && mInfo->description) { - mInfo->description = strdup(mInfo->description); - } - } - - Private(const Private &other) - : mInfo(other.mInfo) - { - if (mInfo && mInfo->description) { - mInfo->description = strdup(mInfo->description); - } - } - - ~Private() - { - if (mInfo) { - std::free(mInfo->description); - mInfo->description = nullptr; - - delete mInfo; - } - } - - gpgme_tofu_info_t mInfo; -}; - -GpgME::TofuInfo::TofuInfo(gpgme_tofu_info_t info) - : d(new Private(info)) -{ -} - -GpgME::TofuInfo::TofuInfo() : d() -{ -} - -bool GpgME::TofuInfo::isNull() const -{ - return !d || !d->mInfo; -} - -GpgME::TofuInfo::Validity GpgME::TofuInfo::validity() const -{ - if (isNull()) { - return ValidityUnknown; - } - switch (d->mInfo->validity) { - case 0: - return Conflict; - case 1: - return NoHistory; - case 2: - return LittleHistory; - case 3: - return BasicHistory; - case 4: - return LargeHistory; - default: - return ValidityUnknown; - } -} - -GpgME::TofuInfo::Policy GpgME::TofuInfo::policy() const -{ - if (isNull()) { - return PolicyUnknown; - } - switch (d->mInfo->policy) { - case GPGME_TOFU_POLICY_NONE: - return PolicyNone; - case GPGME_TOFU_POLICY_AUTO: - return PolicyAuto; - case GPGME_TOFU_POLICY_GOOD: - return PolicyGood; - case GPGME_TOFU_POLICY_BAD: - return PolicyBad; - case GPGME_TOFU_POLICY_ASK: - return PolicyAsk; - case GPGME_TOFU_POLICY_UNKNOWN: - default: - return PolicyUnknown; - } -} - -const char *GpgME::TofuInfo::description() const -{ - return isNull() ? nullptr : d->mInfo->description; -} - -unsigned short GpgME::TofuInfo::signCount() const -{ - return isNull() ? 0 : d->mInfo->signcount; -} - -unsigned short GpgME::TofuInfo::encrCount() const -{ - return isNull() ? 0 : d->mInfo->encrcount; -} - -unsigned long GpgME::TofuInfo::signFirst() const -{ - return isNull() ? 0 : d->mInfo->signfirst; -} - -unsigned long GpgME::TofuInfo::signLast() const -{ - return isNull() ? 0 : d->mInfo->signlast; -} - -unsigned long GpgME::TofuInfo::encrFirst() const -{ - return isNull() ? 0 : d->mInfo->encrfirst; -} - -unsigned long GpgME::TofuInfo::encrLast() const -{ - return isNull() ? 0 : d->mInfo->encrlast; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const GpgME::TofuInfo &info) -{ - os << "GpgME::Signature::TofuInfo("; - if (!info.isNull()) { - os << "\n desc: " << protect(info.description()) - << "\n validity: " << info.validity() - << "\n policy: " << info.policy() - << "\n signcount: "<< info.signCount() - << "\n signfirst: "<< info.signFirst() - << "\n signlast: " << info.signLast() - << "\n encrcount: "<< info.encrCount() - << "\n encrfirst: "<< info.encrFirst() - << "\n encrlast: " << info.encrLast() - << '\n'; - } - return os << ")"; -} diff --git a/lang/cpp/src/tofuinfo.h b/lang/cpp/src/tofuinfo.h deleted file mode 100644 index 67ed62a5..00000000 --- a/lang/cpp/src/tofuinfo.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - tofuinfo.h - wraps gpgme tofu info - Copyright (C) 2016 by Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_TOFUINFO_H__ -#define __GPGMEPP_TOFUINFO_H__ - -#include "gpgmepp_export.h" - -#include "global.h" - -#include <memory> - -namespace GpgME -{ - -class GPGMEPP_EXPORT TofuInfo -{ -public: - TofuInfo(); - explicit TofuInfo(gpgme_tofu_info_t info); - - TofuInfo(const TofuInfo &other) = default; - const TofuInfo &operator=(TofuInfo other) - { - swap(other); - return *this; - } - - void swap(TofuInfo &other) - { - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - /* @enum Validity - * @brief The TOFU Validity. */ - enum Validity : unsigned int { - /*! Unknown (uninitialized).*/ - ValidityUnknown, - /*! TOFU Conflict.*/ - Conflict, - /*! Key without history.*/ - NoHistory, - /*! Key with too little history.*/ - LittleHistory, - /*! Key with enough history for basic trust.*/ - BasicHistory, - /*! Key with a lot of history.*/ - LargeHistory, - }; - Validity validity() const; - - /* @enum Policy - * @brief The TOFU Validity. */ - enum Policy : unsigned int { - /*! GPGME_TOFU_POLICY_NONE */ - PolicyNone, - /*! GPGME_TOFU_POLICY_AUTO */ - PolicyAuto, - /*! GPGME_TOFU_POLICY_GOOD */ - PolicyGood, - /*! GPGME_TOFU_POLICY_UNKNOWN */ - PolicyUnknown, - /*! GPGME_TOFU_POLICY_BAD */ - PolicyBad, - /*! GPGME_TOFU_POLICY_ASK */ - PolicyAsk, - }; - Policy policy() const; - - /* Number of signatures seen for this binding. Capped at USHRT_MAX. */ - unsigned short signCount() const; - - /* Number of encryption done to this binding. Capped at USHRT_MAX. */ - unsigned short encrCount() const; - - /** Number of seconds since epoch when the first message was verified */ - unsigned long signFirst() const; - - /** Number of seconds since epoch when the last message was verified */ - unsigned long signLast() const; - - /** Number of seconds since epoch when the first message was encrypted */ - unsigned long encrFirst() const; - - /** Number of seconds since epoch when the last message was encrypted */ - unsigned long encrLast() const; - - /* If non-NULL a human readable string summarizing the TOFU data. */ - const char *description() const; - -private: - class Private; - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const TofuInfo &info); - -} // namespace GpgME - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(TofuInfo) -#endif // __GPGMEPP_TOFUINFO_H__ diff --git a/lang/cpp/src/trustitem.cpp b/lang/cpp/src/trustitem.cpp deleted file mode 100644 index 4302f657..00000000 --- a/lang/cpp/src/trustitem.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - trustitem.cpp - wraps a gpgme trust item - Copyright (C) 2003 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <trustitem.h> - -#include <gpgme.h> - -#include <cassert> - -namespace GpgME -{ - -class TrustItem::Private -{ -public: - Private(gpgme_trust_item_t aItem) - : item(aItem) - { - } - - gpgme_trust_item_t item; -}; - -TrustItem::TrustItem(gpgme_trust_item_t item) -{ - d = new Private(item); - if (d->item) { - gpgme_trust_item_ref(d->item); - } -} - -TrustItem::TrustItem(const TrustItem &other) -{ - d = new Private(other.d->item); - if (d->item) { - gpgme_trust_item_ref(d->item); - } -} - -TrustItem::~TrustItem() -{ - if (d->item) { - gpgme_trust_item_unref(d->item); - } - delete d; d = nullptr; -} - -bool TrustItem::isNull() const -{ - return !d || !d->item; -} - -gpgme_trust_item_t TrustItem::impl() const -{ - return d->item; -} - -const char *TrustItem::keyID() const -{ - return d->item ? d->item->keyid : nullptr ; -} - -const char *TrustItem::userID() const -{ - return d->item ? d->item->name : nullptr ; -} - -const char *TrustItem::ownerTrustAsString() const -{ - return d->item ? d->item->owner_trust : nullptr ; -} - -const char *TrustItem::validityAsString() const -{ - return d->item ? d->item->validity : nullptr ; -} - -int TrustItem::trustLevel() const -{ - return d->item ? d->item->level : 0 ; -} - -TrustItem::Type TrustItem::type() const -{ - if (!d->item) { - return Unknown; - } else { - return - d->item->type == 1 ? Key : - d->item->type == 2 ? UserID : - Unknown ; - } -} - -} // namespace GpgME diff --git a/lang/cpp/src/trustitem.h b/lang/cpp/src/trustitem.h deleted file mode 100644 index a951bdf9..00000000 --- a/lang/cpp/src/trustitem.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - trustitem.h - wraps a gpgme trust item - Copyright (C) 2003 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_TRUSTITEM_H__ -#define __GPGMEPP_TRUSTITEM_H__ - -#include "gpgmefw.h" -#include "key.h" -#include "gpgmepp_export.h" - -#include <algorithm> - -namespace GpgME -{ - -class Context; - -class GPGMEPP_EXPORT TrustItem -{ - friend class ::GpgME::Context; -public: - explicit TrustItem(gpgme_trust_item_t item = nullptr); - TrustItem(const TrustItem &other); - virtual ~TrustItem(); - - const TrustItem &operator=(TrustItem other) - { - swap(other); - return *this; - } - - void swap(TrustItem &other) - { - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - const char *keyID() const; - const char *userID() const; - - const char *ownerTrustAsString() const; - const char *validityAsString() const; - - int trustLevel() const; - - enum Type { Unknown = 0, Key = 1, UserID = 2 }; - Type type() const; - -private: - gpgme_trust_item_t impl() const; - class Private; - Private *d; -}; - -} // namepace GpgME - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(TrustItem) - -#endif // __GPGMEPP_TRUSTITEM_H__ diff --git a/lang/cpp/src/util.cpp b/lang/cpp/src/util.cpp deleted file mode 100644 index 9104435f..00000000 --- a/lang/cpp/src/util.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - util.cpp - some internal helpers - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "util.h" - -#include <functional> - -StringsToCStrings::StringsToCStrings(const std::vector<std::string>& v) - : m_strings{v} -{ -} - -const char **StringsToCStrings::c_strs() const -{ - if (m_cstrings.empty()) { - m_cstrings.reserve(m_strings.size() + 1); - std::transform(std::begin(m_strings), std::end(m_strings), - std::back_inserter(m_cstrings), - std::mem_fn(&std::string::c_str)); - m_cstrings.push_back(nullptr); - } - return m_cstrings.data(); -} diff --git a/lang/cpp/src/util.h b/lang/cpp/src/util.h deleted file mode 100644 index cb6df0d0..00000000 --- a/lang/cpp/src/util.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - util.h - some internal helpers - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - Copyright (c) 2022 g10 Code GmbH - Software engineering by Ingo Klöcker <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// -*- c++ -*- -#ifndef __GPGMEPP_UTIL_H__ -#define __GPGMEPP_UTIL_H__ - -#include "global.h" -#include "notation.h" - -#include <gpgme.h> - -#ifndef NDEBUG -#include <iostream> -#endif -#include <sstream> -#include <string> - -static inline const char *protect(const char *s) -{ - return s ? s : "<null>" ; -} - -static inline gpgme_error_t make_error(gpgme_err_code_t code) -{ - return gpgme_err_make((gpgme_err_source_t)22, code); -} - -static inline unsigned long to_pid(const std::string &s) -{ - std::stringstream ss(s); - unsigned int result; - if (ss >> result) { - return result; - } else { - return 0U; - } -} - -static inline gpgme_keylist_mode_t add_to_gpgme_keylist_mode_t(unsigned int oldmode, unsigned int newmodes) -{ - if (newmodes & GpgME::Local) { - oldmode |= GPGME_KEYLIST_MODE_LOCAL; - } - if (newmodes & GpgME::Extern) { - oldmode |= GPGME_KEYLIST_MODE_EXTERN; - } - if (newmodes & GpgME::Signatures) { - oldmode |= GPGME_KEYLIST_MODE_SIGS; - } - if (newmodes & GpgME::SignatureNotations) { - oldmode |= GPGME_KEYLIST_MODE_SIG_NOTATIONS; - } - if (newmodes & GpgME::Validate) { - oldmode |= GPGME_KEYLIST_MODE_VALIDATE; - } - if (newmodes & GpgME::Ephemeral) { - oldmode |= GPGME_KEYLIST_MODE_EPHEMERAL; - } - if (newmodes & GpgME::WithTofu) { - oldmode |= GPGME_KEYLIST_MODE_WITH_TOFU; - } - if (newmodes & GpgME::WithKeygrip) { - oldmode |= GPGME_KEYLIST_MODE_WITH_KEYGRIP; - } - if (newmodes & GpgME::WithSecret) { - oldmode |= GPGME_KEYLIST_MODE_WITH_SECRET; - } - if (newmodes & GpgME::ForceExtern) { - oldmode |= GPGME_KEYLIST_MODE_FORCE_EXTERN; - } -#ifndef NDEBUG - if (newmodes & ~(GpgME::KeyListModeMask)) { - //std::cerr << "GpgME::Context: keylist mode must be one of Local, " - //"Extern, Signatures, SignatureNotations, Validate, Ephemeral, WithTofu, " - //"WithKeygrip, WithSecret, ForceExtern, or a combination thereof!" - //<< std::endl; - } -#endif - return static_cast<gpgme_keylist_mode_t>(oldmode); -} - -static inline unsigned int convert_from_gpgme_keylist_mode_t(unsigned int mode) -{ - unsigned int result = 0; - if (mode & GPGME_KEYLIST_MODE_LOCAL) { - result |= GpgME::Local; - } - if (mode & GPGME_KEYLIST_MODE_EXTERN) { - result |= GpgME::Extern; - } - if (mode & GPGME_KEYLIST_MODE_SIGS) { - result |= GpgME::Signatures; - } - if (mode & GPGME_KEYLIST_MODE_SIG_NOTATIONS) { - result |= GpgME::SignatureNotations; - } - if (mode & GPGME_KEYLIST_MODE_WITH_SECRET) { - result |= GpgME::WithSecret; - } - if (mode & GPGME_KEYLIST_MODE_WITH_TOFU) { - result |= GpgME::WithTofu; - } - if (mode & GPGME_KEYLIST_MODE_WITH_KEYGRIP) { - result |= GpgME::WithKeygrip; - } - if (mode & GPGME_KEYLIST_MODE_EPHEMERAL) { - result |= GpgME::Ephemeral; - } - if (mode & GPGME_KEYLIST_MODE_VALIDATE) { - result |= GpgME::Validate; - } - if (mode & GPGME_KEYLIST_MODE_FORCE_EXTERN) { - result |= GpgME::ForceExtern; - } -#ifndef NDEBUG - if (mode & ~(GPGME_KEYLIST_MODE_LOCAL | - GPGME_KEYLIST_MODE_EXTERN | - GPGME_KEYLIST_MODE_SIGS | - GPGME_KEYLIST_MODE_SIG_NOTATIONS | - GPGME_KEYLIST_MODE_WITH_SECRET | - GPGME_KEYLIST_MODE_WITH_TOFU | - GPGME_KEYLIST_MODE_WITH_KEYGRIP | - GPGME_KEYLIST_MODE_EPHEMERAL | - GPGME_KEYLIST_MODE_VALIDATE | - GPGME_KEYLIST_MODE_FORCE_EXTERN)) { - //std::cerr << "GpgME: WARNING: gpgme_get_keylist_mode() returned an unknown flag!" << std::endl; - } -#endif // NDEBUG - return result; -} - -static inline GpgME::Notation::Flags convert_from_gpgme_sig_notation_flags_t(unsigned int flags) -{ - unsigned int result = 0; - if (flags & GPGME_SIG_NOTATION_HUMAN_READABLE) { - result |= GpgME::Notation::HumanReadable ; - } - if (flags & GPGME_SIG_NOTATION_CRITICAL) { - result |= GpgME::Notation::Critical ; - } - return static_cast<GpgME::Notation::Flags>(result); -} - -static inline gpgme_sig_notation_flags_t add_to_gpgme_sig_notation_flags_t(unsigned int oldflags, unsigned int newflags) -{ - unsigned int result = oldflags; - if (newflags & GpgME::Notation::HumanReadable) { - result |= GPGME_SIG_NOTATION_HUMAN_READABLE; - } - if (newflags & GpgME::Notation::Critical) { - result |= GPGME_SIG_NOTATION_CRITICAL; - } - return static_cast<gpgme_sig_notation_flags_t>(result); -} - -static inline std::vector<std::string> split(const std::string &text, char delimiter) -{ - std::vector<std::string> result; - if (!text.empty()) { - std::istringstream stream{text}; - std::string line; - while (std::getline(stream, line, delimiter)) { - result.push_back(line); - } - } - return result; -} - -/** - * Adapter for passing a vector of strings as NULL-terminated array of - * const char* to the C-interface of gpgme. - */ -class StringsToCStrings -{ -public: - explicit StringsToCStrings(const std::vector<std::string> &v); - ~StringsToCStrings() = default; - - StringsToCStrings(const StringsToCStrings &) = delete; - StringsToCStrings &operator=(const StringsToCStrings &) = delete; - StringsToCStrings(StringsToCStrings &&) = delete; - StringsToCStrings &operator=(StringsToCStrings &&) = delete; - - const char **c_strs() const; -private: - const std::vector<std::string> m_strings; - mutable std::vector<const char *> m_cstrings; -}; - -#endif // __GPGMEPP_UTIL_H__ diff --git a/lang/cpp/src/verificationresult.cpp b/lang/cpp/src/verificationresult.cpp deleted file mode 100644 index 0299fcec..00000000 --- a/lang/cpp/src/verificationresult.cpp +++ /dev/null @@ -1,642 +0,0 @@ -/* - verificationresult.cpp - wraps a gpgme verify result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <verificationresult.h> -#include <notation.h> -#include "result_p.h" -#include "util.h" -#include "key.h" -#include "context.h" - -#include <gpgme.h> - -#include <istream> -#include <algorithm> -#include <iterator> -#include <string> -#include <cstring> -#include <cstdlib> - -#include <string.h> - -class GpgME::VerificationResult::Private -{ -public: - explicit Private(const gpgme_verify_result_t r) - { - if (!r) { - return; - } - if (r->file_name) { - file_name = r->file_name; - } - // copy recursively, using compiler-generated copy ctor. - // We just need to handle the pointers in the structs: - for (gpgme_signature_t is = r->signatures ; is ; is = is->next) { - gpgme_signature_t scopy = new _gpgme_signature(*is); - if (is->fpr) { - scopy->fpr = strdup(is->fpr); - } -// PENDING(marc) why does this crash on Windows in strdup()? -# ifndef _WIN32 - if (is->pka_address) { - scopy->pka_address = strdup(is->pka_address); - } -# else - scopy->pka_address = nullptr; -# endif - scopy->next = nullptr; - sigs.push_back(scopy); - // copy keys - if (scopy->key) { - keys.push_back(Key(scopy->key, true)); - } else { - keys.push_back(Key()); - } - // copy notations: - nota.push_back(std::vector<Nota>()); - purls.push_back(nullptr); - for (gpgme_sig_notation_t in = is->notations ; in ; in = in->next) { - if (!in->name) { - if (in->value) { - purls.back() = strdup(in->value); // policy url - } - continue; - } - Nota n = { nullptr, nullptr, in->flags }; - n.name = strdup(in->name); - if (in->value) { - n.value = strdup(in->value); - } - nota.back().push_back(n); - } - } - } - ~Private() - { - for (std::vector<gpgme_signature_t>::iterator it = sigs.begin() ; it != sigs.end() ; ++it) { - std::free((*it)->fpr); - std::free((*it)->pka_address); - delete *it; *it = nullptr; - } - for (std::vector< std::vector<Nota> >::iterator it = nota.begin() ; it != nota.end() ; ++it) { - for (std::vector<Nota>::iterator jt = it->begin() ; jt != it->end() ; ++jt) { - std::free(jt->name); jt->name = nullptr; - std::free(jt->value); jt->value = nullptr; - } - } - std::for_each(purls.begin(), purls.end(), &std::free); - } - - struct Nota { - char *name; - char *value; - gpgme_sig_notation_flags_t flags; - }; - - std::vector<gpgme_signature_t> sigs; - std::vector< std::vector<Nota> > nota; - std::vector<GpgME::Key> keys; - std::vector<char *> purls; - std::string file_name; - Protocol proto; -}; - -GpgME::VerificationResult::VerificationResult(gpgme_ctx_t ctx, int error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -GpgME::VerificationResult::VerificationResult(gpgme_ctx_t ctx, const Error &error) - : GpgME::Result(error), d() -{ - init(ctx); -} - -void GpgME::VerificationResult::init(gpgme_ctx_t ctx) -{ - if (!ctx) { - return; - } - gpgme_verify_result_t res = gpgme_op_verify_result(ctx); - if (!res) { - return; - } - d.reset(new Private(res)); - gpgme_protocol_t proto = gpgme_get_protocol(ctx); - d->proto = proto == GPGME_PROTOCOL_OpenPGP ? OpenPGP : - proto == GPGME_PROTOCOL_CMS ? CMS : - UnknownProtocol; -} - -make_standard_stuff(VerificationResult) - -const char *GpgME::VerificationResult::fileName() const -{ - return d ? d->file_name.c_str() : nullptr ; -} - -unsigned int GpgME::VerificationResult::numSignatures() const -{ - return d ? d->sigs.size() : 0 ; -} - -GpgME::Signature GpgME::VerificationResult::signature(unsigned int idx) const -{ - return Signature(d, idx); -} - -std::vector<GpgME::Signature> GpgME::VerificationResult::signatures() const -{ - if (!d) { - return std::vector<Signature>(); - } - std::vector<Signature> result; - result.reserve(d->sigs.size()); - for (unsigned int i = 0 ; i < d->sigs.size() ; ++i) { - result.push_back(Signature(d, i)); - } - return result; -} - -GpgME::Signature::Signature(const std::shared_ptr<VerificationResult::Private> &parent, unsigned int i) - : d(parent), idx(i) -{ -} - -GpgME::Signature::Signature() : d(), idx(0) {} - -bool GpgME::Signature::isNull() const -{ - return !d || idx >= d->sigs.size() ; -} - -GpgME::Signature::Summary GpgME::Signature::summary() const -{ - if (isNull()) { - return None; - } - gpgme_sigsum_t sigsum = d->sigs[idx]->summary; - unsigned int result = 0; - if (sigsum & GPGME_SIGSUM_VALID) { - result |= Valid; - } - if (sigsum & GPGME_SIGSUM_GREEN) { - result |= Green; - } - if (sigsum & GPGME_SIGSUM_RED) { - result |= Red; - } - if (sigsum & GPGME_SIGSUM_KEY_REVOKED) { - result |= KeyRevoked; - } - if (sigsum & GPGME_SIGSUM_KEY_EXPIRED) { - result |= KeyExpired; - } - if (sigsum & GPGME_SIGSUM_SIG_EXPIRED) { - result |= SigExpired; - } - if (sigsum & GPGME_SIGSUM_KEY_MISSING) { - result |= KeyMissing; - } - if (sigsum & GPGME_SIGSUM_CRL_MISSING) { - result |= CrlMissing; - } - if (sigsum & GPGME_SIGSUM_CRL_TOO_OLD) { - result |= CrlTooOld; - } - if (sigsum & GPGME_SIGSUM_BAD_POLICY) { - result |= BadPolicy; - } - if (sigsum & GPGME_SIGSUM_SYS_ERROR) { - result |= SysError; - } - if (sigsum & GPGME_SIGSUM_TOFU_CONFLICT) { - result |= TofuConflict; - } - return static_cast<Summary>(result); -} - -const char *GpgME::Signature::fingerprint() const -{ - return isNull() ? nullptr : d->sigs[idx]->fpr ; -} - -GpgME::Error GpgME::Signature::status() const -{ - return Error(isNull() ? 0 : d->sigs[idx]->status); -} - -time_t GpgME::Signature::creationTime() const -{ - return static_cast<time_t>(isNull() ? 0 : d->sigs[idx]->timestamp); -} - -time_t GpgME::Signature::expirationTime() const -{ - return static_cast<time_t>(isNull() ? 0 : d->sigs[idx]->exp_timestamp); -} - -bool GpgME::Signature::neverExpires() const -{ - return expirationTime() == (time_t)0; -} - -bool GpgME::Signature::isWrongKeyUsage() const -{ - return !isNull() && d->sigs[idx]->wrong_key_usage; -} - -bool GpgME::Signature::isVerifiedUsingChainModel() const -{ - return !isNull() && d->sigs[idx]->chain_model; -} - -bool GpgME::Signature::isDeVs() const -{ - return !isNull() && d->sigs[idx]->is_de_vs; -} - -bool GpgME::Signature::isBetaCompliance() const -{ - return !isNull() && d->sigs[idx]->beta_compliance; -} - -GpgME::Signature::PKAStatus GpgME::Signature::pkaStatus() const -{ - if (!isNull()) { - return static_cast<PKAStatus>(d->sigs[idx]->pka_trust); - } - return UnknownPKAStatus; -} - -const char *GpgME::Signature::pkaAddress() const -{ - if (!isNull()) { - return d->sigs[idx]->pka_address; - } - return nullptr; -} - -GpgME::Signature::Validity GpgME::Signature::validity() const -{ - if (isNull()) { - return Unknown; - } - switch (d->sigs[idx]->validity) { - default: - case GPGME_VALIDITY_UNKNOWN: return Unknown; - case GPGME_VALIDITY_UNDEFINED: return Undefined; - case GPGME_VALIDITY_NEVER: return Never; - case GPGME_VALIDITY_MARGINAL: return Marginal; - case GPGME_VALIDITY_FULL: return Full; - case GPGME_VALIDITY_ULTIMATE: return Ultimate; - } -} - -char GpgME::Signature::validityAsString() const -{ - if (isNull()) { - return '?'; - } - switch (d->sigs[idx]->validity) { - default: - case GPGME_VALIDITY_UNKNOWN: return '?'; - case GPGME_VALIDITY_UNDEFINED: return 'q'; - case GPGME_VALIDITY_NEVER: return 'n'; - case GPGME_VALIDITY_MARGINAL: return 'm'; - case GPGME_VALIDITY_FULL: return 'f'; - case GPGME_VALIDITY_ULTIMATE: return 'u'; - } -} - -GpgME::Error GpgME::Signature::nonValidityReason() const -{ - return Error(isNull() ? 0 : d->sigs[idx]->validity_reason); -} - -unsigned int GpgME::Signature::publicKeyAlgorithm() const -{ - if (!isNull()) { - return d->sigs[idx]->pubkey_algo; - } - return 0; -} - -const char *GpgME::Signature::publicKeyAlgorithmAsString() const -{ - if (!isNull()) { - return gpgme_pubkey_algo_name(d->sigs[idx]->pubkey_algo); - } - return nullptr; -} - -unsigned int GpgME::Signature::hashAlgorithm() const -{ - if (!isNull()) { - return d->sigs[idx]->hash_algo; - } - return 0; -} - -const char *GpgME::Signature::hashAlgorithmAsString() const -{ - if (!isNull()) { - return gpgme_hash_algo_name(d->sigs[idx]->hash_algo); - } - return nullptr; -} - -const char *GpgME::Signature::policyURL() const -{ - return isNull() ? nullptr : d->purls[idx] ; -} - -GpgME::Notation GpgME::Signature::notation(unsigned int nidx) const -{ - return GpgME::Notation(d, idx, nidx); -} - -std::vector<GpgME::Notation> GpgME::Signature::notations() const -{ - if (isNull()) { - return std::vector<GpgME::Notation>(); - } - std::vector<GpgME::Notation> result; - result.reserve(d->nota[idx].size()); - for (unsigned int i = 0 ; i < d->nota[idx].size() ; ++i) { - result.push_back(GpgME::Notation(d, idx, i)); - } - return result; -} - -GpgME::Key GpgME::Signature::key() const -{ - if (isNull()) { - return Key(); - } - return d->keys[idx]; -} - -GpgME::Key GpgME::Signature::key(bool search, bool update) const -{ - if (isNull()) { - return Key(); - } - - GpgME::Key ret = key(); - if (ret.isNull() && search && fingerprint ()) { - auto ctx = Context::createForProtocol (d->proto); - if (ctx) { - ctx->setKeyListMode(KeyListMode::Local | - KeyListMode::Signatures | - KeyListMode::SignatureNotations | - KeyListMode::Validate | - KeyListMode::WithTofu | - KeyListMode::WithKeygrip); - Error e; - ret = d->keys[idx] = ctx->key(fingerprint(), e, false); - delete ctx; - } - } - if (update) { - d->keys[idx].update(); - ret = d->keys[idx]; - } - return ret; -} - -class GpgME::Notation::Private -{ -public: - Private() : d(), sidx(0), nidx(0), nota(nullptr) {} - Private(const std::shared_ptr<VerificationResult::Private> &priv, unsigned int sindex, unsigned int nindex) - : d(priv), sidx(sindex), nidx(nindex), nota(nullptr) - { - - } - Private(gpgme_sig_notation_t n) - : d(), sidx(0), nidx(0), nota(n ? new _gpgme_sig_notation(*n) : nullptr) - { - if (nota && nota->name) { - nota->name = strdup(nota->name); - } - if (nota && nota->value) { - nota->value = strdup(nota->value); - } - } - Private(const Private &other) - : d(other.d), sidx(other.sidx), nidx(other.nidx), nota(other.nota) - { - if (nota) { - nota->name = strdup(nota->name); - nota->value = strdup(nota->value); - } - } - ~Private() - { - if (nota) { - std::free(nota->name); nota->name = nullptr; - std::free(nota->value); nota->value = nullptr; - delete nota; - } - } - - std::shared_ptr<VerificationResult::Private> d; - unsigned int sidx, nidx; - gpgme_sig_notation_t nota; -}; - -GpgME::Notation::Notation(const std::shared_ptr<VerificationResult::Private> &parent, unsigned int sindex, unsigned int nindex) - : d(new Private(parent, sindex, nindex)) -{ - -} - -GpgME::Notation::Notation(gpgme_sig_notation_t nota) - : d(new Private(nota)) -{ - -} - -GpgME::Notation::Notation() : d() {} - -bool GpgME::Notation::isNull() const -{ - if (!d) { - return true; - } - if (d->d) { - return d->sidx >= d->d->nota.size() || d->nidx >= d->d->nota[d->sidx].size() ; - } - return !d->nota; -} - -const char *GpgME::Notation::name() const -{ - return - isNull() ? nullptr : - d->d ? d->d->nota[d->sidx][d->nidx].name : - d->nota ? d->nota->name : nullptr ; -} - -const char *GpgME::Notation::value() const -{ - return - isNull() ? nullptr : - d->d ? d->d->nota[d->sidx][d->nidx].value : - d->nota ? d->nota->value : nullptr ; -} - -GpgME::Notation::Flags GpgME::Notation::flags() const -{ - return - convert_from_gpgme_sig_notation_flags_t( - isNull() ? 0: - d->d ? d->d->nota[d->sidx][d->nidx].flags : - d->nota ? d->nota->flags : 0); -} - -bool GpgME::Notation::isHumanReadable() const -{ - return flags() & HumanReadable; -} - -bool GpgME::Notation::isCritical() const -{ - return flags() & Critical; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const VerificationResult &result) -{ - os << "GpgME::VerificationResult("; - if (!result.isNull()) { - os << "\n error: " << result.error() - << "\n fileName: " << protect(result.fileName()) - << "\n signatures:\n"; - const std::vector<Signature> sigs = result.signatures(); - std::copy(sigs.begin(), sigs.end(), - std::ostream_iterator<Signature>(os, "\n")); - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, Signature::PKAStatus pkaStatus) -{ - os << "GpgME::Signature::PKAStatus("; - switch (pkaStatus) { -#define OUTPUT( x ) case GpgME::Signature:: x: os << #x; break - OUTPUT(UnknownPKAStatus); - OUTPUT(PKAVerificationFailed); - OUTPUT(PKAVerificationSucceeded); -#undef OUTPUT - default: - os << "??? (" << static_cast<int>(pkaStatus) << ')'; - break; - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, Signature::Summary summary) -{ - os << "GpgME::Signature::Summary("; - if (summary == Signature::None) { - os << "None"; - } else { -#define OUTPUT( x ) if ( !(summary & (GpgME::Signature:: x)) ) {} else do { os << #x " "; } while(0) - OUTPUT(Valid); - OUTPUT(Green); - OUTPUT(Red); - OUTPUT(KeyRevoked); - OUTPUT(KeyExpired); - OUTPUT(SigExpired); - OUTPUT(KeyMissing); - OUTPUT(CrlMissing); - OUTPUT(CrlTooOld); - OUTPUT(BadPolicy); - OUTPUT(SysError); - OUTPUT(TofuConflict); -#undef OUTPUT - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const Signature &sig) -{ - os << "GpgME::Signature("; - if (!sig.isNull()) { - os << "\n Summary: " << sig.summary() - << "\n Fingerprint: " << protect(sig.fingerprint()) - << "\n Status: " << sig.status() - << "\n creationTime: " << sig.creationTime() - << "\n expirationTime: " << sig.expirationTime() - << "\n isWrongKeyUsage: " << sig.isWrongKeyUsage() - << "\n isVerifiedUsingChainModel: " << sig.isVerifiedUsingChainModel() - << "\n pkaStatus: " << sig.pkaStatus() - << "\n pkaAddress: " << protect(sig.pkaAddress()) - << "\n validity: " << sig.validityAsString() - << "\n nonValidityReason: " << sig.nonValidityReason() - << "\n publicKeyAlgorithm: " << protect(sig.publicKeyAlgorithmAsString()) - << "\n hashAlgorithm: " << protect(sig.hashAlgorithmAsString()) - << "\n policyURL: " << protect(sig.policyURL()) - << "\n isDeVs: " << sig.isDeVs() - << "\n isBetaCompliance: " << sig.isBetaCompliance() - << "\n notations:\n"; - const std::vector<Notation> nota = sig.notations(); - std::copy(nota.begin(), nota.end(), - std::ostream_iterator<Notation>(os, "\n")); - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, Notation::Flags flags) -{ - os << "GpgME::Notation::Flags("; - if (flags == Notation::NoFlags) { - os << "NoFlags"; - } else { -#define OUTPUT( x ) if ( !(flags & (GpgME::Notation:: x)) ) {} else do { os << #x " "; } while(0) - OUTPUT(HumanReadable); - OUTPUT(Critical); -#undef OUTPUT - } - return os << ')'; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const Notation ¬a) -{ - os << "GpgME::Signature::Notation("; - if (!nota.isNull()) { - os << "\n name: " << protect(nota.name()) - << "\n value: " << protect(nota.value()) - << "\n flags: " << nota.flags() - << '\n'; - } - return os << ")"; -} diff --git a/lang/cpp/src/verificationresult.h b/lang/cpp/src/verificationresult.h deleted file mode 100644 index cd455d31..00000000 --- a/lang/cpp/src/verificationresult.h +++ /dev/null @@ -1,207 +0,0 @@ -/* - verificationresult.h - wraps a gpgme verify result - Copyright (C) 2004 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_VERIFICATIONRESULT_H__ -#define __GPGMEPP_VERIFICATIONRESULT_H__ - -#include "gpgmefw.h" -#include "result.h" -#include "gpgmepp_export.h" - -#include <time.h> - -#include <memory> - -#include <vector> -#include <iosfwd> - -namespace GpgME -{ - -class Error; -class Signature; -class Notation; -class Key; - -class GPGMEPP_EXPORT VerificationResult : public Result -{ -public: - VerificationResult(); - VerificationResult(gpgme_ctx_t ctx, int error); - VerificationResult(gpgme_ctx_t ctx, const Error &error); - explicit VerificationResult(const Error &err); - - VerificationResult(const VerificationResult &other) = default; - const VerificationResult &operator=(VerificationResult other) - { - swap(other); - return *this; - } - - void swap(VerificationResult &other) - { - Result::swap(other); - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - - const char *fileName() const; - - unsigned int numSignatures() const; - Signature signature(unsigned int index) const; - std::vector<Signature> signatures() const; - - class Private; -private: - void init(gpgme_ctx_t ctx); - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const VerificationResult &result); - -class GPGMEPP_EXPORT Signature -{ - friend class ::GpgME::VerificationResult; - Signature(const std::shared_ptr<VerificationResult::Private> &parent, unsigned int index); -public: - GPGMEPP_DEPRECATED typedef GpgME::Notation Notation; - - Signature(); - - Signature(const Signature &other) = default; - const Signature &operator=(Signature other) - { - swap(other); - return *this; - } - - void swap(Signature &other) - { - using std::swap; - swap(this->d, other.d); - swap(this->idx, other.idx); - } - - bool isNull() const; - - enum Summary { - None = 0x000, - Valid = 0x001, - Green = 0x002, - Red = 0x004, - KeyRevoked = 0x008, - KeyExpired = 0x010, - SigExpired = 0x020, - KeyMissing = 0x040, - CrlMissing = 0x080, - CrlTooOld = 0x100, - BadPolicy = 0x200, - SysError = 0x400, - TofuConflict= 0x800 - }; - Summary summary() const; - - const char *fingerprint() const; - - Error status() const; - - time_t creationTime() const; - time_t expirationTime() const; - bool neverExpires() const; - - GPGMEPP_DEPRECATED bool wrongKeyUsage() const - { - return isWrongKeyUsage(); - } - bool isWrongKeyUsage() const; - bool isVerifiedUsingChainModel() const; - bool isDeVs() const; - bool isBetaCompliance() const; - - enum PKAStatus { - UnknownPKAStatus, PKAVerificationFailed, PKAVerificationSucceeded - }; - PKAStatus pkaStatus() const; - const char *pkaAddress() const; - - enum Validity { - Unknown, Undefined, Never, Marginal, Full, Ultimate - }; - Validity validity() const; - char validityAsString() const; - Error nonValidityReason() const; - - unsigned int publicKeyAlgorithm() const; - const char *publicKeyAlgorithmAsString() const; - - unsigned int hashAlgorithm() const; - const char *hashAlgorithmAsString() const; - - const char *policyURL() const; - GpgME::Notation notation(unsigned int index) const; - std::vector<GpgME::Notation> notations() const; - - /** Returns the key object associated with this signature. - * May be incomplete but will have at least the fingerprint - * set or the associated TOFU Information if applicable. */ - GpgME::Key key() const; - - /* Search / Update the key of this signature. - * - * Same as above but if search is set to true this will - * either update the key provided by the engine or search - * the key in the engine. The key is cached. - * - * As this involves an engine call it might take some time - * to finish so it should be avoided to do this in a UI - * thread. The result will be cached and no engine call - * will be done if update is set to false and a key is - * already cached. - * - * If no key was provided by the engine this will look - * up the key so this call might block while the engine - * is called to obtain the key. - * - * If both search and update are false this is the same - * as calling key() - */ - GpgME::Key key(bool search, bool update) const; - -private: - std::shared_ptr<VerificationResult::Private> d; - unsigned int idx; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const Signature &sig); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Signature::PKAStatus pkaStatus); -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, Signature::Summary summary); - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(VerificationResult) -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Signature) - -#endif // __GPGMEPP_VERIFICATIONRESULT_H__ diff --git a/lang/cpp/src/vfsmountresult.cpp b/lang/cpp/src/vfsmountresult.cpp deleted file mode 100644 index 901ccfe2..00000000 --- a/lang/cpp/src/vfsmountresult.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - vfsmountresult.cpp - wraps a gpgme vfs mount result - Copyright (C) 2009 Klarälvdalens Datakonsult AB - 2016 Bundesamt für Sicherheit in der Informationstechnik - Software engineering by Intevation GmbH <[email protected]> - Author: Marc Mutz <[email protected]>, Volker Krause <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include <vfsmountresult.h> -#include "result_p.h" - -#include <gpgme.h> - -#include <istream> -#include <string.h> - -using namespace GpgME; - -class VfsMountResult::Private -{ -public: - explicit Private(const gpgme_vfs_mount_result_t r) : mountDir(nullptr) - { - if (r && r->mount_dir) { - mountDir = strdup(r->mount_dir); - } - } - - ~Private() - { - std::free(mountDir); - } - - char *mountDir; -}; - -VfsMountResult::VfsMountResult(gpgme_ctx_t ctx, const Error &error, const Error &opError) - : Result(error ? error : opError), d() -{ - init(ctx); -} - -void VfsMountResult::init(gpgme_ctx_t ctx) -{ - (void)ctx; - if (!ctx) { - return; - } - gpgme_vfs_mount_result_t res = gpgme_op_vfs_mount_result(ctx); - if (!res) { - return; - } - d.reset(new Private(res)); -} - -make_standard_stuff(VfsMountResult) - -const char *VfsMountResult::mountDir() const -{ - if (d) { - return d->mountDir; - } - return nullptr; -} - -std::ostream &GpgME::operator<<(std::ostream &os, const VfsMountResult &result) -{ - os << "GpgME::VfsMountResult("; - if (!result.isNull()) { - os << "\n error: " << result.error() - << "\n mount dir: " << result.mountDir() - << "\n"; - } - return os << ')'; -} diff --git a/lang/cpp/src/vfsmountresult.h b/lang/cpp/src/vfsmountresult.h deleted file mode 100644 index 6bc67ba3..00000000 --- a/lang/cpp/src/vfsmountresult.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - vfsmountresult.h - wraps a gpgme vfs mount result - Copyright (C) 2009 Klarälvdalens Datakonsult AB <[email protected]> - Author: Marc Mutz <[email protected]>, Volker Krause <[email protected]> - - This file is part of GPGME++. - - GPGME++ is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - GPGME++ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with GPGME++; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __GPGMEPP_VFSMOUNTRESULT_H__ -#define __GPGMEPP_VFSMOUNTRESULT_H__ - -#include "gpgmefw.h" -#include "result.h" -#include "gpgmepp_export.h" - -#include <memory> - -#include <vector> -#include <iosfwd> - -namespace GpgME -{ - -class Error; - -class GPGMEPP_EXPORT VfsMountResult : public Result -{ -public: - VfsMountResult(); - VfsMountResult(gpgme_ctx_t ctx, const Error &error, const Error &opError); - explicit VfsMountResult(const Error &err); - - VfsMountResult(const VfsMountResult &other) = default; - const VfsMountResult &operator=(VfsMountResult other) - { - swap(other); - return *this; - } - - void swap(VfsMountResult &other) - { - Result::swap(other); - using std::swap; - swap(this->d, other.d); - } - - bool isNull() const; - const char *mountDir() const; - - class Private; -private: - void init(gpgme_ctx_t ctx); - std::shared_ptr<Private> d; -}; - -GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const VfsMountResult &result); - -} - -GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(VfsMountResult) - -#endif // __GPGMEPP_VFSMOUNTRESULT_H__ |