-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssl_print.c
104 lines (95 loc) · 3.09 KB
/
ssl_print.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ssl_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vdenysov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/22 12:53:28 by vdenysov #+# #+# */
/* Updated: 2018/10/22 12:53:29 by vdenysov ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_md5.h"
#include "ft_sha256.h"
#include "ft_sha512.h"
void printserror(void)
{
ft_printf("md5: option requires an argument -- s\n");
ft_printf("usage: md5 [-pqr] [-s string] [files ...]\n");
exit(0);
}
void printferror(char c)
{
ft_printf("illegal option -- %c\n", c);
ft_printf("usage: md5 [-pqr] [-s string] [files ...]\n");
exit(0);
}
void sha512print(t_sha512 *sha, t_flags *flag)
{
char s;
s = '\0';
if (flag && !flag->q && !flag->p)
{
if (sha->isstr == 1)
s = '\"';
if (sha->mdname && !flag->r && s == '\0')
ft_printf("SHA%d(%s)= ", sha->sha, sha->mdname);
else if (sha->mdname && !flag->r && s == '\"')
ft_printf("SHA%d(%c%s%c)= ", sha->sha, s, sha->mdname, s);
}
else if (flag && flag->p)
ft_printf("%s", sha->input);
ft_printf("%016lx%016lx%016lx%016lx", sha->a, sha->b, sha->c, sha->d);
ft_printf("%016lx%016lx", sha->e, sha->f);
if (sha->sha == 512)
ft_printf("%016lx%016lx", sha->g, sha->h);
if (flag->r && !flag->q && !flag->p)
ft_printf(" %c%s%c", s, sha->mdname, s);
ft_printf("\n");
}
void sha256print(t_sha256 *sha, t_flags *flag)
{
char s;
s = '\0';
if (flag && !flag->q && !flag->p)
{
if (sha->isstr == 1)
s = '\"';
if (sha->mdname && !flag->r && s == '\0')
ft_printf("SHA%d(%s)= ", sha->sha, sha->mdname);
else if (sha->mdname && !flag->r && s == '\"')
ft_printf("SHA%d(%c%s%c)= ", sha->sha, s, sha->mdname, s);
}
else if (flag && flag->p)
ft_printf("%s", sha->input);
ft_printf("%x%x%x%x", sha->a, sha->b, sha->c, sha->d);
ft_printf("%x%x%x", sha->e, sha->f, sha->g);
if (sha->sha == 256)
ft_printf("%x", sha->h);
if (flag->r && !flag->q && !flag->p)
ft_printf(" %c%s%c", s, sha->mdname, s);
ft_printf("\n");
}
void md5print(t_md5 *md, t_flags *flag)
{
char s;
s = '\0';
if (flag && !flag->q && !flag->p)
{
if (md->isstr == 1)
s = '\"';
if (md->mdname && !flag->r && s == '\0')
ft_printf("MD5 (%s) = ", md->mdname);
else if (md->mdname && !flag->r && s == '\"')
ft_printf("MD5 (%c%s%c) = ", s, md->mdname, s);
}
else if (flag && flag->p)
ft_printf("%s", md->input);
md52hex(md->a);
md52hex(md->b);
md52hex(md->c);
md52hex(md->d);
if (flag->r && !flag->q && !flag->p)
ft_printf(" %c%s%c", s, md->mdname, s);
ft_printf("\n");
}