From: Simon Josefsson Date: Fri, 4 Dec 2009 12:36:58 +0000 (+0100) Subject: Improve example of printing cert info. X-Git-Tag: gnutls_2_9_10~185 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8d7fd3776ca104cf92a8ebae05ef7a270bd8e95b;p=thirdparty%2Fgnutls.git Improve example of printing cert info. --- diff --git a/doc/examples/ex-x509-info.c b/doc/examples/ex-x509-info.c index 6e575c3d36..aaddb47913 100644 --- a/doc/examples/ex-x509-info.c +++ b/doc/examples/ex-x509-info.c @@ -39,13 +39,14 @@ void print_x509_certificate_info (gnutls_session_t session) { char serial[40]; - char dn[128]; + char dn[256]; size_t size; unsigned int algo, bits; time_t expiration_time, activation_time; const gnutls_datum_t *cert_list; unsigned int cert_list_size = 0; gnutls_x509_crt_t cert; + gnutls_datum_t cinfo; /* This function only works for X.509 certificates. */ @@ -58,6 +59,7 @@ print_x509_certificate_info (gnutls_session_t session) if (cert_list_size > 0) { + int ret; /* we only print information about the first certificate. */ @@ -67,6 +69,19 @@ print_x509_certificate_info (gnutls_session_t session) printf ("Certificate info:\n"); + /* This is the preferred way of printing short information about + a certificate. */ + + ret = gnutls_x509_crt_print (cert, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + if (ret == 0) + { + printf ("\t%s\n", cinfo.data); + gnutls_free (cinfo.data); + } + + /* If you want to extract fields manually for some other reason, + below are popular example calls. */ + expiration_time = gnutls_x509_crt_get_expiration_time (cert); activation_time = gnutls_x509_crt_get_activation_time (cert); @@ -87,7 +102,7 @@ print_x509_certificate_info (gnutls_session_t session) printf ("Certificate public key: %s", gnutls_pk_algorithm_get_name (algo)); - /* Print the version of the X.509 + /* Print the version of the X.509 * certificate. */ printf ("\tCertificate version: #%d\n",