summaryrefslogtreecommitdiff
path: root/support/dktools/dk4mdch.c
blob: b70e18990f04dfbc804c2aa41e1f9e288d6ba05b (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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
	WARNING: This file was generated by dkct.
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: dk4mdch.ctr
*/

/**	@file dk4mdch.c The dk4mdch module.
*/


#line 6 "dk4mdch.ctr"

#include "dk4md.h"
#include "dk4strd.h"





#line 13 "dk4mdch.ctr"



/**     Message digest type names.
        Order must match the definition order in the enum in dk4md.h.
*/
static const dkChar * const     dk4md_type_names[] = {
/* 0 */
dkT("md5"),

/* 1 */
dkT("sha-1"),

/* 2 */
dkT("sha-224"),

/* 3 */
dkT("sha-256"),

/* 4 */
dkT("sha-384"),

/* 5 */
dkT("sha-512"),

/* 6 */
dkT("ripemd-160"),

/* 7 */
dkT("sha1"),

/* 8 */
dkT("sha224"),

/* 9 */
dkT("sha256"),

/* 10 */
dkT("sha384"),

/* 11 */
dkT("sha512"),

/* 12 */
dkT("ripemd160"),

NULL


#line 35 "dk4mdch.ctr"
};



int
dk4md_choose_type(const dkChar *name, dk4_er_t *erp)
{
  int		 back = -1;
  if (NULL != name) {
    switch (dk4str_array_index(dk4md_type_names, name, 0)) {
      case 0: {
        back = DK4_MD_MD5;
      } break;
      case 1: case 7: {
        back = DK4_MD_SHA1;
      } break;
      case 2: case 8: {
        back = DK4_MD_SHA224;
      } break;
      case 3: case 9: {
        back = DK4_MD_SHA256;
      } break;
      case 4: case 10: {
        back = DK4_MD_SHA384;
      } break;
      case 5: case 11: {
        back = DK4_MD_SHA512;
      } break;
      case 6: case 12: {
        back = DK4_MD_RIPEMD_160;
      } break;
    }
    if (-1 == back) {
      dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
    }
  } else {
    dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
  }
  return back;
}



int
dk4md_check_type(int mdtype)
{
  int		 back = 0;
  switch (mdtype) {
    case DK4_MD_MD5 : {
#if DK4_HAVE_OPENSSL_MD5_H
      back = 1;
#endif
    } break;
    case DK4_MD_SHA1 : {
#if DK4_HAVE_OPENSSL_SHA_H
      back = 1;
#endif
    } break;
    case DK4_MD_SHA224 : {
#if DK4_HAVE_OPENSSL_SHA_H && DK4_HAVE_SHA224
      back = 1;
#endif
    } break;
    case DK4_MD_SHA256 : {
#if DK4_HAVE_OPENSSL_SHA_H && DK4_HAVE_SHA256
      back = 1;
#endif
    } break;
    case DK4_MD_SHA384 : {
#if DK4_HAVE_OPENSSL_SHA_H && DK4_HAVE_SHA384
      back = 1;
#endif
    } break;
    case DK4_MD_SHA512 : {
#if DK4_HAVE_OPENSSL_SHA_H && DK4_HAVE_SHA512
      back = 1;
#endif
    } break;
    case DK4_MD_RIPEMD_160 : {
#if DK4_HAVE_OPENSSL_RIPEMD_H
      back = 1;
#endif
    } break;
  }
  return back;
}