corrected makefile
[gnutls.git] / tests / pgps2kgnu.c
blob0c646e9751f79d6674e7308ae32204ea14b3d971
1 /*
2 * Copyright (C) 2008-2012 Free Software Foundation, Inc.
4 * Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
6 * pgps2kgnu: test GNU extensions to the OpenPGP S2K specification.
7 * at the moment, we just test the "GNU dummy" S2K
8 * extension.
11 * This file is part of GnuTLS.
13 * GnuTLS is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * GnuTLS is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GnuTLS; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <gnutls/gnutls.h>
36 #include <gnutls/openpgp.h>
38 static char dummy_key[] =
39 "-----BEGIN PGP PRIVATE KEY BLOCK-----\n"
40 "Version: GnuPG v1.4.9 (GNU/Linux)\n"
41 "\n"
42 "lQCVBEO3YdABBACRqqEnucag4+vyZny2M67Pai5+5suIRRvY+Ly8Ms5MvgCi3EVV\n"
43 "xT05O/+0ShiRaf+QicCOFrhbU9PZzzU+seEvkeW2UCu4dQfILkmj+HBEIltGnHr3\n"
44 "G0yegHj5pnqrcezERURf2e17gGFWX91cXB9Cm721FPXczuKraphKwCA9PwARAQAB\n"
45 "/gNlAkdOVQG0OURlbW9uc3RyYXRpb24gS2V5IGZvciBTMksgR05VIGV4dGVuc2lv\n"
46 "biAxMDAxIC0tIGdudS1kdW1teYi8BBMBAgAmBQJDt2HQAhsDBQkB4TOABgsJCAcD\n"
47 "AgQVAggDBBYCA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hEORjWO4f46qk73RAgSqG/GyzI4ltWiDhqn\n"
63 "vnQCFl3+QFSe4zinqykHnLwGPMXv428d/ZjkIc2ju8dRsn4=\n"
64 "=CR5w\n" "-----END PGP PRIVATE KEY BLOCK-----\n";
66 /* Test capability of reading the gnu-dummy OpenPGP S2K extension.
67 See: doc/DETAILS from gnupg
68 http://lists.gnu.org/archive/html/gnutls-devel/2008-08/msg00023.html
71 static void
72 tls_log_func (int level, const char *str)
74 fprintf (stderr, "|<%d>| %s", level, str);
77 int
78 main (int argc, char** argv)
80 int rc;
81 gnutls_datum_t keydatum =
82 { (unsigned char *) dummy_key, strlen (dummy_key) };
83 gnutls_openpgp_privkey_t key;
85 if (argc > 1)
87 gnutls_global_set_log_function (tls_log_func);
88 gnutls_global_set_log_level (9);
91 rc = gnutls_global_init ();
92 if (rc)
94 printf ("gnutls_global_init rc %d: %s\n", rc, gnutls_strerror (rc));
95 return 1;
98 rc = gnutls_openpgp_privkey_init (&key);
99 if (rc)
101 printf ("gnutls_openpgp_privkey_init rc %d: %s\n",
102 rc, gnutls_strerror (rc));
103 return 1;
106 rc = gnutls_openpgp_privkey_import (key, &keydatum,
107 GNUTLS_OPENPGP_FMT_BASE64, NULL, 0);
108 if (rc)
110 printf ("gnutls_openpgp_privkey_import rc %d: %s\n",
111 rc, gnutls_strerror (rc));
112 return 1;
115 gnutls_openpgp_privkey_deinit (key);
117 gnutls_global_deinit ();
119 return 0;