We reverted the ABI bump.
[gnutls.git] / lib / debug.c
blobef5a4af6017e0760a61f8627196114f803ce7185
1 /*
2 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GNUTLS.
8 * The GNUTLS 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 2.1 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
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 * USA
25 #include "gnutls_int.h"
26 #include "gnutls_errors.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <gcrypt.h>
31 #ifdef DEBUG
34 void
35 _gnutls_print_state (gnutls_session_t session)
38 _gnutls_debug_log ("GNUTLS State:\n");
39 _gnutls_debug_log ("Connection End: %d\n",
40 session->security_parameters.entity);
41 _gnutls_debug_log ("Cipher Algorithm: %d\n",
42 session->security_parameters.read_bulk_cipher_algorithm);
43 _gnutls_debug_log ("MAC algorithm: %d\n",
44 session->security_parameters.read_mac_algorithm);
45 _gnutls_debug_log ("Compression Algorithm: %d\n",
46 session->security_parameters.read_compression_algorithm);
47 _gnutls_debug_log ("\n");
51 #endif
53 const char *
54 _gnutls_packet2str (content_type_t packet)
56 switch (packet)
58 case GNUTLS_CHANGE_CIPHER_SPEC:
59 return "Change Cipher Spec";
60 case GNUTLS_ALERT:
61 return "Alert";
62 case GNUTLS_HANDSHAKE:
63 return "Handshake";
64 case GNUTLS_APPLICATION_DATA:
65 return "Application Data";
66 case GNUTLS_INNER_APPLICATION:
67 return "Inner Application";
69 default:
70 return "Unknown Packet";
74 const char *
75 _gnutls_handshake2str (gnutls_handshake_description_t handshake)
78 switch (handshake)
80 case GNUTLS_HANDSHAKE_HELLO_REQUEST:
81 return "HELLO REQUEST";
82 break;
83 case GNUTLS_HANDSHAKE_CLIENT_HELLO:
84 return "CLIENT HELLO";
85 break;
86 case GNUTLS_HANDSHAKE_SERVER_HELLO:
87 return "SERVER HELLO";
88 break;
89 case GNUTLS_HANDSHAKE_CERTIFICATE_PKT:
90 return "CERTIFICATE";
91 break;
92 case GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE:
93 return "SERVER KEY EXCHANGE";
94 break;
95 case GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST:
96 return "CERTIFICATE REQUEST";
97 break;
98 case GNUTLS_HANDSHAKE_SERVER_HELLO_DONE:
99 return "SERVER HELLO DONE";
100 break;
101 case GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY:
102 return "CERTIFICATE VERIFY";
103 break;
104 case GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE:
105 return "CLIENT KEY EXCHANGE";
106 break;
107 case GNUTLS_HANDSHAKE_FINISHED:
108 return "FINISHED";
109 break;
110 case GNUTLS_HANDSHAKE_SUPPLEMENTAL:
111 return "SUPPLEMENTAL";
112 break;
113 default:
114 return "Unknown Handshake packet";
119 void
120 _gnutls_dump_mpi (const char *prefix, mpi_t a)
122 opaque buf[1024];
123 size_t n = sizeof buf;
125 if (gcry_mpi_print (GCRYMPI_FMT_HEX, buf, n, &n, a))
126 strcpy (buf, "[can't print value]"); /* Flawfinder: ignore */
127 _gnutls_hard_log ("MPI: length: %d\n\t%s%s\n", (n - 1) / 2, prefix, buf);