gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22482 - in gnunet/src: include regex


From: gnunet
Subject: [GNUnet-SVN] r22482 - in gnunet/src: include regex
Date: Wed, 4 Jul 2012 17:46:47 +0200

Author: szengel
Date: 2012-07-04 17:46:47 +0200 (Wed, 04 Jul 2012)
New Revision: 22482

Modified:
   gnunet/src/include/gnunet_regex_lib.h
   gnunet/src/regex/regex.c
   gnunet/src/regex/test_regex_iterate_api.c
Log:
regex: actually checking the proof, fixes


Modified: gnunet/src/include/gnunet_regex_lib.h
===================================================================
--- gnunet/src/include/gnunet_regex_lib.h       2012-07-04 15:44:26 UTC (rev 
22481)
+++ gnunet/src/include/gnunet_regex_lib.h       2012-07-04 15:46:47 UTC (rev 
22482)
@@ -119,7 +119,7 @@
 
 /**
  * Get the first key for the given 'input_string'. This hashes
- * the first x bits of the 'input_strings'.
+ * the first x bits of the 'input_string'.
  *
  * @param input_string string.
  * @param string_len length of the 'input_string'.
@@ -128,18 +128,18 @@
  * @return number of bits of 'input_string' that have been consumed
  *         to construct the key
  */
-unsigned int /* FIXME: size_t */
-GNUNET_REGEX_get_first_key (const char *input_string, /* FIXME: size_t */ 
unsigned int string_len,
+size_t
+GNUNET_REGEX_get_first_key (const char *input_string, size_t string_len,
                             struct GNUNET_HashCode * key);
 
 
 /**
  * Check if the given 'proof' matches the given 'key'.
  *
- * @param proof partial regex
- * @param key hash
+ * @param proof partial regex of a state.
+ * @param key hash of a state.
  *
- * @return GNUNET_OK if the proof is valid for the given key
+ * @return GNUNET_OK if the proof is valid for the given key.
  */
 int
 GNUNET_REGEX_check_proof (const char *proof,

Modified: gnunet/src/regex/regex.c
===================================================================
--- gnunet/src/regex/regex.c    2012-07-04 15:44:26 UTC (rev 22481)
+++ gnunet/src/regex/regex.c    2012-07-04 15:46:47 UTC (rev 22482)
@@ -287,7 +287,8 @@
  * Get all edges leaving state 's'.
  *
  * @param s state.
- * @param edges all edges leaving 's'.
+ * @param edges all edges leaving 's', expected to be allocated and have enough
+ *        space for s->transitions_count elements.
  *
  * @return number of edges.
  */
@@ -2471,7 +2472,7 @@
 
 /**
  * Get the first key for the given 'input_string'. This hashes the first x bits
- * of the 'input_strings'.
+ * of the 'input_string'.
  *
  * @param input_string string.
  * @param string_len length of the 'input_string'.
@@ -2480,9 +2481,9 @@
  * @return number of bits of 'input_string' that have been consumed
  *         to construct the key
  */
-unsigned int
-GNUNET_REGEX_get_first_key (const char *input_string, unsigned int string_len,
-                            struct GNUNET_HashCode *key)
+size_t
+GNUNET_REGEX_get_first_key (const char *input_string, size_t string_len,
+                            struct GNUNET_HashCode * key)
 {
   unsigned int size;
 
@@ -2503,15 +2504,17 @@
 /**
  * Check if the given 'proof' matches the given 'key'.
  *
- * @param proof partial regex
- * @param key hash
+ * @param proof partial regex of a state.
+ * @param key hash of a state.
  *
- * @return GNUNET_OK if the proof is valid for the given key
+ * @return GNUNET_OK if the proof is valid for the given key.
  */
 int
 GNUNET_REGEX_check_proof (const char *proof, const struct GNUNET_HashCode *key)
 {
-  return GNUNET_OK;
+  struct GNUNET_HashCode key_check;
+  GNUNET_CRYPTO_hash (proof, strlen (proof), &key_check);
+  return (0 == GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : 
GNUNET_NO;
 }
 
 

Modified: gnunet/src/regex/test_regex_iterate_api.c
===================================================================
--- gnunet/src/regex/test_regex_iterate_api.c   2012-07-04 15:44:26 UTC (rev 
22481)
+++ gnunet/src/regex/test_regex_iterate_api.c   2012-07-04 15:46:47 UTC (rev 
22482)
@@ -33,6 +33,7 @@
               const struct GNUNET_REGEX_Edge *edges)
 {
   unsigned int i;
+  int *error = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating... (accepting: %i)\n",
               accepting);
@@ -41,6 +42,8 @@
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Edge %i: %s\n", i, edges[i].label);
   }
 
+  *error += (GNUNET_OK == GNUNET_REGEX_check_proof (proof, key)) ? 0 : 1;
+
   if (NULL != proof)
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof: %s\n", proof);
 }
@@ -57,44 +60,37 @@
                     NULL);
 
   int error;
-  const char *regex;
+  int i;
   struct GNUNET_REGEX_Automaton *dfa;
 
   error = 0;
-  /* regex = "ab(c|d)+c*(a(b|c)+d)+(bla)+"; */
-  /* regex = "(bla)*"; */
-  /*regex = "b(lab)*la"; */
-  /* regex = "(ab)*"; */
-  regex = "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*";
-  /*regex = "z(abc|def)?xyz"; */
-  /* regex = "1*0(0|1)*"; */
-  /* regex = "a*b*"; */
-  /* regex = "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*"; */
-  /* regex = 
"abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)";
 */
-  /* regex = "abc(1|0)*def"; */
-  /* regex = "ab|ac"; */
-  /* regex = "(ab)(ab)*"; */
-  /* regex = "ab|cd|ef|gh"; */
-  /* regex = "a|b|c|d|e|f|g"; */
-  /* regex = "(ab)|(ac)"; */
-  /* regex = "a(b|c)"; */
-  /* regex = "a*a"; */
-  /* regex = "ab?(abcd)?"; */
-  /* regex = "(ab)+"; */
-  /* regex = "(ab|cs|df|sdf)*"; */
-  /* regex = "(ab|cd)*"; */
-  /* regex = "(cd|ab)*"; */
-  /* regex = "(ab|c)+"; */
-  /* regex = "(a|bc)+"; */
-  /* regex = "(ab|c)(ab|c)*"; */
-  /* regex = "(a|bc)(a|bc)*"; */
-  /* regex = "(ac|b)*"; */
-  /* regex = "a|aa*a"; */
 
-  dfa = GNUNET_REGEX_construct_dfa (regex, strlen (regex));
-  GNUNET_REGEX_automaton_save_graph (dfa, "dfa.dot");
-  GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, NULL);
-  GNUNET_REGEX_automaton_destroy (dfa);
+  const char *regex[17] = {
+    "ab(c|d)+c*(a(b|c)+d)+(bla)+",
+    "(bla)*",
+    "b(lab)*la",
+    "(ab)*",
+    "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*",
+    "z(abc|def)?xyz",
+    "1*0(0|1)*",
+    "a*b*",
+    "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*",
+    
"abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)",
+    "abc(1|0)*def",
+    "ab|ac",
+    "(ab)(ab)*",
+    "ab|cd|ef|gh",
+    "a|b|c|d|e|f|g",
+    "(ab)|(ac)",
+    "a(b|c)"
+  };
 
+  for (i = 0; i < 17; i++)
+  {
+    dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
+    GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &error);
+    GNUNET_REGEX_automaton_destroy (dfa);
+  }
+  
   return error;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]