56 lines
1.2 KiB
C
56 lines
1.2 KiB
C
#include <stdio.h>
|
|
|
|
#include <cli.h>
|
|
#include <libft_ssl.h>
|
|
|
|
#include "compiler.h"
|
|
#include "ft_ssl.h"
|
|
#include "ft_ssl_flags.h"
|
|
#include "internal/ssl/ssl.h"
|
|
#include "version_gen.h"
|
|
|
|
/* Forward declarations */
|
|
static int check_algo(const struct ssl_config *config);
|
|
static inline void update_ret(int *ret, int result);
|
|
/* ------------------- */
|
|
|
|
int
|
|
ssl_run(const struct ssl_config *config)
|
|
{
|
|
int ret;
|
|
int has_input;
|
|
int i;
|
|
|
|
if (CLI_SUCCESS != check_algo(config))
|
|
return CLI_ERROR;
|
|
ret = CLI_SUCCESS;
|
|
has_input = (NULL != config->string || 0 < config->nb_files);
|
|
if (HAS_FLAG(config->flags, FLAG_P) || !has_input)
|
|
update_ret(&ret, run_stdin(config));
|
|
if (NULL != config->string)
|
|
update_ret(&ret, run_string(config));
|
|
for (i = 0; i < config->nb_files; i++)
|
|
update_ret(&ret, run_file(config, config->files[i]));
|
|
return ret;
|
|
}
|
|
|
|
static int
|
|
check_algo(const struct ssl_config *config)
|
|
{
|
|
if (NULL == config->algo->init
|
|
|| NULL == config->algo->update
|
|
|| NULL == config->algo->final)
|
|
{
|
|
fprintf(stderr, "%s: %s: not yet implemented\n",
|
|
g_prog_name, config->algo->name);
|
|
return CLI_ERROR;
|
|
}
|
|
return CLI_SUCCESS;
|
|
}
|
|
|
|
static inline void
|
|
update_ret(int *ret, int result)
|
|
{
|
|
if (CLI_ERROR == result)
|
|
*ret = CLI_ERROR;
|
|
}
|