Commit c7be8cf8 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Use the hexdecode/hexencode helpers provided by libkleo

The hexdecode/hexencode helpers in libkleo are (apart from some additional
braces and explicit namespacing) identical copies.

GnuPG-bug-id: 5795
parent 3dbda428
Pipeline #128537 passed with stage
in 3 minutes and 30 seconds
......@@ -32,7 +32,7 @@ option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF)
# Standalone build. Find / include everything necessary.
set(KF5_MIN_VERSION "5.90.0")
set(KMIME_VERSION "5.19.40")
set(LIBKLEO_VERSION "5.19.48")
set(LIBKLEO_VERSION "5.19.49")
set(QT_REQUIRED_VERSION "5.15.2")
set(GPGME_REQUIRED_VERSION "1.15.0")
set(BOOST_REQUIRED_VERSION "1.58")
......
......@@ -79,7 +79,6 @@ set(_kleopatra_SRCS
utils/multivalidator.cpp
utils/systemtrayicon.cpp
utils/hex.cpp
utils/path-helper.cpp
utils/input.cpp
utils/output.cpp
......
......@@ -8,7 +8,6 @@ find_package(KF5TextWidgets ${KF5_MIN_VERSION} CONFIG REQUIRED)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version-kwatchgnupg.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/version-kwatchgnupg.h)
set(kwatchgnupg_SRCS
../utils/hex.cpp
../utils/kuniqueservice.cpp
../kleopatra_debug.cpp
kwatchgnupgmainwin.cpp
......
......@@ -14,7 +14,7 @@
#include "implementation_p.h"
#include <Libkleo/GnuPG>
#include <utils/hex.h>
#include <Libkleo/Hex>
#include "kleopatra_debug.h"
#include <KLocalizedString>
......
......@@ -24,10 +24,10 @@
#include <utils/output.h>
#include <Libkleo/GnuPG>
#include <utils/detail_p.h>
#include <utils/hex.h>
#include <utils/log.h>
#include <utils/kleo_assert.h>
#include <Libkleo/Hex>
#include <Libkleo/Stl_Util>
#include <Libkleo/KleoException>
#include <Libkleo/KeyCache>
......
......@@ -14,11 +14,11 @@
#include <crypto/decryptverifytask.h>
#include <crypto/decryptverifyemailcontroller.h>
#include <utils/hex.h>
#include <utils/input.h>
#include <utils/output.h>
#include <utils/kleo_assert.h>
#include <Libkleo/Hex>
#include <Libkleo/KleoException>
#include <Libkleo/KeyCache>
#include <Libkleo/Formatting>
......
......@@ -17,11 +17,11 @@
#include "crypto/decryptverifyfilescontroller.h"
#include "crypto/autodecryptverifyfilescontroller.h"
#include <utils/hex.h>
#include <utils/input.h>
#include <utils/output.h>
#include <utils/kleo_assert.h>
#include <Libkleo/Hex>
#include <Libkleo/Stl_Util>
#include <Libkleo/KleoException>
#include <Libkleo/KeyCache>
......
/* -*- mode: c++; c-basic-offset:4 -*-
utils/hex.cpp
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-kleopatra.h>
#include "hex.h"
#include <Libkleo/KleoException>
#include <KLocalizedString>
#include <QString>
#include <QByteArray>
using namespace Kleo;
static unsigned char unhex(unsigned char ch)
{
if (ch >= '0' && ch <= '9') {
return ch - '0';
}
if (ch >= 'A' && ch <= 'F') {
return ch - 'A' + 10;
}
if (ch >= 'a' && ch <= 'f') {
return ch - 'a' + 10;
}
const char cch = ch;
throw Exception(gpg_error(GPG_ERR_ASS_SYNTAX),
i18n("Invalid hex char '%1' in input stream.",
QString::fromLatin1(&cch, 1)));
}
std::string Kleo::hexdecode(const std::string &in)
{
std::string result;
result.reserve(in.size());
for (std::string::const_iterator it = in.begin(), end = in.end(); it != end; ++it)
if (*it == '%') {
++it;
unsigned char ch = '\0';
if (it == end)
throw Exception(gpg_error(GPG_ERR_ASS_SYNTAX),
i18n("Premature end of hex-encoded char in input stream"));
ch |= unhex(*it) << 4;
++it;
if (it == end)
throw Exception(gpg_error(GPG_ERR_ASS_SYNTAX),
i18n("Premature end of hex-encoded char in input stream"));
ch |= unhex(*it);
result.push_back(ch);
} else if (*it == '+') {
result += ' ';
} else {
result.push_back(*it);
}
return result;
}
std::string Kleo::hexencode(const std::string &in)
{
std::string result;
result.reserve(3 * in.size());
static const char hex[] = "0123456789ABCDEF";
for (std::string::const_iterator it = in.begin(), end = in.end(); it != end; ++it)
switch (const unsigned char ch = *it) {
default:
if ((ch >= '!' && ch <= '~') || ch > 0xA0) {
result += ch;
break;
}
// else fall through
case ' ':
result += '+';
break;
case '"':
case '#':
case '$':
case '%':
case '\'':
case '+':
case '=':
result += '%';
result += hex[(ch & 0xF0) >> 4 ];
result += hex[(ch & 0x0F) ];
break;
}
return result;
}
std::string Kleo::hexdecode(const char *in)
{
if (!in) {
return std::string();
}
return hexdecode(std::string(in));
}
std::string Kleo::hexencode(const char *in)
{
if (!in) {
return std::string();
}
return hexencode(std::string(in));
}
QByteArray Kleo::hexdecode(const QByteArray &in)
{
if (in.isNull()) {
return QByteArray();
}
const std::string result = hexdecode(std::string(in.constData()));
return QByteArray(result.data(), result.size());
}
QByteArray Kleo::hexencode(const QByteArray &in)
{
if (in.isNull()) {
return QByteArray();
}
const std::string result = hexencode(std::string(in.constData()));
return QByteArray(result.data(), result.size());
}
/* -*- mode: c++; c-basic-offset:4 -*-
utils/hex.h
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <string>
class QByteArray;
namespace Kleo
{
std::string hexencode(const char *s);
std::string hexdecode(const char *s);
std::string hexencode(const std::string &s);
std::string hexdecode(const std::string &s);
QByteArray hexencode(const QByteArray &s);
QByteArray hexdecode(const QByteArray &s);
}
......@@ -39,8 +39,7 @@ if(USABLE_ASSUAN_FOUND)
add_definitions(-DGPG_ERR_SOURCE_DEFAULT=GPG_ERR_SOURCE_USER_2)
set(test_uiserver_SRCS test_uiserver.cpp ${CMAKE_SOURCE_DIR}/src/utils/wsastarter.cpp
${CMAKE_SOURCE_DIR}/src/utils/hex.cpp)
set(test_uiserver_SRCS test_uiserver.cpp ${CMAKE_SOURCE_DIR}/src/utils/wsastarter.cpp)
#FIXME: omitting TEST makes test_uiserver print output again on a Win32 console;
# find a better fix for this issue
......
......@@ -16,10 +16,10 @@
#include <kleo-assuan.h>
#include <gpg-error.h>
#include <Libkleo/Hex>
#include <Libkleo/KleoException>
#include "utils/wsastarter.h"
#include "utils/hex.h"
#ifndef Q_OS_WIN32
# include <unistd.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment