GNUnet  0.11.x
Data Structures | Functions | Variables
reclaim_credential.c File Reference

helper library to manage identity attribute credentials More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_reclaim_plugin.h"
#include "reclaim_credential.h"
Include dependency graph for reclaim_credential.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 

Functions

static void add_plugin (void *cls, const char *library_name, void *lib_ret)
 Add a plugin. More...
 
static void init ()
 Load plugins. More...
 
uint32_t GNUNET_RECLAIM_credential_typename_to_number (const char *typename)
 Convert an credential type name to the corresponding number. More...
 
const char * GNUNET_RECLAIM_credential_number_to_typename (uint32_t type)
 Convert an credential type number to the corresponding credential type string. More...
 
int GNUNET_RECLAIM_credential_string_to_value (uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of a 'claim' of an credential to the binary representation. More...
 
char * GNUNET_RECLAIM_credential_value_to_string (uint32_t type, const void *data, size_t data_size)
 Convert the 'claim' of an credential to a string. More...
 
struct GNUNET_RECLAIM_CredentialGNUNET_RECLAIM_credential_new (const char *attr_name, uint32_t type, const void *data, size_t data_size)
 Create a new credential. More...
 
size_t GNUNET_RECLAIM_credential_list_serialize_get_size (const struct GNUNET_RECLAIM_CredentialList *credentials)
 Get required size for serialization buffer. More...
 
size_t GNUNET_RECLAIM_credential_list_serialize (const struct GNUNET_RECLAIM_CredentialList *credentials, char *result)
 Serialize an attribute list. More...
 
struct GNUNET_RECLAIM_CredentialListGNUNET_RECLAIM_credential_list_deserialize (const char *data, size_t data_size)
 Deserialize an credential list. More...
 
struct GNUNET_RECLAIM_CredentialListGNUNET_RECLAIM_credential_list_dup (const struct GNUNET_RECLAIM_CredentialList *al)
 Make a (deep) copy of the credential list. More...
 
void GNUNET_RECLAIM_credential_list_destroy (struct GNUNET_RECLAIM_CredentialList *al)
 Destroy credential list. More...
 
size_t GNUNET_RECLAIM_credential_serialize_get_size (const struct GNUNET_RECLAIM_Credential *credential)
 Get required size for serialization buffer. More...
 
size_t GNUNET_RECLAIM_credential_serialize (const struct GNUNET_RECLAIM_Credential *credential, char *result)
 Serialize an credential. More...
 
struct GNUNET_RECLAIM_CredentialGNUNET_RECLAIM_credential_deserialize (const char *data, size_t data_size)
 Deserialize an credential. More...
 
struct GNUNET_RECLAIM_AttributeListGNUNET_RECLAIM_credential_get_attributes (const struct GNUNET_RECLAIM_Credential *credential)
 Convert an credential type name to the corresponding number. More...
 
char * GNUNET_RECLAIM_credential_get_issuer (const struct GNUNET_RECLAIM_Credential *credential)
 
int GNUNET_RECLAIM_credential_get_expiration (const struct GNUNET_RECLAIM_Credential *credential, struct GNUNET_TIME_Absolute *exp)
 
uint32_t GNUNET_RECLAIM_presentation_typename_to_number (const char *typename)
 Convert an presentation type name to the corresponding number. More...
 
const char * GNUNET_RECLAIM_presentation_number_to_typename (uint32_t type)
 Convert an presentation type number to the corresponding presentation type string. More...
 
int GNUNET_RECLAIM_presentation_string_to_value (uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of a 'claim' of an presentation to the binary representation. More...
 
char * GNUNET_RECLAIM_presentation_value_to_string (uint32_t type, const void *data, size_t data_size)
 Convert the 'claim' of an presentation to a string. More...
 
struct GNUNET_RECLAIM_PresentationGNUNET_RECLAIM_presentation_new (uint32_t type, const void *data, size_t data_size)
 
size_t GNUNET_RECLAIM_presentation_list_serialize_get_size (const struct GNUNET_RECLAIM_PresentationList *presentations)
 Get required size for serialization buffer. More...
 
size_t GNUNET_RECLAIM_presentation_list_serialize (const struct GNUNET_RECLAIM_PresentationList *presentations, char *result)
 Serialize an attribute list. More...
 
struct GNUNET_RECLAIM_PresentationListGNUNET_RECLAIM_presentation_list_deserialize (const char *data, size_t data_size)
 Deserialize an presentation list. More...
 
struct GNUNET_RECLAIM_PresentationListGNUNET_RECLAIM_presentation_list_dup (const struct GNUNET_RECLAIM_PresentationList *al)
 Make a (deep) copy of the presentation list. More...
 
void GNUNET_RECLAIM_presentation_list_destroy (struct GNUNET_RECLAIM_PresentationList *al)
 Destroy presentation list. More...
 
size_t GNUNET_RECLAIM_presentation_serialize_get_size (const struct GNUNET_RECLAIM_Presentation *presentation)
 Get required size for serialization buffer. More...
 
size_t GNUNET_RECLAIM_presentation_serialize (const struct GNUNET_RECLAIM_Presentation *presentation, char *result)
 Serialize an presentation. More...
 
struct GNUNET_RECLAIM_PresentationGNUNET_RECLAIM_presentation_deserialize (const char *data, size_t data_size)
 Deserialize an presentation. More...
 
struct GNUNET_RECLAIM_AttributeListGNUNET_RECLAIM_presentation_get_attributes (const struct GNUNET_RECLAIM_Presentation *presentation)
 
char * GNUNET_RECLAIM_presentation_get_issuer (const struct GNUNET_RECLAIM_Presentation *presentation)
 
int GNUNET_RECLAIM_presentation_get_expiration (const struct GNUNET_RECLAIM_Presentation *presentation, struct GNUNET_TIME_Absolute *exp)
 
int GNUNET_RECLAIM_credential_get_presentation (const struct GNUNET_RECLAIM_Credential *cred, const struct GNUNET_RECLAIM_AttributeList *attrs, struct GNUNET_RECLAIM_Presentation **pres)
 Create a presentation from a credential and a lift of (selected) attributes in the credential. More...
 

Variables

static struct Plugin ** credential_plugins
 Plugins. More...
 
static unsigned int num_plugins
 Number of plugins. More...
 
static int initialized
 Init canary. More...
 

Detailed Description

helper library to manage identity attribute credentials

Author
Martin Schanzenbach

Definition in file reclaim_credential.c.

Function Documentation

◆ add_plugin()

static void add_plugin ( void *  cls,
const char *  library_name,
void *  lib_ret 
)
static

Add a plugin.

Parameters
clsclosure
library_namename of the API library
lib_retthe plugin API pointer

Definition at line 75 of file reclaim_credential.c.

References Plugin::api, GNUNET_array_append, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_strdup, Plugin::library_name, num_plugins, and plugin.

Referenced by init().

76 {
77  struct GNUNET_RECLAIM_CredentialPluginFunctions *api = lib_ret;
78  struct Plugin *plugin;
79 
81  "Loading credential plugin `%s'\n",
82  library_name);
83  plugin = GNUNET_new (struct Plugin);
84  plugin->api = api;
87 }
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
static struct Plugin ** credential_plugins
Plugins.
static unsigned int num_plugins
Number of plugins.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * library_name
Name of the shared library.
Definition: block.c:42
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
static char * plugin
Solver plugin name as string.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ init()

static void init ( )
static

Load plugins.

Definition at line 94 of file reclaim_credential.c.

References add_plugin(), GNUNET_PLUGIN_load_all(), GNUNET_YES, and initialized.

Referenced by GNUNET_RECLAIM_credential_get_attributes(), GNUNET_RECLAIM_credential_get_expiration(), GNUNET_RECLAIM_credential_get_issuer(), GNUNET_RECLAIM_credential_get_presentation(), GNUNET_RECLAIM_credential_number_to_typename(), GNUNET_RECLAIM_credential_string_to_value(), GNUNET_RECLAIM_credential_typename_to_number(), GNUNET_RECLAIM_credential_value_to_string(), GNUNET_RECLAIM_presentation_get_attributes(), GNUNET_RECLAIM_presentation_get_expiration(), GNUNET_RECLAIM_presentation_get_issuer(), GNUNET_RECLAIM_presentation_number_to_typename(), GNUNET_RECLAIM_presentation_string_to_value(), GNUNET_RECLAIM_presentation_typename_to_number(), and GNUNET_RECLAIM_presentation_value_to_string().

95 {
96  if (GNUNET_YES == initialized)
97  return;
99  GNUNET_PLUGIN_load_all ("libgnunet_plugin_reclaim_credential_",
100  NULL,
101  &add_plugin,
102  NULL);
103 }
static void add_plugin(void *cls, const char *library_name, void *lib_ret)
Add a plugin.
static int initialized
Init canary.
void GNUNET_PLUGIN_load_all(const char *basename, void *arg, GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
Load all compatible plugins with the given base name.
Definition: plugin.c:372
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_RECLAIM_credential_list_dup()

struct GNUNET_RECLAIM_CredentialList* GNUNET_RECLAIM_credential_list_dup ( const struct GNUNET_RECLAIM_CredentialList al)

Make a (deep) copy of the credential list.

Parameters
attrsclaim list to copy
Returns
copied claim list

Definition at line 360 of file reclaim_credential.c.

References GNUNET_RECLAIM_CredentialListEntry::credential, GNUNET_RECLAIM_Credential::data, GNUNET_RECLAIM_Credential::data_size, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_RECLAIM_credential_new(), GNUNET_RECLAIM_Credential::id, GNUNET_RECLAIM_CredentialList::list_head, GNUNET_RECLAIM_CredentialList::list_tail, GNUNET_RECLAIM_Credential::name, GNUNET_RECLAIM_CredentialListEntry::next, result, and GNUNET_RECLAIM_Credential::type.

362 {
364  struct GNUNET_RECLAIM_CredentialListEntry *result_ale;
366 
367  result = GNUNET_new (struct GNUNET_RECLAIM_CredentialList);
368  for (ale = al->list_head; NULL != ale; ale = ale->next)
369  {
370  result_ale = GNUNET_new (struct GNUNET_RECLAIM_CredentialListEntry);
371  GNUNET_assert (NULL != ale->credential);
372  result_ale->credential =
374  ale->credential->type,
375  ale->credential->data,
376  ale->credential->data_size);
377  result_ale->credential->id = ale->credential->id;
379  result->list_tail,
380  result_ale);
381  }
382  return result;
383 }
struct GNUNET_RECLAIM_Identifier id
ID.
uint32_t type
Type/Format of Claim.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_RECLAIM_Credential * credential
The credential.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
size_t data_size
Number of bytes in data.
struct GNUNET_RECLAIM_CredentialListEntry * list_tail
List tail.
struct GNUNET_RECLAIM_CredentialListEntry * next
DLL.
const void * data
Binary value stored as credential value.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int result
Global testing status.
struct GNUNET_RECLAIM_CredentialListEntry * list_head
List head.
const char * name
The name of the credential.
A list of GNUNET_RECLAIM_Credential structures.
struct GNUNET_RECLAIM_Credential * GNUNET_RECLAIM_credential_new(const char *attr_name, uint32_t type, const void *data, size_t data_size)
Create a new credential.
Here is the call graph for this function:

◆ GNUNET_RECLAIM_presentation_typename_to_number()

uint32_t GNUNET_RECLAIM_presentation_typename_to_number ( const char *  typename)

Convert an presentation type name to the corresponding number.

Parameters
typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 580 of file reclaim_credential.c.

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, init(), num_plugins, plugin, and ret.

581 {
582  unsigned int i;
583  struct Plugin *plugin;
584  uint32_t ret;
585  init ();
586  for (i = 0; i < num_plugins; i++)
587  {
588  plugin = credential_plugins[i];
589  if (UINT32_MAX !=
590  (ret = plugin->api->typename_to_number_p (plugin->api->cls,
591  typename)))
592  return ret;
593  }
594  return UINT32_MAX;
595 }
static struct Plugin ** credential_plugins
Plugins.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static unsigned int num_plugins
Number of plugins.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
static void init()
Load plugins.
static char * plugin
Solver plugin name as string.
Handle for a plugin.
Definition: block.c:37
void * cls
Closure for all of the callbacks.
Here is the call graph for this function:

◆ GNUNET_RECLAIM_presentation_list_dup()

struct GNUNET_RECLAIM_PresentationList* GNUNET_RECLAIM_presentation_list_dup ( const struct GNUNET_RECLAIM_PresentationList al)

Make a (deep) copy of the presentation list.

Parameters
attrsclaim list to copy
Returns
copied claim list

Definition at line 810 of file reclaim_credential.c.

References GNUNET_RECLAIM_Presentation::credential_id, GNUNET_RECLAIM_Presentation::data, GNUNET_RECLAIM_Presentation::data_size, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_RECLAIM_presentation_new(), GNUNET_RECLAIM_PresentationList::list_head, GNUNET_RECLAIM_PresentationList::list_tail, GNUNET_RECLAIM_PresentationListEntry::next, GNUNET_RECLAIM_PresentationListEntry::presentation, result, and GNUNET_RECLAIM_Presentation::type.

812 {
814  struct GNUNET_RECLAIM_PresentationListEntry *result_ale;
816 
818  for (ale = al->list_head; NULL != ale; ale = ale->next)
819  {
820  result_ale = GNUNET_new (struct GNUNET_RECLAIM_PresentationListEntry);
821  GNUNET_assert (NULL != ale->presentation);
822  result_ale->presentation =
824  ale->presentation->data,
825  ale->presentation->data_size);
828  result->list_tail,
829  result_ale);
830  }
831  return result;
832 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
uint32_t type
Type/Format of Claim.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_RECLAIM_PresentationListEntry * next
DLL.
struct GNUNET_RECLAIM_PresentationListEntry * list_head
List head.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int result
Global testing status.
struct GNUNET_RECLAIM_Identifier credential_id
The credential id of which this is a presentation.
const void * data
Binary value stored as presentation value.
size_t data_size
Number of bytes in data.
struct GNUNET_RECLAIM_Presentation * presentation
The credential.
A list of GNUNET_RECLAIM_Presentation structures.
struct GNUNET_RECLAIM_Presentation * GNUNET_RECLAIM_presentation_new(uint32_t type, const void *data, size_t data_size)
struct GNUNET_RECLAIM_PresentationListEntry * list_tail
List tail.
Here is the call graph for this function:

Variable Documentation

◆ credential_plugins

struct Plugin** credential_plugins
static

Plugins.

Definition at line 52 of file reclaim_credential.c.

◆ num_plugins

unsigned int num_plugins
static

◆ initialized

int initialized
static

Init canary.

Definition at line 64 of file reclaim_credential.c.

Referenced by init().