test_regex_iterate_api.c
test_regex_iterate_api_LDADD = -lm \
$(top_builddir)/src/regex/libgnunetregex_internal.a \
- $(top_builddir)/src/dht/libgnunetdht.la \
$(top_builddir)/src/regex/libgnunetregexblock.la \
+ $(top_builddir)/src/dht/libgnunetdht.la \
$(top_builddir)/src/util/libgnunetutil.la
test_regex_proofs_SOURCES = \
#define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__)
+
+/**
+ * Check if the given 'proof' matches the given 'key'.
+ *
+ * @param proof partial regex of a state
+ * @param proof_len number of bytes in 'proof'
+ * @param key hash of a state.
+ *
+ * @return GNUNET_OK if the proof is valid for the given key.
+ */
+int
+REGEX_INTERNAL_check_proof (const char *proof,
+ size_t proof_len,
+ const struct GNUNET_HashCode *key)
+{
+ struct GNUNET_HashCode key_check;
+
+ if ( (NULL == proof) || (NULL == key))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n");
+ return GNUNET_NO;
+ }
+
+ GNUNET_CRYPTO_hash (proof, proof_len, &key_check);
+ return (0 ==
+ GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO;
+}
+
+
/**
* Struct to keep track of the xquery while iterating all the edges in a block.
*/
{
struct CheckEdgeContext ctx;
int res;
+ uint32_t len;
- // FIXME: fails to check the proof!
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking block with xquery `%s'\n",
NULL != xquery ? xquery : "NULL");
+ len = ntohl (block->n_proof);
+ if (size < sizeof (struct RegexBlock) + len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK != REGEX_INTERNAL_check_proof ((const char *) &block[1], len, &block->key))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if ( (GNUNET_YES == ntohl (block->accepting)) &&
( (NULL == xquery) || ('\0' == xquery[0]) ) )
return GNUNET_OK;
};
+/**
+ * Check if the given 'proof' matches the given 'key'.
+ *
+ * @param proof partial regex of a state
+ * @param proof_len number of bytes in 'proof'
+ * @param key hash of a state.
+ *
+ * @return GNUNET_OK if the proof is valid for the given key.
+ */
+int
+REGEX_INTERNAL_check_proof (const char *proof,
+ size_t proof_len,
+ const struct GNUNET_HashCode *key);
+
+
/**
* Check if the regex block is well formed, including all edges.
*
*/
int
REGEX_BLOCK_check (const struct RegexBlock *block,
- size_t size,
- const char *xquery);
+ size_t size,
+ const char *xquery);
/* FIXME: might want to use 'struct REGEX_BLOCK_Edge' here instead of 3 arguments! */
* @return GNUNET_YES if should keep iterating, GNUNET_NO otherwise.
*/
typedef int (*REGEX_INTERNAL_EgdeIterator)(void *cls,
- const char *token,
- size_t len,
- const struct GNUNET_HashCode *key);
+ const char *token,
+ size_t len,
+ const struct GNUNET_HashCode *key);
/**
}
-/**
- * Check if the given 'proof' matches the given 'key'.
- *
- * @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.
- */
-int
-REGEX_INTERNAL_check_proof (const char *proof, const struct GNUNET_HashCode *key)
-{
- struct GNUNET_HashCode key_check;
-
- if (NULL == proof || NULL == key)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed, was NULL.\n");
- return GNUNET_NO;
- }
-
- GNUNET_CRYPTO_hash (proof, strlen (proof), &key_check);
- return (0 ==
- GNUNET_CRYPTO_hash_cmp (key, &key_check)) ? GNUNET_OK : GNUNET_NO;
-}
-
-
/**
* Recursive function that calls the iterator for each synthetic start state.
*
&((struct RegexBlock *)copy)->key, copy,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)
);
- len = ntohl (block->n_proof);
- {
- char proof[len + 1];
-
- memcpy (proof, &block[1], len);
- proof[len] = '\0';
- if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, key))
- {
- GNUNET_break_op (0);
- return;
- }
- }
len = strlen (info->description);
if (len == ctx->position) // String processed
{
struct GNUNET_HashCode * key);
-/**
- * Check if the given 'proof' matches the given 'key'.
- *
- * @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.
- */
-int
-REGEX_INTERNAL_check_proof (const char *proof,
- const struct GNUNET_HashCode *key);
-
-
/**
* Iterator callback function.
*
* @param cls closure.
* @param key hash for current state.
- * @param proof proof for current state.
+ * @param proof proof for current state
* @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
* @param num_edges number of edges leaving current state.
* @param edges edges leaving current state.
#include <time.h>
#include "platform.h"
#include "regex_internal_lib.h"
+#include "regex_block_lib.h"
#include "regex_internal.h"
/**
static void
-key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
+key_iterator (void *cls, const struct GNUNET_HashCode *key,
+ const char *proof,
int accepting, unsigned int num_edges,
const struct REGEX_BLOCK_Edge *edges)
{
ctx->match_count++;
}
- if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, key))
+ if (GNUNET_OK != REGEX_INTERNAL_check_proof (proof, strlen (proof), key))
{
ctx->error++;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,