-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.c
131 lines (125 loc) · 4.02 KB
/
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yinzhang <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/08/04 20:30:50 by yinzhang #+# #+# */
/* Updated: 2019/08/04 20:30:52 by yinzhang ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ssl.h"
void freestuff(t_flags *opt)
{
if (opt->text != NULL)
free(opt->text);
if (opt->stdinputtext != NULL)
free(opt->stdinputtext);
if (opt->emptytext != NULL)
free(opt->emptytext);
opt->text = NULL;
opt->textwithsflag = NULL;
opt->stdinputtext = NULL;
opt->emptytext = NULL;
}
void printmd5(t_md5 *md5, t_flags *opt, unsigned char *s)
{
if (opt->p == 1)
ft_printf("%s", s);
if (opt->filename != NULL && opt->r == 0 && opt->q == 0 && opt->p != 1)
{
ft_printf("MD5 (%s) = ", opt->filename);
}
if (opt->s == 1 && opt->q != 1 && opt->r != 1)
{
ft_printf("MD5 (\"%s\") = ", opt->textwithsflag);
}
ft_printf("%.8x%.8x%.8x%.8x", md5->a0, md5->b0, md5->c0, md5->d0);
if (opt->s == 1 && opt->q != 1 && opt->r == 1)
{
ft_printf(" \"%s\"", opt->textwithsflag);
}
if (opt->r == 1 && opt->q == 0 && opt->filename != NULL && opt->p != 1)
ft_printf(" %s", opt->filename);
ft_printf("\n");
if (opt->p == 1)
opt->p = 2;
freestuff(opt);
}
void printsha256(t_sha256 *sha2, t_flags *opt, unsigned char *s)
{
if (opt->p == 1)
ft_printf("%s", s);
if (opt->filename != NULL && opt->r == 0 && opt->q == 0 && opt->p != 1)
{
ft_printf("SHA256 (%s) = ", opt->filename);
}
if (opt->s == 1 && opt->q != 1 && opt->r != 1)
{
ft_printf("SHA256 (\"%s\") = ", opt->textwithsflag);
}
ft_printf("%.8x%.8x%.8x%.8x%.8x%.8x%.8x%.8x", sha2->h0, sha2->h1, sha2->h2,
sha2->h3, sha2->h4, sha2->h5, sha2->h6, sha2->h7);
if (opt->s == 1 && opt->q != 1 && opt->r == 1)
{
ft_printf(" \"%s\"", opt->textwithsflag);
}
if (opt->r == 1 && opt->q == 0 && opt->filename != NULL && opt->p != 1)
ft_printf(" %s", opt->filename);
ft_printf("\n");
if (opt->p == 1)
opt->p = 2;
freestuff(opt);
}
void printsha224(t_sha256 *sha2, t_flags *opt, unsigned char *s)
{
if (opt->p == 1)
ft_printf("%s", s);
if (opt->filename != NULL && opt->r == 0 && opt->q == 0 && opt->p != 1)
{
ft_printf("SHA224 (%s) = ", opt->filename);
}
if (opt->s == 1 && opt->q != 1 && opt->r != 1)
{
ft_printf("SHA224 (\"%s\") = ", opt->textwithsflag);
}
ft_printf("%.8x%.8x%.8x%.8x%.8x%.8x%.8x", sha2->h0, sha2->h1, sha2->h2,
sha2->h3, sha2->h4, sha2->h5, sha2->h6);
if (opt->s == 1 && opt->q != 1 && opt->r == 1)
{
ft_printf(" \"%s\"", opt->textwithsflag);
}
if (opt->r == 1 && opt->q == 0 && opt->filename != NULL && opt->p != 1)
ft_printf(" %s", opt->filename);
ft_printf("\n");
if (opt->p == 1)
opt->p = 2;
freestuff(opt);
}
void printsha512(t_sha512 *sha5, t_flags *opt, unsigned char *s)
{
if (opt->p == 1)
ft_printf("%s", s);
if (opt->filename != NULL && opt->r == 0 && opt->q == 0 && opt->p != 1)
{
ft_printf("SHA512 (%s) = ", opt->filename);
}
if (opt->s == 1 && opt->q != 1 && opt->r != 1)
{
ft_printf("SHA512 (\"%s\") = ", opt->textwithsflag);
}
ft_printf("%.8llx%.8llx%.8llx%.8llx%.8llx%.8llx%.8llx%.8llx",
sha5->h0, sha5->h1, sha5->h2,
sha5->h3, sha5->h4, sha5->h5, sha5->h6, sha5->h7);
if (opt->s == 1 && opt->q != 1 && opt->r == 1)
{
ft_printf(" \"%s\"", opt->textwithsflag);
}
if (opt->r == 1 && opt->q == 0 && opt->filename != NULL && opt->p == 0)
ft_printf(" %s", opt->filename);
ft_printf("\n");
if (opt->p == 1)
opt->p = 2;
freestuff(opt);
}