base64 init context
This commit is contained in:
parent
aa31879e15
commit
14e2390ef8
7 changed files with 125 additions and 24 deletions
12
Makefile
12
Makefile
|
@ -20,6 +20,7 @@ ROOT := $(shell pwd)
|
||||||
SRC_DIR := $(ROOT)/src/
|
SRC_DIR := $(ROOT)/src/
|
||||||
MD5_DIR := $(SRC_DIR)/md5/
|
MD5_DIR := $(SRC_DIR)/md5/
|
||||||
SHA_DIR := $(SRC_DIR)/sha/
|
SHA_DIR := $(SRC_DIR)/sha/
|
||||||
|
B64_DIR := $(SRC_DIR)/base64/
|
||||||
OBJ_DIR := $(ROOT)/obj/
|
OBJ_DIR := $(ROOT)/obj/
|
||||||
INC_DIR := $(ROOT)/inc/
|
INC_DIR := $(ROOT)/inc/
|
||||||
LIB_DIR := $(ROOT)/lib/
|
LIB_DIR := $(ROOT)/lib/
|
||||||
|
@ -63,6 +64,7 @@ SHA_SRC = ft_sha256_init.c \
|
||||||
ft_sha224_final.c \
|
ft_sha224_final.c \
|
||||||
ft_sha224_digest_string.c
|
ft_sha224_digest_string.c
|
||||||
|
|
||||||
|
BASE64_SRC = ft_base64_init.c
|
||||||
|
|
||||||
SRC = main.c \
|
SRC = main.c \
|
||||||
ft_ssl_init.c \
|
ft_ssl_init.c \
|
||||||
|
@ -81,7 +83,8 @@ SRC = main.c \
|
||||||
ft_ssl_usage.c
|
ft_ssl_usage.c
|
||||||
|
|
||||||
SRC += $(MD5_SRC) \
|
SRC += $(MD5_SRC) \
|
||||||
$(SHA_SRC)
|
$(SHA_SRC) \
|
||||||
|
$(BASE64_SRC)
|
||||||
# project object files
|
# project object files
|
||||||
|
|
||||||
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
||||||
|
@ -97,11 +100,15 @@ MD5_TESTS += $(MD5_SRC)
|
||||||
SHA_TESTS = sha_tests.c
|
SHA_TESTS = sha_tests.c
|
||||||
SHA_TESTS += $(SHA_SRC)
|
SHA_TESTS += $(SHA_SRC)
|
||||||
|
|
||||||
|
BASE64_TESTS = base64_tests.c
|
||||||
|
BASE64_TESTS += $(BASE64_SRC)
|
||||||
|
|
||||||
TEST_SRC = tests.c \
|
TEST_SRC = tests.c \
|
||||||
munit.c
|
munit.c
|
||||||
|
|
||||||
TEST_SRC += $(MD5_TESTS) \
|
TEST_SRC += $(MD5_TESTS) \
|
||||||
$(SHA_TESTS)
|
$(SHA_TESTS) \
|
||||||
|
$(BASE64_TESTS)
|
||||||
|
|
||||||
TEST_OBJ = $(addprefix $(OBJ_DIR), $(TEST_SRC:.c=.o))
|
TEST_OBJ = $(addprefix $(OBJ_DIR), $(TEST_SRC:.c=.o))
|
||||||
|
|
||||||
|
@ -190,6 +197,7 @@ multi:
|
||||||
vpath %.c $(SRC_DIR) \
|
vpath %.c $(SRC_DIR) \
|
||||||
$(MD5_DIR) \
|
$(MD5_DIR) \
|
||||||
$(SHA_DIR) \
|
$(SHA_DIR) \
|
||||||
|
$(B64_DIR) \
|
||||||
$(TST_DIR) \
|
$(TST_DIR) \
|
||||||
$(MUINUT_DIR)
|
$(MUINUT_DIR)
|
||||||
|
|
||||||
|
|
31
inc/ft_base64.h
Normal file
31
inc/ft_base64.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_base64.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/01/19 17:58:39 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2019/01/19 17:59:19 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_BASE64_H
|
||||||
|
# define FT_BASE64_H
|
||||||
|
|
||||||
|
# include <stdint.h>
|
||||||
|
|
||||||
|
# define FT_BASE64_BLOCK_SIZE 24
|
||||||
|
|
||||||
|
typedef uint64_t t_byte8;
|
||||||
|
typedef unsigned char t_byte1;
|
||||||
|
|
||||||
|
typedef struct s_base64_ctx
|
||||||
|
{
|
||||||
|
t_byte8 block_bit_index;
|
||||||
|
t_byte1 block[FT_BASE64_BLOCK_SIZE];
|
||||||
|
} t_base64_ctx;
|
||||||
|
|
||||||
|
void ft_base64_init(t_base64_ctx *ctx);
|
||||||
|
|
||||||
|
#endif
|
31
inc/tests.h
31
inc/tests.h
|
@ -15,21 +15,29 @@
|
||||||
|
|
||||||
# define MUNIT_ENABLE_ASSERT_ALIASES
|
# define MUNIT_ENABLE_ASSERT_ALIASES
|
||||||
# include "munit.h"
|
# include "munit.h"
|
||||||
|
# include "tests_macros.h"
|
||||||
|
|
||||||
MunitResult should_init_ctx(const MunitParameter test_params[],
|
/*
|
||||||
|
** MD5
|
||||||
|
*/
|
||||||
|
MunitResult should_init_md5_ctx(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult update_should_change_count(const MunitParameter test_params[],
|
MunitResult md5_update_change_count(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult decode_string_to_int(const MunitParameter test_params[],
|
MunitResult md5_decode_string_to_int(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult encode_bits_to_string(const MunitParameter test_params[],
|
MunitResult md5_encode_bits_to_string(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult encode_register(const MunitParameter test_params[],
|
MunitResult md5_encode_register(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult create_digest(const MunitParameter test_params[],
|
MunitResult md5_create_digest(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult create_string(const MunitParameter test_params[],
|
MunitResult md5_create_string(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** SHA256
|
||||||
|
*/
|
||||||
MunitResult should_init_ctx_sha256(const MunitParameter test_params[],
|
MunitResult should_init_ctx_sha256(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult decode_string_to_int_sha256(const MunitParameter test_params[],
|
MunitResult decode_string_to_int_sha256(const MunitParameter test_params[],
|
||||||
|
@ -48,6 +56,10 @@ MunitResult compute_digest_sha256(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult create_digest_string_sha256(const MunitParameter test_params[],
|
MunitResult create_digest_string_sha256(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** SHA224
|
||||||
|
*/
|
||||||
MunitResult should_init_ctx_sha224(const MunitParameter test_params[],
|
MunitResult should_init_ctx_sha224(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
MunitResult compute_digest_sha224(const MunitParameter test_params[],
|
MunitResult compute_digest_sha224(const MunitParameter test_params[],
|
||||||
|
@ -55,4 +67,9 @@ MunitResult compute_digest_sha224(const MunitParameter test_params[],
|
||||||
MunitResult create_digest_string_sha224(const MunitParameter test_params[],
|
MunitResult create_digest_string_sha224(const MunitParameter test_params[],
|
||||||
void *test_data);
|
void *test_data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** BASE64
|
||||||
|
*/
|
||||||
|
MunitResult should_init_base64_ctx(const MunitParameter test_params[],
|
||||||
|
void *test_data);
|
||||||
#endif
|
#endif
|
||||||
|
|
20
src/base64/ft_base64_init.c
Normal file
20
src/base64/ft_base64_init.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_base64_init.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/01/19 17:57:47 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2019/01/19 17:58:16 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_base64.h"
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_base64_init(t_base64_ctx *ctx)
|
||||||
|
{
|
||||||
|
ctx->block_bit_index = 0;
|
||||||
|
ft_bzero(ctx->block, FT_BASE64_BLOCK_SIZE);
|
||||||
|
}
|
18
t/base64_tests.c
Normal file
18
t/base64_tests.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#include "tests.h"
|
||||||
|
#include "tests_macros.h"
|
||||||
|
#include "ft_base64.h"
|
||||||
|
|
||||||
|
TEST_RESULT should_init_base64_ctx(TEST_PARAMS, TEST_DATA)
|
||||||
|
{
|
||||||
|
UNUSED(test_params);
|
||||||
|
UNUSED(test_data);
|
||||||
|
t_base64_ctx ctx;
|
||||||
|
|
||||||
|
ft_base64_init(&ctx);
|
||||||
|
|
||||||
|
munit_assert_true(ctx.block_bit_index == 0);
|
||||||
|
for (int i = 0; i < FT_BASE64_BLOCK_SIZE; i++)
|
||||||
|
munit_assert_uchar(ctx.block[i], ==, 0);
|
||||||
|
|
||||||
|
return MUNIT_OK;
|
||||||
|
}
|
|
@ -15,7 +15,7 @@
|
||||||
#include "ft_md5.h"
|
#include "ft_md5.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
TEST_RESULT should_init_ctx(TEST_PARAMS, TEST_DATA)
|
TEST_RESULT should_init_md5_ctx(TEST_PARAMS, TEST_DATA)
|
||||||
{
|
{
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
@ -34,7 +34,7 @@ TEST_RESULT should_init_ctx(TEST_PARAMS, TEST_DATA)
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_RESULT decode_string_to_int(TEST_PARAMS, TEST_DATA)
|
TEST_RESULT md5_decode_string_to_int(TEST_PARAMS, TEST_DATA)
|
||||||
{
|
{
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
@ -56,7 +56,7 @@ TEST_RESULT decode_string_to_int(TEST_PARAMS, TEST_DATA)
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_RESULT update_should_change_count(TEST_PARAMS, TEST_DATA)
|
TEST_RESULT md5_update_change_count(TEST_PARAMS, TEST_DATA)
|
||||||
{
|
{
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
@ -72,7 +72,7 @@ TEST_RESULT update_should_change_count(TEST_PARAMS, TEST_DATA)
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_RESULT encode_bits_to_string(TEST_PARAMS, TEST_DATA)
|
TEST_RESULT md5_encode_bits_to_string(TEST_PARAMS, TEST_DATA)
|
||||||
{
|
{
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
@ -101,7 +101,7 @@ TEST_RESULT encode_bits_to_string(TEST_PARAMS, TEST_DATA)
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_RESULT encode_register(TEST_PARAMS, TEST_DATA)
|
TEST_RESULT md5_encode_register(TEST_PARAMS, TEST_DATA)
|
||||||
{
|
{
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
@ -127,7 +127,7 @@ TEST_RESULT encode_register(TEST_PARAMS, TEST_DATA)
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_RESULT create_digest(TEST_PARAMS, TEST_DATA)
|
TEST_RESULT md5_create_digest(TEST_PARAMS, TEST_DATA)
|
||||||
{
|
{
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
@ -168,7 +168,7 @@ TEST_RESULT create_digest(TEST_PARAMS, TEST_DATA)
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_RESULT create_string(TEST_PARAMS, TEST_DATA)
|
TEST_RESULT md5_create_string(TEST_PARAMS, TEST_DATA)
|
||||||
{
|
{
|
||||||
UNUSED(test_params);
|
UNUSED(test_params);
|
||||||
UNUSED(test_data);
|
UNUSED(test_data);
|
||||||
|
|
23
t/tests.c
23
t/tests.c
|
@ -14,13 +14,13 @@
|
||||||
#include "tests_macros.h"
|
#include "tests_macros.h"
|
||||||
|
|
||||||
MunitTest g_md5_tests[] = {
|
MunitTest g_md5_tests[] = {
|
||||||
IT("/init_ctx", should_init_ctx, NULL, NULL, 0, NULL),
|
IT("/init_ctx", should_init_md5_ctx, NULL, NULL, 0, NULL),
|
||||||
IT("/updates_ctx_count", update_should_change_count, NULL, NULL, 0, NULL),
|
IT("/updates_ctx_count", md5_update_change_count, NULL, NULL, 0, NULL),
|
||||||
IT("/decode_string_to_int", decode_string_to_int, NULL, NULL, 0, NULL),
|
IT("/decode_string_to_int", md5_decode_string_to_int, NULL, NULL, 0, NULL),
|
||||||
IT("/encode_bits_to_string", encode_bits_to_string, NULL, NULL, 0, NULL),
|
IT("/encode_to_string", md5_encode_bits_to_string, NULL, NULL, 0, NULL),
|
||||||
IT("/encode_register", encode_register, NULL, NULL, 0, NULL),
|
IT("/encode_register", md5_encode_register, NULL, NULL, 0, NULL),
|
||||||
IT("/creates_digest", create_digest, NULL, NULL, 0, NULL),
|
IT("/creates_digest", md5_create_digest, NULL, NULL, 0, NULL),
|
||||||
IT("/creates_string", create_string, NULL, NULL, 0, NULL),
|
IT("/creates_string", md5_create_string, NULL, NULL, 0, NULL),
|
||||||
END_IT
|
END_IT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,11 +37,18 @@ MunitTest g_sha_tests[] = {
|
||||||
IT("/compute_digest_224", compute_digest_sha224, NULL, NULL, 0, NULL),
|
IT("/compute_digest_224", compute_digest_sha224, NULL, NULL, 0, NULL),
|
||||||
IT("/creates_string_256", create_digest_string_sha256, NULL, NULL, 0, NULL),
|
IT("/creates_string_256", create_digest_string_sha256, NULL, NULL, 0, NULL),
|
||||||
IT("/creates_string_224", create_digest_string_sha224, NULL, NULL, 0, NULL),
|
IT("/creates_string_224", create_digest_string_sha224, NULL, NULL, 0, NULL),
|
||||||
END_IT};
|
END_IT
|
||||||
|
};
|
||||||
|
|
||||||
|
MunitTest g_base64_tests[] = {
|
||||||
|
IT("/init_ctx", should_init_base64_ctx, NULL, NULL, 0, NULL),
|
||||||
|
END_IT
|
||||||
|
};
|
||||||
|
|
||||||
static const MunitSuite g_ft_ssl_suites[] = {
|
static const MunitSuite g_ft_ssl_suites[] = {
|
||||||
{(char *)"/md5_suite", g_md5_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE},
|
{(char *)"/md5_suite", g_md5_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE},
|
||||||
{(char *)"/sha_suite", g_sha_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE},
|
{(char *)"/sha_suite", g_sha_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE},
|
||||||
|
{(char *)"/base64_suite", g_base64_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE},
|
||||||
{NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}
|
{NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue