File: enums.c

package info (click to toggle)
oath-toolkit 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,824 kB
  • ctags: 9,237
  • sloc: ansic: 54,713; sh: 13,738; yacc: 1,254; xml: 756; makefile: 353
file content (275 lines) | stat: -rw-r--r-- 6,972 bytes parent folder | download | duplicates (2)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * enums.c - support functions for PSKC enums.
 * Copyright (C) 2012-2015 Simon Josefsson
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <config.h>

#include <pskc/pskc.h>
#include "internal.h"

#include <string.h>		/* strcmp */

/**
 * pskc_pinusagemode2str:
 * @pinusagemode: an #pskc_pinusagemode enumeration type
 *
 * Convert #pskc_pinusagemode to a string.  For example,
 * pskc_pinusagemode2str(%PSKC_PINUSAGEMODE_LOCAL) will return
 * "Local".  The returned string must not be deallocated.
 *
 * Returns: String corresponding to #pskc_pinusagemode.
 */
const char *
pskc_pinusagemode2str (pskc_pinusagemode pinusagemode)
{
  const char *p;

  switch (pinusagemode)
    {
    case PSKC_PINUSAGEMODE_LOCAL:
      p = "Local";
      break;

    case PSKC_PINUSAGEMODE_PREPEND:
      p = "Prepend";
      break;

    case PSKC_PINUSAGEMODE_APPEND:
      p = "Append";
      break;

    case PSKC_PINUSAGEMODE_ALGORITHMIC:
      p = "Algorithmic";
      break;

    default:
      _pskc_debug ("unknown pinusagemode value %d", pinusagemode);
      p = "Unknown";
      break;
    }

  return p;
}

/**
 * pskc_valueformat2str:
 * @valueformat: an #pskc_valueformat enumeration type
 *
 * Convert #pskc_valueformat to a string.  For example,
 * pskc_valueformat2str(%PSKC_VALUEFORMAT_DECIMAL) will return
 * "DECIMAL".  The returned string must not be deallocated.
 *
 * Returns: String corresponding to #pskc_valueformat.
 */
const char *
pskc_valueformat2str (pskc_valueformat valueformat)
{
  const char *p;

  switch (valueformat)
    {
    case PSKC_VALUEFORMAT_DECIMAL:
      p = "DECIMAL";
      break;

    case PSKC_VALUEFORMAT_HEXADECIMAL:
      p = "HEXADECIMAL";
      break;

    case PSKC_VALUEFORMAT_ALPHANUMERIC:
      p = "ALPHANUMERIC";
      break;

    case PSKC_VALUEFORMAT_BASE64:
      p = "BASE64";
      break;

    case PSKC_VALUEFORMAT_BINARY:
      p = "BINARY";
      break;

    default:
      _pskc_debug ("unknown valueformat value %d", valueformat);
      p = "Unknown";
      break;
    }

  return p;
}

/**
 * pskc_keyusage2str:
 * @keyusage: an #pskc_keyusage enumeration type
 *
 * Convert #pskc_keyusage to a string.  For example,
 * pskc_keyusage2str(%PSKC_KEYUSAGE_OTP) will return "OTP".  The
 * returned string must not be deallocated.
 *
 * Returns: String corresponding to #pskc_keyusage.
 */
const char *
pskc_keyusage2str (pskc_keyusage keyusage)
{
  const char *p;

  switch (keyusage)
    {
    case PSKC_KEYUSAGE_OTP:
      p = "OTP";
      break;

    case PSKC_KEYUSAGE_CR:
      p = "CR";
      break;

    case PSKC_KEYUSAGE_ENCRYPT:
      p = "Encrypt";
      break;

    case PSKC_KEYUSAGE_INTEGRITY:
      p = "Integrity";
      break;

    case PSKC_KEYUSAGE_VERIFY:
      p = "Verify";
      break;

    case PSKC_KEYUSAGE_UNLOCK:
      p = "Unlock";
      break;

    case PSKC_KEYUSAGE_DECRYPT:
      p = "Decrypt";
      break;

    case PSKC_KEYUSAGE_KEYWRAP:
      p = "KeyWrap";
      break;

    case PSKC_KEYUSAGE_UNWRAP:
      p = "Unwrap";
      break;

    case PSKC_KEYUSAGE_DERIVE:
      p = "Derive";
      break;

    case PSKC_KEYUSAGE_GENERATE:
      p = "Generate";
      break;

    default:
      _pskc_debug ("unknown keyusage value %d", keyusage);
      p = "Unknown";
      break;
    }

  return p;
}

/**
 * pskc_str2pinusagemode:
 * @pinusagemode: an string describing a key usage.
 *
 * Convert a string to a #pskc_pinusagemode type.  For example,
 * pskc_str2pinusagemode("Local") will return
 * %PSKC_PINUSAGEMODE_LOCAL.
 *
 * Returns: The corresponding #pskc_pinusagemode value.
 */
pskc_pinusagemode
pskc_str2pinusagemode (const char *pinusagemode)
{
  if (strcmp ("Local", pinusagemode) == 0)
    return PSKC_PINUSAGEMODE_LOCAL;
  else if (strcmp ("Prepend", pinusagemode) == 0)
    return PSKC_PINUSAGEMODE_PREPEND;
  else if (strcmp ("Append", pinusagemode) == 0)
    return PSKC_PINUSAGEMODE_APPEND;
  else if (strcmp ("Algorithmic", pinusagemode) == 0)
    return PSKC_PINUSAGEMODE_ALGORITHMIC;
  _pskc_debug ("unknown pinusagemode value '%s'", pinusagemode);
  return PSKC_PINUSAGEMODE_UNKNOWN;
}

/**
 * pskc_str2valueformat:
 * @valueformat: an string describing a key usage.
 *
 * Convert a string to a #pskc_valueformat type.  For example,
 * pskc_str2valueformat("DECIMAL") will return
 * %PSKC_VALUEFORMAT_DECIMAL.
 *
 * Returns: The corresponding #pskc_valueformat value.
 */
pskc_valueformat
pskc_str2valueformat (const char *valueformat)
{
  if (strcmp ("DECIMAL", valueformat) == 0)
    return PSKC_VALUEFORMAT_DECIMAL;
  else if (strcmp ("HEXADECIMAL", valueformat) == 0)
    return PSKC_VALUEFORMAT_HEXADECIMAL;
  else if (strcmp ("ALPHANUMERIC", valueformat) == 0)
    return PSKC_VALUEFORMAT_ALPHANUMERIC;
  else if (strcmp ("BASE64", valueformat) == 0)
    return PSKC_VALUEFORMAT_BASE64;
  else if (strcmp ("BINARY", valueformat) == 0)
    return PSKC_VALUEFORMAT_BINARY;
  _pskc_debug ("unknown valueformat value '%s'", valueformat);
  return PSKC_VALUEFORMAT_UNKNOWN;
}

/**
 * pskc_str2keyusage:
 * @keyusage: an string describing a key usage.
 *
 * Convert a string to a #pskc_keyusage type.  For example,
 * pskc_str2keyusage("KeyWrap") will return %PSKC_KEYUSAGE_KEYWRAP.
 *
 * Returns: The corresponding #pskc_keyusage value.
 */
pskc_keyusage
pskc_str2keyusage (const char *keyusage)
{
  if (strcmp ("OTP", keyusage) == 0)
    return PSKC_KEYUSAGE_OTP;
  else if (strcmp ("CR", keyusage) == 0)
    return PSKC_KEYUSAGE_CR;
  else if (strcmp ("Encrypt", keyusage) == 0)
    return PSKC_KEYUSAGE_ENCRYPT;
  else if (strcmp ("Integrity", keyusage) == 0)
    return PSKC_KEYUSAGE_INTEGRITY;
  else if (strcmp ("Verify", keyusage) == 0)
    return PSKC_KEYUSAGE_VERIFY;
  else if (strcmp ("Unlock", keyusage) == 0)
    return PSKC_KEYUSAGE_UNLOCK;
  else if (strcmp ("Decrypt", keyusage) == 0)
    return PSKC_KEYUSAGE_DECRYPT;
  else if (strcmp ("KeyWrap", keyusage) == 0)
    return PSKC_KEYUSAGE_KEYWRAP;
  else if (strcmp ("Unwrap", keyusage) == 0)
    return PSKC_KEYUSAGE_UNWRAP;
  else if (strcmp ("Derive", keyusage) == 0)
    return PSKC_KEYUSAGE_DERIVE;
  else if (strcmp ("Generate", keyusage) == 0)
    return PSKC_KEYUSAGE_GENERATE;
  _pskc_debug ("unknown keyusage value '%s'", keyusage);
  return PSKC_KEYUSAGE_UNKNOWN;
}