/**
* 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'.
* @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,
* 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.
*/
/**
* 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'.
* @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;
/**
* 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;
}
const struct GNUNET_REGEX_Edge *edges)
{
unsigned int i;
+ int *error = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating... (accepting: %i)\n",
accepting);
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);
}
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;
}