aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 608dc907ead0e9b5398707ffe2bbb2d8ba1b4245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/03 20:29:33 by cacharle          #+#    #+#             */
/*   Updated: 2020/08/02 14:17:53 by charles          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "ft_ssl.h"

static const uint32_t	g_md5_state[4] = {MD5_A_INIT, MD5_B_INIT, MD5_C_INIT, MD5_D_INIT};

/* static uint32_t	g_sha1_state[5] = {0}; */

t_compression_entry	g_compression_table[] = {
	{"md5", {md5_compression_func, g_md5_state, sizeof(g_md5_state), 64}},
	/* {"sha1", {sha1_compression_func, g_sha1_state, sizeof(g_sha1_state), 64}} */
};

t_message_digest_param	*dispatch_command(char *command)
{
	size_t	i;

	i = 0;
	while (i < sizeof(g_compression_table) / sizeof(t_compression_entry))
	{
		if (ft_strcasecmp(g_compression_table[i].name, command) == 0)
			return (&g_compression_table[i].param);
		i++;
	}
	error_command(command);
	return (NULL);
}

int main(int argc, char **argv)
{
	if (argc == 1)
	{
		ft_putstr("usage: ");
		ft_putstr(argv[0]);
		ft_putendl_fd(" command [command opts] [command args]", STDERR_FILENO);
		return (1);
	}
	t_message_digest_param *md_param = dispatch_command(argv[1]);
	if (md_param == NULL)
		return 1;
	return (parse_args(argc - 2, argv + 2, ft_strtoupper(argv[1]), md_param));
}