Exemple #1
0
static inline void
_co_tree_print_r(co_obj_t *tree, _treenode_t *current, int *count)
{
  CHECK(IS_TREE(tree), "Recursion target is not a tree.");
  if(current == NULL) return;
  char *key = NULL;
  char *value = NULL;
  if(co_node_value(current) != NULL)
  {
    (*count)++;
    co_obj_data(&key, co_node_key(current));
    co_obj_data(&value, co_node_value(current));
    //CHECK(IS_STR(key) && IS_STR(value), "Incorrect types for profile.");
    if(*count < co_tree_length(tree))
    {
      printf(" \"%s\": \"%s\", ", key, value);
    }
    else
    {
      printf(" \"%s\": \"%s\" ", key, value);
    }
  }
  _co_tree_print_r(tree, current->low, count); 
  _co_tree_print_r(tree, current->equal, count); 
  _co_tree_print_r(tree, current->high, count); 
  return; 
error:
  return;
}
Exemple #2
0
int olsrd_mdp_sign(co_obj_t *self, co_obj_t **output, co_obj_t *params) {
  int msg_len = 0, ret = 0, sig_buf_len;
  unsigned char *msg = NULL, *sig_buf = NULL;
  
  /** skipping some error checking for performance reasons */
  
//   CHECK(IS_LIST(params) && co_list_length(params) == 2,"Invalid params");
  
  msg_len = co_obj_data((char**)&msg,co_list_element(params,1));
  sig_buf_len = SIGNATURE_BYTES + msg_len + 1;
  sig_buf = calloc(sig_buf_len,sizeof(unsigned char));
  
  CHECK(serval_create_signature((unsigned char*)_LIST_ELEMENT(params,0),
                     msg,
		     msg_len,
		     sig_buf,
		     sig_buf_len),"Failed to sign OLSRd packet");
  
  CMD_OUTPUT("sig",co_bin8_create((char*)(sig_buf+msg_len),SIGNATURE_BYTES,0));
  
  ret = 1;
error:
  if (sig_buf) free(sig_buf);
  return ret;
}
Exemple #3
0
size_t
co_response_get_bin(co_obj_t *response, char **output, const char *key, const size_t klen) 
{
  co_obj_t *obj = co_response_get(response, key, klen);
  CHECK(obj != NULL, "Response value %s does not exist.", key);
  CHECK(IS_BIN(obj), "Value %s is not a binary.", key);
  return co_obj_data(output, obj);
  error:
  return -1;
}
Exemple #4
0
int
olsrd_mdp_sign(co_obj_t *self, co_obj_t **output, co_obj_t *params)
{
  int ret = 0;
  svl_crypto_ctx *ctx = svl_crypto_ctx_new();
  
  /** skipping some error checking for performance reasons */
  
//   CHECK(IS_LIST(params) && co_list_length(params) == 2, "Invalid params");
  
  ctx->msg_len = co_obj_data((char**)&ctx->msg, co_list_element(params, 1));
  
  memcpy(ctx->sas_private,_LIST_ELEMENT(params, 0),crypto_sign_SECRETKEYBYTES);
  
  CHECK(serval_create_signature(ctx), "Failed to sign OLSRd packet");
  
  CMD_OUTPUT("sig", co_bin8_create((char*)ctx->signature, SIGNATURE_BYTES, 0));
  
  ret = 1;
error:
  svl_crypto_ctx_free(ctx);
  return ret;
}