From: hama Date: Wed, 18 Nov 2015 22:05:11 +0000 (+0100) Subject: cuRandomizer works X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=c5a53cfb48a3e5b10dee03b43c3f23e1fd99bafd;p=reqt cuRandomizer works --- diff --git a/base/ReRandomizer.cpp b/base/ReRandomizer.cpp index 8ef7b7a..2bf9595 100644 --- a/base/ReRandomizer.cpp +++ b/base/ReRandomizer.cpp @@ -10,7 +10,7 @@ */ #include "base/rebase.hpp" -#define WITH_TRACE +//#define WITH_TRACE #include "retrace.hpp" enum { LOC_READ_1 = LOC_FIRST_OF(LOC_RANDOMIZER), // 12201 @@ -1138,7 +1138,7 @@ bool ReByteScrambler::initFromHeader(int reservedLength, int markerLength, QByteArray& info) { TRACE("initFromHeader():\n"); - encryptedFrom = max(encryptedFrom, encryptedFrom < (int) sizeof(int64_t) + encryptedFrom = max(encryptedFrom, (int) sizeof(int64_t) + reservedLength + markerLength); bool rc = true; if (header == NULL) @@ -1151,7 +1151,7 @@ bool ReByteScrambler::initFromHeader(int reservedLength, int markerLength, } else { m_salt.fromBytes(reinterpret_cast(header->constData())); randomReset(); - TRACE1("salt: %08lx\n", m_salt.m_int); + TRACE2("salt: %08lx / %s\n", m_salt.m_int, hexBytes(m_salt.m_bytes, 8).constData()); QByteArray expectedMarker; if (markerLength > 0) m_contentRandom.nextString(markerLength, markerLength, expectedMarker); @@ -1207,8 +1207,8 @@ void ReByteScrambler::initHeader(int reservedLength, int markerLength, int infoLength, int encryptedFrom, const QByteArray& info) { TRACE("initHeader():\n"); - encryptedFrom = max(encryptedFrom, encryptedFrom < (int) sizeof(int64_t) - + reservedLength + markerLength); + encryptedFrom = max(encryptedFrom, + (int) sizeof(int64_t) + reservedLength + markerLength); m_salt.m_int = ReRandomizer::nearTrueRandom(); m_contentRandom.reset(); m_contentRandom.modifySeed(m_salt.m_int); @@ -1223,12 +1223,14 @@ void ReByteScrambler::initHeader(int reservedLength, int markerLength, m_buffer, markerLength); TRACE1("marker: %s\n", m_buffer.constData()); } + TRACE1("header-2 %s\n", hexBytes(m_header.constData(), 8).constData()); char* trg; if (info.length() > 0){ int offset = sizeof(int64_t) + reservedLength + markerLength; trg = reinterpret_cast(m_header.data() + offset); memcpy(trg, info, min(m_header.length() - offset, info.length())); } + TRACE1("header-3 %s\n", hexBytes(m_header.constData(), 8).constData()); if (encryptedFrom < m_header.length()){ randomReset(); uint8_t* start = reinterpret_cast(m_header.data() + encryptedFrom); diff --git a/base/ReRandomizer.hpp b/base/ReRandomizer.hpp index 7fd75d1..c56039c 100644 --- a/base/ReRandomizer.hpp +++ b/base/ReRandomizer.hpp @@ -100,7 +100,7 @@ public: * @param start first index to encode/decode. The data lying in front * will be copied */ - inline void codec(QByteArray& target, const QByteArray source, int start = 0){ + inline void codec(QByteArray& target, const QByteArray& source, int start = 0){ target.resize(source.length()); if (start > 0) memcpy((uint8_t*)target.data(), (const uint8_t*) source.constData(), diff --git a/cunit/allTests.cpp b/cunit/allTests.cpp index 69a4d10..d126387 100644 --- a/cunit/allTests.cpp +++ b/cunit/allTests.cpp @@ -97,8 +97,8 @@ static void testOs() { testReFileSystem(); } void allTests() { - testBase(); testOs(); + testBase(); testGui(); if (s_allTest) { testBase(); diff --git a/cunit/cuReProcess.cpp b/cunit/cuReProcess.cpp new file mode 100644 index 0000000..8e3b2a2 --- /dev/null +++ b/cunit/cuReProcess.cpp @@ -0,0 +1,44 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. +*/ +/** @file + * @brief Unit test of the byte and C string storage. + */ + +#include "base/rebase.hpp" + +class TestReProcess: public ReTest { +public: + TestReProcess() : + ReTest("ReProcess") { + doIt(); + } +private: + void testExecAndRead() { +#if defined __linux__ + QStringList args; + args.append("-u"); + QByteArray id = ReProcess::executeAndRead(QString("/usr/bin/id"), args); + checkF(id.isEmpty()); + +#else +#error "missing test" +#endif + } + +public: + virtual void run() { + testExecAndRead(); + } +}; +void testReProcess() { + TestReProcess test; +} + + + + diff --git a/cunit/cuReRandomizer.cpp b/cunit/cuReRandomizer.cpp index e8ab901..263c896 100644 --- a/cunit/cuReRandomizer.cpp +++ b/cunit/cuReRandomizer.cpp @@ -203,11 +203,11 @@ public: } src = "12345678abcdefghijklmn"; QByteArray trg; - scrambler.contentRandom(true).codec(src, trg, 8); + scrambler.contentRandom(true).codec(trg, src, 8); checkEqu("12345678", trg.mid(0, 8)); src = "1234XY78abcdefghijklmn"; QByteArray trg2; - scrambler.contentRandom(true).codec(src, trg2, 8); + scrambler.contentRandom(true).codec(trg2, src, 8); checkEqu("1234XY78", trg2.mid(0, 8)); checkEqu(trg.mid(8), trg2.mid(8)); }