refactor: rename ssl_config to digest_config

This commit is contained in:
lohhiiccc 2026-06-27 17:05:37 +02:00
parent 46ec3184cd
commit 66b0a2cb66
11 changed files with 27 additions and 29 deletions

View file

@ -5,19 +5,17 @@
#include <libft_ssl.h>
#include <stdint.h>
#define SSL_MAX_STRINGS 64
#define DIGEST_MAX_STRINGS 64
struct ssl_config
struct digest_config
{
const struct digest_algo *algo;
const char *cmd_name;
uint8_t flags;
const char *strings[SSL_MAX_STRINGS];
const char *strings[DIGEST_MAX_STRINGS];
int nb_strings;
char **files;
int nb_files;
};
enum cli_code cli_parse_arguments(int argc, char **argv, struct ssl_config *config);
int ssl_run(const struct ssl_config *config);
#endif

View file

@ -8,12 +8,12 @@
#define MAX_DIGEST_SIZE 64
#define READ_BUFSIZE 4096
int run_string(const struct ssl_config *config, const char *s);
int run_file(const struct ssl_config *config, const char *path);
int run_stdin(const struct ssl_config *config);
int digest_stream(const struct ssl_config *config, int fd,
int run_string(const struct digest_config *config, const char *s);
int run_file(const struct digest_config *config, const char *path);
int run_stdin(const struct digest_config *config);
int digest_stream(const struct digest_config *config, int fd,
const char *label, int show_algo, int echo);
void print_digest(const struct ssl_config *config, const uint8_t *digest,
void print_digest(const struct digest_config *config, const uint8_t *digest,
const char *label, int show_algo);
#endif

View file

@ -6,7 +6,7 @@
int
cli_handle_p(__unused const char *arg, void *config_void)
{
struct ssl_config *config = (struct ssl_config *)config_void;
struct digest_config *config = (struct digest_config *)config_void;
SET_FLAG(config->flags, FLAG_P);
return CLI_SUCCESS;

View file

@ -6,7 +6,7 @@
int
cli_handle_q(__unused const char *arg, void *config_void)
{
struct ssl_config *config = (struct ssl_config *)config_void;
struct digest_config *config = (struct digest_config *)config_void;
SET_FLAG(config->flags, FLAG_Q);
return CLI_SUCCESS;

View file

@ -6,7 +6,7 @@
int
cli_handle_r(__unused const char *arg, void *config_void)
{
struct ssl_config *config = (struct ssl_config *)config_void;
struct digest_config *config = (struct digest_config *)config_void;
SET_FLAG(config->flags, FLAG_R);
return CLI_SUCCESS;

View file

@ -4,9 +4,9 @@
int
cli_handle_s(const char *arg, void *config_void)
{
struct ssl_config *config = (struct ssl_config *)config_void;
struct digest_config *config = (struct digest_config *)config_void;
if (config->nb_strings >= SSL_MAX_STRINGS)
if (config->nb_strings >= DIGEST_MAX_STRINGS)
return CLI_ERROR;
config->strings[config->nb_strings++] = arg;
return CLI_SUCCESS;

View file

@ -7,12 +7,12 @@
#include "internal/ssl/ssl.h"
/* Forward declarations */
static void process_chunk(const struct ssl_config *config, union digest_ctx *ctx,
static void process_chunk(const struct digest_config *config, union digest_ctx *ctx,
const uint8_t *buf, size_t n, int echo);
/* ------------------- */
int
digest_stream(const struct ssl_config *config, int fd,
digest_stream(const struct digest_config *config, int fd,
const char *label, int show_algo, int echo)
{
union digest_ctx ctx;
@ -31,7 +31,7 @@ digest_stream(const struct ssl_config *config, int fd,
}
static void
process_chunk(const struct ssl_config *config, union digest_ctx *ctx,
process_chunk(const struct digest_config *config, union digest_ctx *ctx,
const uint8_t *buf, size_t n, int echo)
{
if (echo)

View file

@ -20,7 +20,7 @@ typedef void (*t_formatter)(const char *hex, const char *name_upper,
const char *label);
/* Forward declarations */
static enum fmt_mode resolve_fmt(const struct ssl_config *config,
static enum fmt_mode resolve_fmt(const struct digest_config *config,
int show_algo);
static void build_hex(char *buf, const uint8_t *digest, size_t size);
static void build_upper(char *buf, const char *src, size_t size);
@ -42,7 +42,7 @@ static const t_formatter s_formatters[] = {
};
void
print_digest(const struct ssl_config *config, const uint8_t *digest,
print_digest(const struct digest_config *config, const uint8_t *digest,
const char *label, int show_algo)
{
char hex[MAX_DIGEST_SIZE * 2 + 1];
@ -54,7 +54,7 @@ print_digest(const struct ssl_config *config, const uint8_t *digest,
}
static enum fmt_mode
resolve_fmt(const struct ssl_config *config, int show_algo)
resolve_fmt(const struct digest_config *config, int show_algo)
{
if (HAS_FLAG(config->flags, FLAG_Q))
return FMT_QUIET;

View file

@ -11,7 +11,7 @@
#include "version_gen.h"
int
run_file(const struct ssl_config *config, const char *path)
run_file(const struct digest_config *config, const char *path)
{
int fd;
int ret;

View file

@ -11,13 +11,13 @@
#include "internal/ssl/ssl.h"
/* Forward declarations */
static int run_stdin_p(const struct ssl_config *config);
static ssize_t read_and_hash(const struct ssl_config *config, union digest_ctx
static int run_stdin_p(const struct digest_config *config);
static ssize_t read_and_hash(const struct digest_config *config, union digest_ctx
*ctx, char *label, size_t cap);
/* ------------------- */
int
run_stdin(const struct ssl_config *config)
run_stdin(const struct digest_config *config)
{
if (HAS_FLAG(config->flags, FLAG_P) && !HAS_FLAG(config->flags, FLAG_Q))
return run_stdin_p(config);
@ -26,7 +26,7 @@ run_stdin(const struct ssl_config *config)
}
static ssize_t
read_and_hash(const struct ssl_config *config, union digest_ctx *ctx,
read_and_hash(const struct digest_config *config, union digest_ctx *ctx,
char *label, size_t cap)
{
uint8_t buf[READ_BUFSIZE];
@ -47,7 +47,7 @@ read_and_hash(const struct ssl_config *config, union digest_ctx *ctx,
}
static int
run_stdin_p(const struct ssl_config *config)
run_stdin_p(const struct digest_config *config)
{
union digest_ctx ctx;
uint8_t digest[MAX_DIGEST_SIZE];

View file

@ -8,7 +8,7 @@
#include "internal/ssl/ssl.h"
int
run_string(const struct ssl_config *config, const char *s)
run_string(const struct digest_config *config, const char *s)
{
union digest_ctx ctx;
uint8_t digest[MAX_DIGEST_SIZE];