diff options
author | Maximilian Szengel <gnunet@maxsz.de> | 2012-07-04 15:46:47 +0000 |
---|---|---|
committer | Maximilian Szengel <gnunet@maxsz.de> | 2012-07-04 15:46:47 +0000 |
commit | c6c6d70ac090acbc8b9c75f19af249030e2a751b (patch) | |
tree | 960400a3d5fd9d11ee320111caddba8a0a192d5a /src/regex | |
parent | 9534e25a16b3f9d2574ffb969ff295f77f74c351 (diff) | |
download | gnunet-c6c6d70ac090acbc8b9c75f19af249030e2a751b.tar.gz gnunet-c6c6d70ac090acbc8b9c75f19af249030e2a751b.zip |
regex: actually checking the proof, fixes
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/regex.c | 21 | ||||
-rw-r--r-- | src/regex/test_regex_iterate_api.c | 64 |
2 files changed, 42 insertions, 43 deletions
diff --git a/src/regex/regex.c b/src/regex/regex.c index a1619ef28..1290569cc 100644 --- a/src/regex/regex.c +++ b/src/regex/regex.c | |||
@@ -287,7 +287,8 @@ state_compare (const void *a, const void *b) | |||
287 | * Get all edges leaving state 's'. | 287 | * Get all edges leaving state 's'. |
288 | * | 288 | * |
289 | * @param s state. | 289 | * @param s state. |
290 | * @param edges all edges leaving 's'. | 290 | * @param edges all edges leaving 's', expected to be allocated and have enough |
291 | * space for s->transitions_count elements. | ||
291 | * | 292 | * |
292 | * @return number of edges. | 293 | * @return number of edges. |
293 | */ | 294 | */ |
@@ -2471,7 +2472,7 @@ GNUNET_REGEX_get_canonical_regex (struct GNUNET_REGEX_Automaton *a) | |||
2471 | 2472 | ||
2472 | /** | 2473 | /** |
2473 | * Get the first key for the given 'input_string'. This hashes the first x bits | 2474 | * Get the first key for the given 'input_string'. This hashes the first x bits |
2474 | * of the 'input_strings'. | 2475 | * of the 'input_string'. |
2475 | * | 2476 | * |
2476 | * @param input_string string. | 2477 | * @param input_string string. |
2477 | * @param string_len length of the 'input_string'. | 2478 | * @param string_len length of the 'input_string'. |
@@ -2480,9 +2481,9 @@ GNUNET_REGEX_get_canonical_regex (struct GNUNET_REGEX_Automaton *a) | |||
2480 | * @return number of bits of 'input_string' that have been consumed | 2481 | * @return number of bits of 'input_string' that have been consumed |
2481 | * to construct the key | 2482 | * to construct the key |
2482 | */ | 2483 | */ |
2483 | unsigned int | 2484 | size_t |
2484 | GNUNET_REGEX_get_first_key (const char *input_string, unsigned int string_len, | 2485 | GNUNET_REGEX_get_first_key (const char *input_string, size_t string_len, |
2485 | struct GNUNET_HashCode *key) | 2486 | struct GNUNET_HashCode * key) |
2486 | { | 2487 | { |
2487 | unsigned int size; | 2488 | unsigned int size; |
2488 | 2489 | ||
@@ -2503,15 +2504,17 @@ GNUNET_REGEX_get_first_key (const char *input_string, unsigned int string_len, | |||
2503 | /** | 2504 | /** |
2504 | * Check if the given 'proof' matches the given 'key'. | 2505 | * Check if the given 'proof' matches the given 'key'. |
2505 | * | 2506 | * |
2506 | * @param proof partial regex | 2507 | * @param proof partial regex of a state. |
2507 | * @param key hash | 2508 | * @param key hash of a state. |
2508 | * | 2509 | * |
2509 | * @return GNUNET_OK if the proof is valid for the given key | 2510 | * @return GNUNET_OK if the proof is valid for the given key. |
2510 | */ | 2511 | */ |
2511 | int | 2512 | int |
2512 | GNUNET_REGEX_check_proof (const char *proof, const struct GNUNET_HashCode *key) | 2513 | GNUNET_REGEX_check_proof (const char *proof, const struct GNUNET_HashCode *key) |
2513 | { | 2514 | { |
2514 | return GNUNET_OK; | 2515 | struct GNUNET_HashCode key_check; |
2516 | GNUNET_CRYPTO_hash (proof, strlen (proof), &key_check); | ||
2517 | return (0 == GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO; | ||
2515 | } | 2518 | } |
2516 | 2519 | ||
2517 | 2520 | ||
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c index 9f4f2280e..246ae7767 100644 --- a/src/regex/test_regex_iterate_api.c +++ b/src/regex/test_regex_iterate_api.c | |||
@@ -33,6 +33,7 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, | |||
33 | const struct GNUNET_REGEX_Edge *edges) | 33 | const struct GNUNET_REGEX_Edge *edges) |
34 | { | 34 | { |
35 | unsigned int i; | 35 | unsigned int i; |
36 | int *error = cls; | ||
36 | 37 | ||
37 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating... (accepting: %i)\n", | 38 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating... (accepting: %i)\n", |
38 | accepting); | 39 | accepting); |
@@ -41,6 +42,8 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, | |||
41 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Edge %i: %s\n", i, edges[i].label); | 42 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Edge %i: %s\n", i, edges[i].label); |
42 | } | 43 | } |
43 | 44 | ||
45 | *error += (GNUNET_OK == GNUNET_REGEX_check_proof (proof, key)) ? 0 : 1; | ||
46 | |||
44 | if (NULL != proof) | 47 | if (NULL != proof) |
45 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof: %s\n", proof); | 48 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof: %s\n", proof); |
46 | } | 49 | } |
@@ -57,44 +60,37 @@ main (int argc, char *argv[]) | |||
57 | NULL); | 60 | NULL); |
58 | 61 | ||
59 | int error; | 62 | int error; |
60 | const char *regex; | 63 | int i; |
61 | struct GNUNET_REGEX_Automaton *dfa; | 64 | struct GNUNET_REGEX_Automaton *dfa; |
62 | 65 | ||
63 | error = 0; | 66 | error = 0; |
64 | /* regex = "ab(c|d)+c*(a(b|c)+d)+(bla)+"; */ | ||
65 | /* regex = "(bla)*"; */ | ||
66 | /*regex = "b(lab)*la"; */ | ||
67 | /* regex = "(ab)*"; */ | ||
68 | regex = "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*"; | ||
69 | /*regex = "z(abc|def)?xyz"; */ | ||
70 | /* regex = "1*0(0|1)*"; */ | ||
71 | /* regex = "a*b*"; */ | ||
72 | /* regex = "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*"; */ | ||
73 | /* 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)"; */ | ||
74 | /* regex = "abc(1|0)*def"; */ | ||
75 | /* regex = "ab|ac"; */ | ||
76 | /* regex = "(ab)(ab)*"; */ | ||
77 | /* regex = "ab|cd|ef|gh"; */ | ||
78 | /* regex = "a|b|c|d|e|f|g"; */ | ||
79 | /* regex = "(ab)|(ac)"; */ | ||
80 | /* regex = "a(b|c)"; */ | ||
81 | /* regex = "a*a"; */ | ||
82 | /* regex = "ab?(abcd)?"; */ | ||
83 | /* regex = "(ab)+"; */ | ||
84 | /* regex = "(ab|cs|df|sdf)*"; */ | ||
85 | /* regex = "(ab|cd)*"; */ | ||
86 | /* regex = "(cd|ab)*"; */ | ||
87 | /* regex = "(ab|c)+"; */ | ||
88 | /* regex = "(a|bc)+"; */ | ||
89 | /* regex = "(ab|c)(ab|c)*"; */ | ||
90 | /* regex = "(a|bc)(a|bc)*"; */ | ||
91 | /* regex = "(ac|b)*"; */ | ||
92 | /* regex = "a|aa*a"; */ | ||
93 | 67 | ||
94 | dfa = GNUNET_REGEX_construct_dfa (regex, strlen (regex)); | 68 | const char *regex[17] = { |
95 | GNUNET_REGEX_automaton_save_graph (dfa, "dfa.dot"); | 69 | "ab(c|d)+c*(a(b|c)+d)+(bla)+", |
96 | GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, NULL); | 70 | "(bla)*", |
97 | GNUNET_REGEX_automaton_destroy (dfa); | 71 | "b(lab)*la", |
72 | "(ab)*", | ||
73 | "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*", | ||
74 | "z(abc|def)?xyz", | ||
75 | "1*0(0|1)*", | ||
76 | "a*b*", | ||
77 | "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", | ||
78 | "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)", | ||
79 | "abc(1|0)*def", | ||
80 | "ab|ac", | ||
81 | "(ab)(ab)*", | ||
82 | "ab|cd|ef|gh", | ||
83 | "a|b|c|d|e|f|g", | ||
84 | "(ab)|(ac)", | ||
85 | "a(b|c)" | ||
86 | }; | ||
98 | 87 | ||
88 | for (i = 0; i < 17; i++) | ||
89 | { | ||
90 | dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i])); | ||
91 | GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &error); | ||
92 | GNUNET_REGEX_automaton_destroy (dfa); | ||
93 | } | ||
94 | |||
99 | return error; | 95 | return error; |
100 | } | 96 | } |