]> gitweb.hamatoma.de Git - reqt/commitdiff
cuRandomizer works
authorhama <hama@siduction.net>
Wed, 18 Nov 2015 22:05:11 +0000 (23:05 +0100)
committerhama <hama@siduction.net>
Wed, 18 Nov 2015 22:05:11 +0000 (23:05 +0100)
base/ReRandomizer.cpp
base/ReRandomizer.hpp
cunit/allTests.cpp
cunit/cuReProcess.cpp [new file with mode: 0644]
cunit/cuReRandomizer.cpp

index 8ef7b7a0aa344c1cec20486648f92125b28cc6d8..2bf9595e5a97dc5b3d458e808fbf3691cf8950e5 100644 (file)
@@ -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<const uint8_t*>(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<char*>(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<uint8_t*>(m_header.data() + encryptedFrom);
index 7fd75d113db65e8166b9a2f8e8146ae23cd5e699..c56039ca9f712082b5b7812886fdb6815058ffb0 100644 (file)
@@ -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(),
index 69a4d1014c6f520458cc9934a49645cc60620547..d12638729790ea3f3354ba23c8273dce1dd5fc97 100644 (file)
@@ -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 (file)
index 0000000..8e3b2a2
--- /dev/null
@@ -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;
+}
+
+
+
+
index e8ab901e2ab1492b06e6a0231c7a89eaad24f928..263c89607b3b5e3d1b2c537fc26997f0436cac05 100644 (file)
@@ -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));
        }