From 6eebd95de1b3e0ac27be06fdb46e08ef5bc76f57 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Thu, 10 May 2012 18:34:51 +0200 Subject: [PATCH] Move FileKey::isHex() to Tools. --- src/core/Tools.cpp | 11 +++++++++++ src/core/Tools.h | 1 + src/keys/FileKey.cpp | 14 ++------------ src/keys/FileKey.h | 1 - 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index b235de012..6811d0785 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -103,4 +103,15 @@ QString imageReaderFilter() return formatsStringList.join(" "); } +bool isHex(const QByteArray& ba) +{ + Q_FOREACH (char c, ba) { + if ( !( (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ) ) { + return false; + } + } + + return true; +} + } // namespace Tools diff --git a/src/core/Tools.h b/src/core/Tools.h index 46463d2b1..65c0f5e2e 100644 --- a/src/core/Tools.h +++ b/src/core/Tools.h @@ -31,6 +31,7 @@ bool hasChild(const QObject* parent, const QObject* child); bool readAllFromDevice(QIODevice* device, QByteArray& data); QDateTime currentDateTimeUtc(); QString imageReaderFilter(); +bool isHex(const QByteArray& ba); } // namespace Tools diff --git a/src/keys/FileKey.cpp b/src/keys/FileKey.cpp index 1faf70490..9063251de 100644 --- a/src/keys/FileKey.cpp +++ b/src/keys/FileKey.cpp @@ -20,6 +20,7 @@ #include #include +#include "core/Tools.h" #include "crypto/CryptoHash.h" #include "crypto/Random.h" @@ -233,7 +234,7 @@ bool FileKey::loadHex(QIODevice* device) QByteArray data = device->readAll(); - if (!isHex(data)) { + if (!Tools::isHex(data)) { return false; } @@ -262,14 +263,3 @@ bool FileKey::loadHashed(QIODevice* device) return true; } - -bool FileKey::isHex(const QByteArray& ba) -{ - Q_FOREACH (char c, ba) { - if ( !( (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ) ) { - return false; - } - } - - return true; -} diff --git a/src/keys/FileKey.h b/src/keys/FileKey.h index cc2c87255..bf3b5d391 100644 --- a/src/keys/FileKey.h +++ b/src/keys/FileKey.h @@ -42,7 +42,6 @@ private: bool loadBinary(QIODevice* device); bool loadHex(QIODevice* device); bool loadHashed(QIODevice* device); - static bool isHex(const QByteArray& ba); QByteArray m_key; };