- code documentation cleaned
This commit is contained in:
@@ -186,7 +186,7 @@
|
|||||||
/**
|
/**
|
||||||
* Macro to reallocate some memory.
|
* Macro to reallocate some memory.
|
||||||
*
|
*
|
||||||
* See #allocator_s.reallocate for description.
|
* See #allocator_t.reallocate for description.
|
||||||
*
|
*
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
@@ -195,7 +195,7 @@
|
|||||||
/**
|
/**
|
||||||
* Macro to clone some memory.
|
* Macro to clone some memory.
|
||||||
*
|
*
|
||||||
* See #allocator_s.*clone_bytes for description.
|
* See #allocator_t.*clone_bytes for description.
|
||||||
*
|
*
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
@@ -204,7 +204,7 @@
|
|||||||
/**
|
/**
|
||||||
* Macro to free some memory.
|
* Macro to free some memory.
|
||||||
*
|
*
|
||||||
* See #allocator_s.free for description.
|
* See #allocator_t.free_pointer for description.
|
||||||
*
|
*
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ struct iterator_t {
|
|||||||
* Returns the current value at the iterator position.
|
* Returns the current value at the iterator position.
|
||||||
*
|
*
|
||||||
* @param this calling object
|
* @param this calling object
|
||||||
* @param [out]value value is set to the current value at iterator position
|
* @param[out] value value is set to the current value at iterator position
|
||||||
* @return
|
* @return
|
||||||
* - SUCCESS
|
* - SUCCESS
|
||||||
* - FAILED if list is empty
|
* - FAILED if list is empty
|
||||||
@@ -62,7 +62,7 @@ struct iterator_t {
|
|||||||
* The iterator position is not changed after inserting
|
* The iterator position is not changed after inserting
|
||||||
*
|
*
|
||||||
* @param this calling iterator
|
* @param this calling iterator
|
||||||
* @param [in]item value to insert in list
|
* @param[in] item value to insert in list
|
||||||
* @return
|
* @return
|
||||||
* - SUCCESS
|
* - SUCCESS
|
||||||
* - FAILED
|
* - FAILED
|
||||||
@@ -75,7 +75,7 @@ struct iterator_t {
|
|||||||
* The iterator position is not changed after inserting.
|
* The iterator position is not changed after inserting.
|
||||||
*
|
*
|
||||||
* @param this calling iterator
|
* @param this calling iterator
|
||||||
* @param [in]item value to insert in list
|
* @param[in] item value to insert in list
|
||||||
* @return
|
* @return
|
||||||
* - SUCCESS
|
* - SUCCESS
|
||||||
* - FAILED
|
* - FAILED
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ struct logger_t {
|
|||||||
*
|
*
|
||||||
* @param logger_name name for the logger_t object
|
* @param logger_name name for the logger_t object
|
||||||
* @param log_level or'ed set of log_levels to assign to the new logger_t object
|
* @param log_level or'ed set of log_levels to assign to the new logger_t object
|
||||||
|
* @param log_thread_id TRUE if thread id should also be logged
|
||||||
* @param output FILE * if log has to go on a file output, NULL for syslog
|
* @param output FILE * if log has to go on a file output, NULL for syslog
|
||||||
* @return
|
* @return
|
||||||
* - logger_t object
|
* - logger_t object
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file randomizer.c
|
* @file randomizer.c
|
||||||
*
|
*
|
||||||
* @brief Class used to get random and pseudo random values
|
* @brief Implementation of randomizer_t.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -30,53 +30,46 @@
|
|||||||
|
|
||||||
#include <utils/allocator.h>
|
#include <utils/allocator.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* Default random device used when no device is given.
|
|
||||||
*/
|
|
||||||
#define DEFAULT_RANDOM_DEVICE "/dev/random"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pseudo random device used when no device is given.
|
|
||||||
*/
|
|
||||||
#define DEFAULT_PSEUDO_RANDOM_DEVICE "/dev/urandom"
|
|
||||||
|
|
||||||
typedef struct private_randomizer_t private_randomizer_t;
|
typedef struct private_randomizer_t private_randomizer_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private data of an randomizer_t object
|
||||||
|
*/
|
||||||
struct private_randomizer_t {
|
struct private_randomizer_t {
|
||||||
/**
|
/**
|
||||||
* public interface
|
* Public interface.
|
||||||
*/
|
*/
|
||||||
randomizer_t public;
|
randomizer_t public;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reads a specific number of bytes from random or pseudo random device
|
* @brief Reads a specific number of bytes from random or pseudo random device.
|
||||||
*
|
*
|
||||||
|
* @param this calling object
|
||||||
* @param pseudo_random TRUE, if pseudo random bytes should be read,
|
* @param pseudo_random TRUE, if pseudo random bytes should be read,
|
||||||
* FALSE for true random bytes
|
* FALSE for true random bytes
|
||||||
* @param bytes Number of bytes to read
|
* @param bytes number of bytes to read
|
||||||
* @param[out] buffer Pointer to buffer where to write the data in.
|
* @param[out] buffer pointer to buffer where to write the data in.
|
||||||
* Size of buffer has to be at least bytes.
|
* Size of buffer has to be at least bytes.
|
||||||
* @return
|
* @return
|
||||||
* - SUCCESS
|
* - SUCCESS
|
||||||
* - FAILED
|
* - FAILED if random device could not be opened
|
||||||
*/
|
*/
|
||||||
status_t (*get_bytes_from_device) (private_randomizer_t *this,bool pseudo_random, size_t bytes, u_int8_t *buffer);
|
status_t (*get_bytes_from_device) (private_randomizer_t *this,bool pseudo_random, size_t bytes, u_int8_t *buffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random device name
|
* Random device name.
|
||||||
*/
|
*/
|
||||||
char *random_dev_name;
|
char *random_dev_name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pseudo random device name
|
* Pseudo random device name.
|
||||||
*/
|
*/
|
||||||
char *pseudo_random_dev_name;
|
char *pseudo_random_dev_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements private_randomizer_t's get_bytes_from_device function.
|
* Implementation of private_randomizer_t.get_bytes_from_device.
|
||||||
* See #private_randomizer_t.get_bytes_from_device for description.
|
|
||||||
*/
|
*/
|
||||||
static status_t get_bytes_from_device(private_randomizer_t *this,bool pseudo_random, size_t bytes, u_int8_t *buffer)
|
static status_t get_bytes_from_device(private_randomizer_t *this,bool pseudo_random, size_t bytes, u_int8_t *buffer)
|
||||||
{
|
{
|
||||||
@@ -114,16 +107,15 @@ static status_t get_bytes_from_device(private_randomizer_t *this,bool pseudo_ran
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements randomizer_t's get_random_bytes function.
|
* Implementation of randomizer_t.get_random_bytes.
|
||||||
* See #randomizer_t.get_random_bytes for description.
|
|
||||||
*/
|
*/
|
||||||
static status_t get_random_bytes(private_randomizer_t *this,size_t bytes, u_int8_t *buffer)
|
static status_t get_random_bytes(private_randomizer_t *this,size_t bytes, u_int8_t *buffer)
|
||||||
{
|
{
|
||||||
return (this->get_bytes_from_device(this, FALSE, bytes, buffer));
|
return (this->get_bytes_from_device(this, FALSE, bytes, buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements randomizer_t's allocate_random_bytes function.
|
* Implementation of randomizer_t.allocate_random_bytes.
|
||||||
* See #randomizer_t.allocate_random_bytes for description.
|
|
||||||
*/
|
*/
|
||||||
static status_t allocate_random_bytes(private_randomizer_t *this, size_t bytes, chunk_t *chunk)
|
static status_t allocate_random_bytes(private_randomizer_t *this, size_t bytes, chunk_t *chunk)
|
||||||
{
|
{
|
||||||
@@ -137,8 +129,7 @@ static status_t allocate_random_bytes(private_randomizer_t *this, size_t bytes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements randomizer_t's get_pseudo_random_bytes function.
|
* Implementation of randomizer_t.get_pseudo_random_bytes.
|
||||||
* See #randomizer_t.get_pseudo_random_bytes for description.
|
|
||||||
*/
|
*/
|
||||||
static status_t get_pseudo_random_bytes(private_randomizer_t *this,size_t bytes, u_int8_t *buffer)
|
static status_t get_pseudo_random_bytes(private_randomizer_t *this,size_t bytes, u_int8_t *buffer)
|
||||||
{
|
{
|
||||||
@@ -147,8 +138,7 @@ static status_t get_pseudo_random_bytes(private_randomizer_t *this,size_t bytes,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements randomizer_t's allocate_random_bytes function.
|
* Implementation of randomizer_t.allocate_pseudo_random_bytes.
|
||||||
* See #randomizer_t.allocate_random_bytes for description.
|
|
||||||
*/
|
*/
|
||||||
static status_t allocate_pseudo_random_bytes(private_randomizer_t *this, size_t bytes, chunk_t *chunk)
|
static status_t allocate_pseudo_random_bytes(private_randomizer_t *this, size_t bytes, chunk_t *chunk)
|
||||||
{
|
{
|
||||||
@@ -163,8 +153,7 @@ static status_t allocate_pseudo_random_bytes(private_randomizer_t *this, size_t
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements randomizer_t's destroy function.
|
* Implementation of randomizer_t.destroy.
|
||||||
* See #randomizer_t.destroy for description.
|
|
||||||
*/
|
*/
|
||||||
static status_t destroy(private_randomizer_t *this)
|
static status_t destroy(private_randomizer_t *this)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file randomizer.h
|
* @file randomizer.h
|
||||||
*
|
*
|
||||||
* @brief Class used to get random and pseudo random values
|
* @brief Interface of randomizer_t.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,9 +28,11 @@
|
|||||||
typedef struct randomizer_t randomizer_t;
|
typedef struct randomizer_t randomizer_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Object representing an randomizer
|
* @brief Class used to get random and pseudo random values.
|
||||||
*
|
*
|
||||||
* This class is thread save as file system read calls are thread save...
|
* This class is thread save as file system read calls are thread save.
|
||||||
|
*
|
||||||
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
struct randomizer_t {
|
struct randomizer_t {
|
||||||
|
|
||||||
@@ -38,25 +40,25 @@ struct randomizer_t {
|
|||||||
* @brief Reads a specific number of bytes from random device.
|
* @brief Reads a specific number of bytes from random device.
|
||||||
*
|
*
|
||||||
* @param this calling randomizer_t object
|
* @param this calling randomizer_t object
|
||||||
* @param bytes Number of bytes to read
|
* @param bytes number of bytes to read
|
||||||
* @param[out] buffer Pointer to buffer where to write the data in.
|
* @param[out] buffer pointer to buffer where to write the data in.
|
||||||
* Size of buffer has to be at least bytes.
|
* Size of buffer has to be at least bytes.
|
||||||
* @return
|
* @return
|
||||||
* - SUCCESS
|
* - SUCCESS
|
||||||
* - FAILED
|
* - FAILED if random device could not be opened
|
||||||
*/
|
*/
|
||||||
status_t (*get_random_bytes) (randomizer_t *this,size_t bytes, u_int8_t *buffer);
|
status_t (*get_random_bytes) (randomizer_t *this,size_t bytes, u_int8_t *buffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Allocates space and writes in random bytes
|
* @brief Allocates space and writes in random bytes.
|
||||||
*
|
*
|
||||||
* @param this calling randomizer_t object
|
* @param this calling randomizer_t object
|
||||||
* @param bytes Number of bytes to allocate
|
* @param bytes number of bytes to allocate
|
||||||
* @param[out] chunk chunk which will hold the allocated random bytes
|
* @param[out] chunk chunk which will hold the allocated random bytes
|
||||||
* @return
|
* @return
|
||||||
* - SUCCESS
|
* - SUCCESS
|
||||||
* - OUT_OF_RES
|
* - OUT_OF_RES
|
||||||
* - FAILED
|
* - FAILED if random device could not be opened
|
||||||
*/
|
*/
|
||||||
status_t (*allocate_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk);
|
status_t (*allocate_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk);
|
||||||
|
|
||||||
@@ -64,25 +66,25 @@ struct randomizer_t {
|
|||||||
* @brief Reads a specific number of bytes from pseudo random device.
|
* @brief Reads a specific number of bytes from pseudo random device.
|
||||||
*
|
*
|
||||||
* @param this calling randomizer_t object
|
* @param this calling randomizer_t object
|
||||||
* @param bytes Number of bytes to read
|
* @param bytes number of bytes to read
|
||||||
* @param[out] buffer Pointer to buffer where to write the data in.
|
* @param[out] buffer pointer to buffer where to write the data in.
|
||||||
* Size of buffer has to be at least bytes.
|
* size of buffer has to be at least bytes.
|
||||||
* @return
|
* @return
|
||||||
* - SUCCESS
|
* - SUCCESS
|
||||||
* - FAILED
|
* - FAILED if random device could not be opened
|
||||||
*/
|
*/
|
||||||
status_t (*get_pseudo_random_bytes) (randomizer_t *this,size_t bytes, u_int8_t *buffer);
|
status_t (*get_pseudo_random_bytes) (randomizer_t *this,size_t bytes, u_int8_t *buffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Allocates space and writes in pseudo random bytes
|
* @brief Allocates space and writes in pseudo random bytes.
|
||||||
*
|
*
|
||||||
* @param this calling randomizer_t object
|
* @param this calling randomizer_t object
|
||||||
* @param bytes Number of bytes to allocate
|
* @param bytes number of bytes to allocate
|
||||||
* @param[out] chunk chunk which will hold the allocated random bytes
|
* @param[out] chunk chunk which will hold the allocated random bytes
|
||||||
* @return
|
* @return
|
||||||
* - SUCCESS
|
* - SUCCESS
|
||||||
* - OUT_OF_RES
|
* - OUT_OF_RES
|
||||||
* - FAILED
|
* - FAILED if random device could not be opened
|
||||||
*/
|
*/
|
||||||
status_t (*allocate_pseudo_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk);
|
status_t (*allocate_pseudo_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk);
|
||||||
|
|
||||||
@@ -90,29 +92,32 @@ struct randomizer_t {
|
|||||||
* @brief Destroys a randomizer_t object.
|
* @brief Destroys a randomizer_t object.
|
||||||
*
|
*
|
||||||
* @param this randomizer_t object to destroy
|
* @param this randomizer_t object to destroy
|
||||||
* @return
|
* @return SUCCESS in any case
|
||||||
* SUCCESS in any case
|
|
||||||
*/
|
*/
|
||||||
status_t (*destroy) (randomizer_t *this);
|
status_t (*destroy) (randomizer_t *this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create an randomizer_t object
|
* @brief Creates a randomizer_t object
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* - created randomizer_t, or
|
* - created randomizer_t, or
|
||||||
* - NULL if failed
|
* - NULL if failed
|
||||||
|
*
|
||||||
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
randomizer_t *randomizer_create();
|
randomizer_t *randomizer_create();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create an randomizer_t object with specific random device names
|
* @brief Creates an randomizer_t object with specific random device names.
|
||||||
*
|
*
|
||||||
* @param random_dev_name Device name for random values, etc /dev/random
|
* @param random_dev_name device name for random values, etc /dev/random
|
||||||
* @param prandom_dev_name Device name for pseudo random values, etc /dev/urandom
|
* @param prandom_dev_name device name for pseudo random values, etc /dev/urandom
|
||||||
* @return
|
* @return
|
||||||
* - created randomizer_t, or
|
* - created randomizer_t
|
||||||
* - NULL if failed
|
* - NULL if out of ressources
|
||||||
|
*
|
||||||
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
randomizer_t *randomizer_create_on_devices(char * random_dev_name,char * prandom_dev_name);
|
randomizer_t *randomizer_create_on_devices(char * random_dev_name,char * prandom_dev_name);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user