[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25649 - in gnunet-update/src: gnunet_update tests
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25649 - in gnunet-update/src: gnunet_update tests |
Date: |
Tue, 25 Dec 2012 19:14:26 +0100 |
Author: harsha
Date: 2012-12-25 19:14:26 +0100 (Tue, 25 Dec 2012)
New Revision: 25649
Added:
gnunet-update/src/tests/compatibility.c
Removed:
gnunet-update/src/tests/test_data_to_string.c
Modified:
gnunet-update/src/gnunet_update/util.py
gnunet-update/src/tests/
gnunet-update/src/tests/Makefile.am
gnunet-update/src/tests/test_util.py
Log:
- compatibility test cases
Modified: gnunet-update/src/gnunet_update/util.py
===================================================================
--- gnunet-update/src/gnunet_update/util.py 2012-12-25 17:44:31 UTC (rev
25648)
+++ gnunet-update/src/gnunet_update/util.py 2012-12-25 18:14:26 UTC (rev
25649)
@@ -435,7 +435,7 @@
passphrase: string containing the passphrase to get the AES key and
initialization vector
"""
- passphrase = bytearray (passphrase, 'utf-8');
+ passphrase = bytearray (passphrase);
self.key = bytearray (self.KEY_SIZE)
self.iv = bytearray (self.IV_SIZE)
if (len (passphrase) > self.KEY_SIZE):
Index: gnunet-update/src/tests
===================================================================
--- gnunet-update/src/tests 2012-12-25 17:44:31 UTC (rev 25648)
+++ gnunet-update/src/tests 2012-12-25 18:14:26 UTC (rev 25649)
Property changes on: gnunet-update/src/tests
___________________________________________________________________
Modified: svn:ignore
## -4,4 +4,4 ##
user-home
gen_user_home.sh
.deps
-test_data_to_string
+compatibility_test_*
Modified: gnunet-update/src/tests/Makefile.am
===================================================================
--- gnunet-update/src/tests/Makefile.am 2012-12-25 17:44:31 UTC (rev 25648)
+++ gnunet-update/src/tests/Makefile.am 2012-12-25 18:14:26 UTC (rev 25649)
@@ -6,8 +6,12 @@
gen_user_home
check_PROGRAMS = \
- test_data_to_string
+ compatibility_test_data_to_string \
+ compatibility_test_hash \
+ compatibility_test_hash_to_aes_key \
+ compatibility_test_aes_enc
+
gen_user_home: gen_user_home.sh.in Makefile
$(do_subst) < $(srcdir)/gen_user_home.sh.in > gen_user_home.sh
chmod +x gen_user_home.sh
@@ -96,7 +100,22 @@
rm -rf `find $(distdir)/keys -type d -name .svn`
rm -rf `find $(distdir)/confs -type d -name .svn`
-test_data_to_string_SOURCES = \
- test_data_to_string.c
-test_data_to_string_LDADD = \
+compatibility_test_data_to_string_SOURCES = \
+ compatibility.c
+compatibility_test_data_to_string_LDADD = \
-lgnunetutil
+
+compatibility_test_hash_SOURCES = \
+ compatibility.c
+compatibility_test_hash_LDADD = \
+ -lgnunetutil
+
+compatibility_test_hash_to_aes_key_SOURCES = \
+ compatibility.c
+compatibility_test_hash_to_aes_key_LDADD = \
+ -lgnunetutil
+
+compatibility_test_aes_enc_SOURCES = \
+ compatibility.c
+compatibility_test_aes_enc_LDADD = \
+ -lgnunetutil
\ No newline at end of file
Copied: gnunet-update/src/tests/compatibility.c (from rev 25646,
gnunet-update/src/tests/test_data_to_string.c)
===================================================================
--- gnunet-update/src/tests/compatibility.c (rev 0)
+++ gnunet-update/src/tests/compatibility.c 2012-12-25 18:14:26 UTC (rev
25649)
@@ -0,0 +1,245 @@
+/*
+ This file is part of GNUnet.
+ (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2012 Christian Grothoff
(and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file tests/compatibility.c
+ * @brief program to help check compatibility between gnunet util library and
+ * the util library of gnunet-update
+ * @author Sree Harsha Totakura <address@hidden>
+ */
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
+
+/**
+ * Test data; should be the same in the python test cases
+ */
+static const char *data = "This is some test data";
+
+/**
+ * Pointer to AES encrypted data
+ */
+static void *enc_data;
+
+/**
+ * hash code
+ */
+static struct GNUNET_HashCode hash;
+
+/**
+ * AES key
+ */
+struct GNUNET_CRYPTO_AesSessionKey key;
+
+/**
+ * AES initialization vector
+ */
+struct GNUNET_CRYPTO_AesInitializationVector iv;
+
+
+enum Test
+{
+ /**
+ * hash test
+ */
+ TEST_HASH,
+
+ /**
+ * test data to string functions
+ */
+ TEST_DATA_TO_STRING,
+
+ /**
+ * test hash to AES key
+ */
+ TEST_HASH_TO_AES_KEY,
+
+ /**
+ * test AES encryption
+ */
+ TEST_AES_ENC,
+
+ /**
+ * Marks the end of the tests;
+ */
+ TEST_END
+
+};
+
+
+const char *testname_strings[] = {
+ /**
+ * hash test
+ */
+ "TEST_HASH",
+
+ /**
+ * test data to string functions
+ */
+ "TEST_DATA_TO_STRING",
+
+ /**
+ * test hash to AES key
+ */
+ "TEST_HASH_TO_AES_KEY",
+
+ /**
+ * test AES encryption
+ */
+ "TEST_AES_ENC",
+
+ /**
+ * Marks the end of the strings
+ */
+ NULL
+};
+
+
+static enum Test
+string_to_testname (const char *testname)
+{
+ unsigned int cnt;
+
+ for (cnt = 0; NULL != testname_strings[cnt]; cnt++)
+ {
+ if (0 == strcasecmp (testname_strings[cnt], testname))
+ return (enum Test) cnt;
+ }
+ return TEST_END;
+}
+
+
+/**
+ * Function to print the output of GNUNET_STRINGS_data_to_string() function
+ *
+ * @return 1 for failure; 0 for success;
+ */
+static int
+test_data_to_string ()
+{
+ size_t size;
+ char out[1024];
+ char *c;
+
+ size = strlen (data);
+ c = GNUNET_STRINGS_data_to_string ((const unsigned char *) data,
+ size,
+ out,
+ ((size*8) + (((size*8) % 5) > 0 ? 5 -
+ ((size*8) % 5) : 0)) / 5);
+ if (NULL == c)
+ return 1;
+ PRINTF ("%s", out);
+ return 0;
+}
+
+
+/**
+ * Function hash using GNUNET_CRYPTO_hash()
+ *
+ * @return 1 for failure; 0 for success;
+ */
+static int
+test_hash ()
+{
+ GNUNET_CRYPTO_hash (data, strlen (data), &hash);
+ return 0;
+}
+
+
+/**
+ * Function to generate AES key from hash code using
+ * GNUNET_CRYPTO_hash_to_aes_key()
+ *
+ * @return 1 for failure; 0 for success;
+ */
+static int
+test_hash_to_aes_key ()
+{
+ test_hash ();
+ GNUNET_CRYPTO_hash_to_aes_key (&hash, &key, &iv);
+ return 0;
+}
+
+
+/**
+ * Function to do AES encryption using GNUNET_CRYPTO_aes_crypto()
+ *
+ * @return 1 for failure; 0 for success;
+ */
+static int
+test_aes_enc ()
+{
+ ssize_t out;
+
+ test_hash ();
+ test_hash_to_aes_key ();
+ enc_data = GNUNET_malloc (strlen (data));
+ out = GNUNET_CRYPTO_aes_encrypt (data, strlen (data), &key, &iv, enc_data);
+ if (out != strlen (data))
+ return 1;
+ return 0;
+}
+
+
+int main (int argc, char *argv[])
+{
+ const char *testname;
+ int ret;
+
+ if (NULL == (testname = strchr (argv[0], (int) '_')))
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ if (strlen (testname) <= 1)
+ return 1;
+ testname++;
+ switch (string_to_testname (testname))
+ {
+ case TEST_DATA_TO_STRING:
+ return test_data_to_string ();
+ case TEST_HASH:
+ if (0 != (ret = test_hash()))
+ return ret;
+ if (1 != fwrite (&hash, sizeof (hash), 1, stdout))
+ return 1;
+ return 0;
+ case TEST_HASH_TO_AES_KEY:
+ if (0 != (ret = test_hash_to_aes_key()))
+ return ret;
+ if (1 != fwrite (key.key, sizeof (key.key), 1, stdout))
+ return 1;
+ if (1 != fwrite (&iv, sizeof (iv), 1 , stdout))
+ return 1;
+ return 0;
+ case TEST_AES_ENC:
+ if (0 != test_aes_enc ())
+ {
+ GNUNET_free (enc_data);
+ return 1;
+ }
+ if (strlen(data) != fwrite (enc_data, 1, strlen(data), stdout))
+ return 1;
+ return 0;
+ default:
+ return 2;
+ }
+}
Deleted: gnunet-update/src/tests/test_data_to_string.c
===================================================================
--- gnunet-update/src/tests/test_data_to_string.c 2012-12-25 17:44:31 UTC
(rev 25648)
+++ gnunet-update/src/tests/test_data_to_string.c 2012-12-25 18:14:26 UTC
(rev 25649)
@@ -1,22 +0,0 @@
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_util_lib.h>
-
-static const char *data = "This is some test data";
-
-int main (int argc, char *argv)
-{
- size_t size;
- char out[1024];
- char *c;
-
- size = strlen (data);
- c = GNUNET_STRINGS_data_to_string ((const unsigned char *) data,
- size,
- out,
- ((size*8) + (((size*8) % 5) > 0 ? 5 -
- ((size*8) % 5) : 0)) / 5);
- if (NULL == c)
- return 1;
- PRINTF ("%s", out);
- return 0;
-}
Modified: gnunet-update/src/tests/test_util.py
===================================================================
--- gnunet-update/src/tests/test_util.py 2012-12-25 17:44:31 UTC (rev
25648)
+++ gnunet-update/src/tests/test_util.py 2012-12-25 18:14:26 UTC (rev
25649)
@@ -29,6 +29,7 @@
import gpgme
import shutil
import subprocess
+from hashlib import sha512
import __init__
import gnunet_update.util as util
@@ -77,6 +78,9 @@
O0wunfLFgERgNFIKzwgeLYyV1sRT/miQUPtwKpjq2FYU0MgQnrANWXQ6ZQGjd88IxIBywEZmY09Y
LeTvMvFX1Yuu0mjEdz7zYeI8kR+GsR/eH/5cb2HcVG3X5al0t6KutRB9aWumPoKZUCY/I/69DN+Q
"""
+
+ data = "This is some test data"
+
def test_parse_ldd_output(self):
"""Test ldd output parsing."""
expected_output = [
@@ -232,14 +236,42 @@
"""Tests whether our function behaves similar to
GNUNET_STRING_data_to_string() function"""
- proc = subprocess.Popen (["./test_data_to_string"],
+ proc = subprocess.Popen (["./compatibility_test_data_to_string"],
stdout = subprocess.PIPE)
(proc_out, proc_err) = proc.communicate ()
proc.stdout.close()
- data = bytearray("This is some test data", 'utf-8')
+ data = bytearray(self.data, 'utf-8')
out = util.encode_data_to_string (data);
self.assertFalse (out is None)
self.assertEqual (proc_out, out)
+ def test_hash_to_aes_key (self):
+ """Tests whether our function AESKey() behaves similar to
+ GNUNET_CRYPTO_hash_to_aes_key() function when a hashcode is given as
+ passphrase.
+ """
+ proc = subprocess.Popen (["./compatibility_test_hash_to_aes_key"],
+ stdout = subprocess.PIPE)
+ (proc_out, proc_err) = proc.communicate ()
+ proc.stdout.close()
+ hash_obj = sha512()
+ hash_obj.update(self.data)
+ aes_key = util.AESKey(hash_obj.digest())
+ self.assertEqual (aes_key.key + aes_key.iv, proc_out)
+
+ def test_aes_enc (self):
+ """Tests AES encryption."""
+ proc = subprocess.Popen (["./compatibility_test_aes_enc"],
+ stdout = subprocess.PIPE)
+ (proc_out, proc_err) = proc.communicate ()
+ proc.stdout.close()
+ hash_obj = sha512()
+ hash_obj.update(self.data)
+ aes_key = util.AESKey(hash_obj.digest())
+ enc_data = util.aes_encrypt (aes_key, self.data)
+ self.assertEqual (len(enc_data), len(proc_out))
+ self.assertEqual (enc_data, proc_out)
+
+
if __name__ == '__main__':
unittest.main()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25649 - in gnunet-update/src: gnunet_update tests,
gnunet <=