static int element_set_print( octet_t *oct, element_t *ep) { int i; varr_t *va = ep->e.set; element_t *vep; if (!ep) return 1; if (octcat( oct, "(1:*3:set", 9 ) != SPOCP_SUCCESS) return 0; if (va) { for( i = 0 ; i < (int)va->n ; i++ ) { vep = ( element_t * ) va->arr[i]; if (element_print(oct, vep) == 0) return 0; } } if (octcat( oct, ")", 1 ) != SPOCP_SUCCESS) return 0; return 1; }
static void element_set_reduce( element_t *ep ) { varr_t *va; size_t i; element_t *te; #ifdef XYDEBUG octet_t *op; char *tmp; op = oct_new( 512, NULL); element_print( op, ep ); tmp = oct2strdup( op, 0 ); traceLog(LOG_DEBUG,"Reducing: [%s]", tmp ); Free( tmp ); #endif varr_rm_dup( ep->e.set, P_element_cmp, P_element_free ); #ifdef XYDEBUG op->len = 0; element_print( op, ep ); tmp = oct2strdup( op, 0 ); traceLog(LOG_DEBUG, "1:st Reduction to [%s]", tmp); Free(tmp); #endif va = ep->e.set; if( va->n > 1 ) { for( i = 0; i < va->n; i++) { if( va->arr[i] == 0 ) continue; te = (element_t *) va->arr[i]; va->arr[i] = element_reduce(te); } } #ifdef XYDEBUG op->len = 0; element_print( op, ep ); tmp = oct2strdup( op, 0 ); traceLog(LOG_DEBUG, "2:nd Reduction to [%s]", tmp); Free(tmp); oct_free( op ); #endif }
void element_print(scew_element const* element, FILE* out, unsigned int indent) { unsigned int closed = 0; XML_Char const* contents; scew_element* child = NULL; scew_attribute* attribute = NULL; if (element == NULL) { return; } indent_print(out, indent); scew_fprintf(out, _XT("<%s"), scew_element_name(element)); attribute = NULL; while ((attribute = scew_attribute_next(element, attribute)) != NULL) { attribute_print(attribute, out); } contents = scew_element_contents(element); if ((contents == NULL) && (element->child == NULL) && (element->parent != NULL)) { scew_fprintf(out, _XT("/>\n")); closed = 1; } else { scew_fprintf(out, _XT(">")); if (contents == NULL) { scew_fprintf(out, _XT("\n")); } } child = NULL; while ((child = scew_element_next(element, child)) != NULL) { element_print(child, out, indent + 1); } if (contents != NULL) { scew_fprintf(out, _XT("%s"), contents); } else if (!closed) { indent_print(out, indent); } if (!closed) { scew_fprintf(out, _XT("</%s>\n"), scew_element_name(element)); } }
int main(void) { EC_PAIRING p; EC_POINT a, b, c; Element d; pairing_init(p, "ECBN254"); point_init(a, p->g1); point_init(b, p->g2); point_init(c, p->g1); element_init(d, p->g3); point_set_str(a, "[" "0000000000000000000000000000000000000000000000000000000000000001," "0D45589B158FAAF6AB0E4AD38D998E9982E7FF63964EE1460342A592677CCCB0" "]" ); point_set_str(b, "[" "19850140BC38957238BDEB56EC7B97FE30A6A65D15C4BA07CEF54DB5026C7210 " "1DEB7F4B6C1AEFAEBD0EB750B841BD8ABF916EB750FDF7291F99DFD290C28CE0," "14C164D6D18CBC7F64559076E00789C75FF001D1BE0968D210C19FB0D3AD649A " "059A2ABA101B7A3C1FA3CAF4DF6B38F2CB4976287488E33F526FA7E8C5441B4B" "]" ); pairing_map(d, a, b, p); point_print("a", a); point_print("b", b); element_print("d", d); char msg[] = "abc"; point_map_to_point(c, msg, sizeof(msg), 80); point_print("c", c); point_clear(a); point_clear(b); point_clear(c); element_clear(d); pairing_clear(p); return 0; }
char * element2str( element_t *e ) { octet_t *o; char *tmp; o = oct_new( 512, NULL); element_print( o, e ); tmp = oct2strdup(o, 0); oct_free(o); return tmp; }
static int element_list_print( octet_t *oct, element_t *ep) { if (!ep) return 1; if (octcat( oct, "(", 1 ) != SPOCP_SUCCESS) return 0; for( ep = ep->e.list->head; ep ; ep = ep->next ) if (element_print(oct, ep) == 0) return 0; if (octcat( oct, ")", 1 ) != SPOCP_SUCCESS) return 0; return 1; }
void tree_print(scew_tree const* tree, FILE* out) { static XML_Char const* version = _XT("1.0"); #ifdef XML_UNICODE_WCHAR_T static XML_Char const* encoding = _XT("UTF-16"); #else static XML_Char const* encoding = _XT("UTF-8"); #endif /* XML_UNICODE_WCHAR_T */ scew_fprintf( out, _XT("<?xml version=\"%s\" encoding=\"%s\" standalone=\"%s\"?>\n\n"), (tree->version == NULL ? version : tree->version), (tree->encoding == NULL ? encoding : tree->encoding), (tree->standalone > 0 ? _XT("yes") : _XT("no"))); element_print(tree->root, out, 0); }