Change interface for enumerator_create_filter() callback
This avoids the unportable 5 pointer hack, but requires enumerating in the callback.
This commit is contained in:
@@ -819,43 +819,57 @@ static bool entry_match(entry_t *a, entry_t *b)
|
||||
return a->algo == b->algo;
|
||||
}
|
||||
|
||||
/**
|
||||
* check for uniqueness of an entry
|
||||
*/
|
||||
static bool unique_check(linked_list_t *list, entry_t **in, entry_t **out)
|
||||
CALLBACK(unique_check, bool,
|
||||
linked_list_t *list, enumerator_t *orig, va_list args)
|
||||
{
|
||||
if (list->find_first(list, (void*)entry_match, NULL, *in) == SUCCESS)
|
||||
entry_t *entry, **out;
|
||||
|
||||
VA_ARGS_VGET(args, out);
|
||||
|
||||
while (orig->enumerate(orig, &entry))
|
||||
{
|
||||
return FALSE;
|
||||
if (list->find_first(list, (void*)entry_match, NULL, entry) == SUCCESS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*out = entry;
|
||||
list->insert_last(list, entry);
|
||||
return TRUE;
|
||||
}
|
||||
*out = *in;
|
||||
list->insert_last(list, *in);
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* create an enumerator over entry->algo in list with locking and unique check
|
||||
*/
|
||||
static enumerator_t *create_enumerator(private_crypto_factory_t *this,
|
||||
linked_list_t *list, void *filter)
|
||||
linked_list_t *list,
|
||||
bool (*filter)(void*,enumerator_t*,va_list))
|
||||
{
|
||||
this->lock->read_lock(this->lock);
|
||||
return enumerator_create_filter(
|
||||
enumerator_create_filter(
|
||||
list->create_enumerator(list), (void*)unique_check,
|
||||
list->create_enumerator(list), unique_check,
|
||||
linked_list_create(), (void*)list->destroy),
|
||||
filter, this->lock, (void*)this->lock->unlock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool crypter_filter(void *n, entry_t **entry, encryption_algorithm_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
CALLBACK(crypter_filter, bool,
|
||||
void *n, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
entry_t *entry;
|
||||
encryption_algorithm_t *algo;
|
||||
const char **plugin_name;
|
||||
|
||||
VA_ARGS_VGET(args, algo, plugin_name);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*algo = entry->algo;
|
||||
*plugin_name = entry->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_crypter_enumerator, enumerator_t*,
|
||||
@@ -870,15 +884,22 @@ METHOD(crypto_factory_t, create_aead_enumerator, enumerator_t*,
|
||||
return create_enumerator(this, this->aeads, crypter_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool signer_filter(void *n, entry_t **entry, integrity_algorithm_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
CALLBACK(signer_filter, bool,
|
||||
void *n, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
entry_t *entry;
|
||||
integrity_algorithm_t *algo;
|
||||
const char **plugin_name;
|
||||
|
||||
VA_ARGS_VGET(args, algo, plugin_name);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*algo = entry->algo;
|
||||
*plugin_name = entry->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_signer_enumerator, enumerator_t*,
|
||||
@@ -887,15 +908,22 @@ METHOD(crypto_factory_t, create_signer_enumerator, enumerator_t*,
|
||||
return create_enumerator(this, this->signers, signer_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool hasher_filter(void *n, entry_t **entry, hash_algorithm_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
CALLBACK(hasher_filter, bool,
|
||||
void *n, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
entry_t *entry;
|
||||
hash_algorithm_t *algo;
|
||||
const char **plugin_name;
|
||||
|
||||
VA_ARGS_VGET(args, algo, plugin_name);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*algo = entry->algo;
|
||||
*plugin_name = entry->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_hasher_enumerator, enumerator_t*,
|
||||
@@ -904,15 +932,22 @@ METHOD(crypto_factory_t, create_hasher_enumerator, enumerator_t*,
|
||||
return create_enumerator(this, this->hashers, hasher_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool prf_filter(void *n, entry_t **entry, pseudo_random_function_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
CALLBACK(prf_filter, bool,
|
||||
void *n, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
entry_t *entry;
|
||||
pseudo_random_function_t *algo;
|
||||
const char **plugin_name;
|
||||
|
||||
VA_ARGS_VGET(args, algo, plugin_name);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*algo = entry->algo;
|
||||
*plugin_name = entry->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_prf_enumerator, enumerator_t*,
|
||||
@@ -921,15 +956,22 @@ METHOD(crypto_factory_t, create_prf_enumerator, enumerator_t*,
|
||||
return create_enumerator(this, this->prfs, prf_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate algorithm, not entry
|
||||
*/
|
||||
static bool xof_filter(void *n, entry_t **entry, ext_out_function_t *algo,
|
||||
void *i2, const char **plugin_name)
|
||||
CALLBACK(xof_filter, bool,
|
||||
void *n, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*algo = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
entry_t *entry;
|
||||
ext_out_function_t *algo;
|
||||
const char **plugin_name;
|
||||
|
||||
VA_ARGS_VGET(args, algo, plugin_name);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*algo = entry->algo;
|
||||
*plugin_name = entry->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_xof_enumerator, enumerator_t*,
|
||||
@@ -938,15 +980,22 @@ METHOD(crypto_factory_t, create_xof_enumerator, enumerator_t*,
|
||||
return create_enumerator(this, this->xofs, xof_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate group, not entry
|
||||
*/
|
||||
static bool dh_filter(void *n, entry_t **entry, diffie_hellman_group_t *group,
|
||||
void *i2, const char **plugin_name)
|
||||
CALLBACK(dh_filter, bool,
|
||||
void *n, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*group = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
entry_t *entry;
|
||||
diffie_hellman_group_t *algo;
|
||||
const char **plugin_name;
|
||||
|
||||
VA_ARGS_VGET(args, algo, plugin_name);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*algo = entry->algo;
|
||||
*plugin_name = entry->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_dh_enumerator, enumerator_t*,
|
||||
@@ -955,15 +1004,22 @@ METHOD(crypto_factory_t, create_dh_enumerator, enumerator_t*,
|
||||
return create_enumerator(this, this->dhs, dh_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate strength, not entry
|
||||
*/
|
||||
static bool rng_filter(void *n, entry_t **entry, rng_quality_t *quality,
|
||||
void *i2, const char **plugin_name)
|
||||
CALLBACK(rng_filter, bool,
|
||||
void *n, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*quality = (*entry)->algo;
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
entry_t *entry;
|
||||
rng_quality_t *algo;
|
||||
const char **plugin_name;
|
||||
|
||||
VA_ARGS_VGET(args, algo, plugin_name);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*algo = entry->algo;
|
||||
*plugin_name = entry->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_rng_enumerator, enumerator_t*,
|
||||
@@ -972,13 +1028,20 @@ METHOD(crypto_factory_t, create_rng_enumerator, enumerator_t*,
|
||||
return create_enumerator(this, this->rngs, rng_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to enumerate plugin name, not entry
|
||||
*/
|
||||
static bool nonce_gen_filter(void *n, entry_t **entry, const char **plugin_name)
|
||||
CALLBACK(nonce_gen_filter, bool,
|
||||
void *n, enumerator_t *orig, va_list args)
|
||||
{
|
||||
*plugin_name = (*entry)->plugin_name;
|
||||
return TRUE;
|
||||
entry_t *entry;
|
||||
const char **plugin_name;
|
||||
|
||||
VA_ARGS_VGET(args, plugin_name);
|
||||
|
||||
if (orig->enumerate(orig, &entry))
|
||||
{
|
||||
*plugin_name = entry->plugin_name;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
METHOD(crypto_factory_t, create_nonce_gen_enumerator, enumerator_t*,
|
||||
|
||||
Reference in New Issue
Block a user