]> git.stg.codes - stg.git/blobdiff - tests/test_crypto.cpp
Use `time` for message creation time.
[stg.git] / tests / test_crypto.cpp
index 47dbcbb4361daa0b1341882da7e39f7290433573..8db8ab72dec23093de69525f983f4b564511e07b 100644 (file)
@@ -423,11 +423,48 @@ namespace tut
 
         BLOWFISH_CTX ctx;
         InitContext("pr7Hhen", 7, &ctx);
 
         BLOWFISH_CTX ctx;
         InitContext("pr7Hhen", 7, &ctx);
-        char longTest[] = "abcdefghijklmnopqrstuvwxyz 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-        EncryptString(longTest, longTest, sizeof(longTest), &ctx);
+        std::string source("abcdefghijklmnopqrstuvwxyz 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+        char longTest[source.length() + 8];
+        EncryptString(longTest, source.c_str(), source.length() + 1, &ctx);
         DecryptString(longTest, longTest, sizeof(longTest), &ctx);
 
         DecryptString(longTest, longTest, sizeof(longTest), &ctx);
 
-        ensure("DecryptString(EncryptString(longTest)) == longTest", equalString(longTest, "abcdefghijklmnopqrstuvwxyz 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ", sizeof(longTest)));
+        ensure_equals("DecryptString(EncryptString(longTest)) == longTest", source, std::string(longTest));
+    }
+
+    template<>
+    template<>
+    void testobject::test<8>()
+    {
+        set_test_name("Check old string encryption");
+
+        BLOWFISH_CTX ctx;
+        InitContext("123456", 7, &ctx);
+        const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39,
+                                        0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb,
+                                        0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb,
+                                        0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb};
+        char res[32];
+        DecryptString(res, source, 32, &ctx);
+
+        ensure_equals("DecryptString(...) == 'admin'", std::string(res), "admin");
+    }
+
+    template<>
+    template<>
+    void testobject::test<9>()
+    {
+        set_test_name("Check new string encryption");
+
+        BLOWFISH_CTX ctx;
+        InitContext("123456", 7, &ctx);
+        const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39,
+                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+        char res[32];
+        DecryptString(res, source, 32, &ctx);
+
+        ensure_equals("DecryptString(...) == 'admin'", std::string(res), "admin");
     }
 
 }
     }
 
 }