2 * Copyright (C) 1998-2012 Free Software Foundation, Inc.
6 * This file is part of OpenCDK.
8 * The OpenCDK library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
34 #include <gnutls_int.h>
35 #include <gnutls_str.h>
39 _cdk_buftou32 (const byte
* buf
)
54 _cdk_u32tobuf (u32 u
, byte
* buf
)
66 * @sl: the string list
68 * Release the string list object.
71 cdk_strlist_free (cdk_strlist_t sl
)
85 * @list: destination string list
86 * @string: the string to add
88 * Add the given list to the string list.
91 cdk_strlist_add (cdk_strlist_t
* list
, const char *string
)
94 int string_size
= strlen(string
);
99 sl
= cdk_calloc (1, sizeof *sl
+ string_size
+ 2);
102 sl
->d
= (char *) sl
+ sizeof (*sl
);
103 memcpy (sl
->d
, string
, string_size
+1);
110 _cdk_memistr (const char *buf
, size_t buflen
, const char *sub
)
115 for (t
= (byte
*) buf
, n
= buflen
, s
= (byte
*) sub
; n
; t
++, n
--)
117 if (c_toupper (*t
) == c_toupper (*s
))
119 for (buf
= (char*)t
++, buflen
= n
--, s
++;
120 n
&& c_toupper (*t
) == c_toupper ((byte
) * s
); t
++, s
++, n
--)
134 _cdk_map_gnutls_error (int err
)
140 case GNUTLS_E_INVALID_REQUEST
:
141 return CDK_Inv_Value
;
143 return CDK_General_Error
;
148 /* Remove all trailing white spaces from the string. */
150 _cdk_trim_string (char *s
)
154 (s
[len
- 1] == '\t' ||
155 s
[len
- 1] == '\r' ||
156 s
[len
- 1] == '\n' || s
[len
- 1] == ' '))
162 _cdk_check_args (int overwrite
, const char *in
, const char *out
)
167 return CDK_Inv_Value
;
168 if (strlen (in
) == strlen (out
) && strcmp (in
, out
) == 0)
170 if (!overwrite
&& !stat (out
, &stbuf
))
182 /* Because the tmpfile() version of wine is not really useful,
183 we implement our own version to avoid problems with 'make check'. */
184 static const char *letters
= "abcdefghijklmnopqrstuvwxyz";
185 unsigned char buf
[512], rnd
[24];
189 _gnutls_rnd (GNUTLS_RND_NONCE
, rnd
, DIM (rnd
));
190 for (i
= 0; i
< DIM (rnd
) - 1; i
++)
192 char c
= letters
[(unsigned char) rnd
[i
] % 26];
195 rnd
[DIM (rnd
) - 1] = 0;
196 if (!GetTempPath (464, buf
))
198 _gnutls_str_cat (buf
, sizeof(buf
), "_cdk_");
199 _gnutls_str_cat (buf
, sizeof(buf
), rnd
);
201 /* We need to make sure the file will be deleted when it is closed. */
202 fd
= _open (buf
, _O_CREAT
| _O_EXCL
| _O_TEMPORARY
|
203 _O_RDWR
| _O_BINARY
, _S_IREAD
| _S_IWRITE
);
206 fp
= fdopen (fd
, "w+b");
221 _gnutls_hash_algo_to_pgp (int algo
)
229 case GNUTLS_DIG_SHA1
:
231 case GNUTLS_DIG_RMD160
:
233 case GNUTLS_DIG_SHA256
:
235 case GNUTLS_DIG_SHA384
:
237 case GNUTLS_DIG_SHA512
:
239 case GNUTLS_DIG_SHA224
:
248 _pgp_hash_algo_to_gnutls (int algo
)
253 return GNUTLS_DIG_MD5
;
255 return GNUTLS_DIG_SHA1
;
257 return GNUTLS_DIG_RMD160
;
259 return GNUTLS_DIG_MD2
;
261 return GNUTLS_DIG_SHA256
;
263 return GNUTLS_DIG_SHA384
;
265 return GNUTLS_DIG_SHA512
;
267 return GNUTLS_DIG_SHA224
;
270 return GNUTLS_DIG_NULL
;
275 _pgp_cipher_to_gnutls (int cipher
)
280 return GNUTLS_CIPHER_NULL
;
282 return GNUTLS_CIPHER_IDEA_PGP_CFB
;
284 return GNUTLS_CIPHER_3DES_PGP_CFB
;
286 return GNUTLS_CIPHER_CAST5_PGP_CFB
;
288 return GNUTLS_CIPHER_BLOWFISH_PGP_CFB
;
290 return GNUTLS_CIPHER_SAFER_SK128_PGP_CFB
;
292 return GNUTLS_CIPHER_AES128_PGP_CFB
;
294 return GNUTLS_CIPHER_AES192_PGP_CFB
;
296 return GNUTLS_CIPHER_AES256_PGP_CFB
;
298 return GNUTLS_CIPHER_TWOFISH_PGP_CFB
;
302 _gnutls_debug_log("Unknown openpgp cipher %u\n", cipher
);
303 return GNUTLS_CIPHER_UNKNOWN
;
308 _gnutls_cipher_to_pgp (int cipher
)
312 case GNUTLS_CIPHER_NULL
:
314 case GNUTLS_CIPHER_IDEA_PGP_CFB
:
316 case GNUTLS_CIPHER_3DES_PGP_CFB
:
318 case GNUTLS_CIPHER_CAST5_PGP_CFB
:
320 case GNUTLS_CIPHER_BLOWFISH_PGP_CFB
:
322 case GNUTLS_CIPHER_SAFER_SK128_PGP_CFB
:
324 case GNUTLS_CIPHER_AES128_PGP_CFB
:
326 case GNUTLS_CIPHER_AES192_PGP_CFB
:
328 case GNUTLS_CIPHER_AES256_PGP_CFB
:
330 case GNUTLS_CIPHER_TWOFISH_PGP_CFB
: