diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-07-02 15:24:05 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-07-02 15:24:05 +0200 |
commit | bade988016aa5d2936c6bdf53570125181cfe2f9 (patch) | |
tree | 65948be9cd75ccfb8fd2a6c26ad15caed4119cc5 /lib/openpgp/output.c | |
parent | 36f07088e2979bf28e52fec4992d3da04e73eb6c (diff) | |
download | gnutls-bade988016aa5d2936c6bdf53570125181cfe2f9.tar.gz |
Indent code.
Diffstat (limited to 'lib/openpgp/output.c')
-rw-r--r-- | lib/openpgp/output.c | 374 |
1 files changed, 191 insertions, 183 deletions
diff --git a/lib/openpgp/output.c b/lib/openpgp/output.c index e05c3ff94d..027f27ce06 100644 --- a/lib/openpgp/output.c +++ b/lib/openpgp/output.c @@ -76,7 +76,8 @@ hexprint (gnutls_string * str, const char *data, size_t len) } static void -print_key_usage (gnutls_string * str, gnutls_openpgp_crt_t cert, unsigned int idx) +print_key_usage (gnutls_string * str, gnutls_openpgp_crt_t cert, + unsigned int idx) { unsigned int key_usage; int err; @@ -84,7 +85,7 @@ print_key_usage (gnutls_string * str, gnutls_openpgp_crt_t cert, unsigned int id addf (str, _("\t\tKey Usage:\n")); - if (idx == (unsigned int)-1) + if (idx == (unsigned int) -1) err = gnutls_openpgp_crt_get_key_usage (cert, &key_usage); else err = gnutls_openpgp_crt_get_subkey_usage (cert, idx, &key_usage); @@ -112,22 +113,22 @@ print_key_usage (gnutls_string * str, gnutls_openpgp_crt_t cert, unsigned int id static void print_key_id (gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) { - gnutls_openpgp_keyid_t id; - int err; + gnutls_openpgp_keyid_t id; + int err; - if (idx < 0) - err = gnutls_openpgp_crt_get_key_id (cert, id); - else - err = gnutls_openpgp_crt_get_subkey_id( cert, idx, id); + if (idx < 0) + err = gnutls_openpgp_crt_get_key_id (cert, id); + else + err = gnutls_openpgp_crt_get_subkey_id (cert, idx, id); - if (err < 0) - addf (str, "error: get_key_id: %s\n", gnutls_strerror (err)); - else - { - addf (str, _("\tID (hex): ")); - hexprint (str, id, sizeof(id)); - addf (str, "\n"); - } + if (err < 0) + addf (str, "error: get_key_id: %s\n", gnutls_strerror (err)); + else + { + addf (str, _("\tID (hex): ")); + hexprint (str, id, sizeof (id)); + addf (str, "\n"); + } } /* idx == -1 indicates main key @@ -136,181 +137,185 @@ print_key_id (gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) static void print_key_fingerprint (gnutls_string * str, gnutls_openpgp_crt_t cert) { - char fpr[128]; - size_t fpr_size = sizeof (fpr); - int err; + char fpr[128]; + size_t fpr_size = sizeof (fpr); + int err; - err = gnutls_openpgp_crt_get_fingerprint (cert, fpr, &fpr_size); - if (err < 0) - addf (str, "error: get_fingerprint: %s\n", gnutls_strerror (err)); - else - { - addf (str, _("\tFingerprint (hex): ")); - hexprint (str, fpr, fpr_size); - addf (str, "\n"); - } + err = gnutls_openpgp_crt_get_fingerprint (cert, fpr, &fpr_size); + if (err < 0) + addf (str, "error: get_fingerprint: %s\n", gnutls_strerror (err)); + else + { + addf (str, _("\tFingerprint (hex): ")); + hexprint (str, fpr, fpr_size); + addf (str, "\n"); + } } static void print_key_revoked (gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) { - int err; + int err; - if (idx < 0) - err = gnutls_openpgp_crt_get_revoked_status (cert); - else - err = gnutls_openpgp_crt_get_subkey_revoked_status( cert, idx); + if (idx < 0) + err = gnutls_openpgp_crt_get_revoked_status (cert); + else + err = gnutls_openpgp_crt_get_subkey_revoked_status (cert, idx); - if (err != 0) - addf (str, _("\tRevoked: True\n")); - else - addf (str, _("\tRevoked: False\n")); + if (err != 0) + addf (str, _("\tRevoked: True\n")); + else + addf (str, _("\tRevoked: False\n")); } static void -print_key_times(gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) +print_key_times (gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) { - time_t tim; + time_t tim; - addf (str, _("\tTime stamps:\n")); + addf (str, _("\tTime stamps:\n")); - if (idx == -1) - tim = gnutls_openpgp_crt_get_creation_time (cert); + if (idx == -1) + tim = gnutls_openpgp_crt_get_creation_time (cert); + else + tim = gnutls_openpgp_crt_get_subkey_creation_time (cert, idx); + + { + char s[42]; + size_t max = sizeof (s); + struct tm t; + + if (gmtime_r (&tim, &t) == NULL) + addf (str, "error: gmtime_r (%d)\n", t); + else if (strftime (s, max, "%a %b %e %H:%M:%S UTC %Y", &t) == 0) + addf (str, "error: strftime (%d)\n", t); else - tim = gnutls_openpgp_crt_get_subkey_creation_time (cert, idx); - - { - char s[42]; - size_t max = sizeof (s); - struct tm t; - - if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); - else if (strftime (s, max, "%a %b %e %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); - else - addf (str, _("\t\tCreation: %s\n"), s); - } + addf (str, _("\t\tCreation: %s\n"), s); + } - if (idx == -1) - tim = gnutls_openpgp_crt_get_expiration_time (cert); + if (idx == -1) + tim = gnutls_openpgp_crt_get_expiration_time (cert); + else + tim = gnutls_openpgp_crt_get_subkey_expiration_time (cert, idx); + { + char s[42]; + size_t max = sizeof (s); + struct tm t; + + if (tim == 0) + { + addf (str, _("\t\tExpiration: Never\n"), s); + } else - tim = gnutls_openpgp_crt_get_subkey_expiration_time (cert, idx); - { - char s[42]; - size_t max = sizeof (s); - struct tm t; - - if (tim == 0) - { - addf (str, _("\t\tExpiration: Never\n"), s); - } - else - { - if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); - else if (strftime (s, max, "%a %b %e %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); - else - addf (str, _("\t\tExpiration: %s\n"), s); - } - } + { + if (gmtime_r (&tim, &t) == NULL) + addf (str, "error: gmtime_r (%d)\n", t); + else if (strftime (s, max, "%a %b %e %H:%M:%S UTC %Y", &t) == 0) + addf (str, "error: strftime (%d)\n", t); + else + addf (str, _("\t\tExpiration: %s\n"), s); + } + } } static void -print_key_info(gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) +print_key_info (gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) { - int err; - unsigned int bits; + int err; + unsigned int bits; - if (idx == -1) - err = gnutls_openpgp_crt_get_pk_algorithm (cert, &bits); - else - err = gnutls_openpgp_crt_get_subkey_pk_algorithm (cert, idx, &bits); + if (idx == -1) + err = gnutls_openpgp_crt_get_pk_algorithm (cert, &bits); + else + err = gnutls_openpgp_crt_get_subkey_pk_algorithm (cert, idx, &bits); - if (err < 0) - addf (str, "error: get_pk_algorithm: %s\n", gnutls_strerror (err)); - else - { - const char *name = gnutls_pk_algorithm_get_name (err); - if (name == NULL) - name = _("unknown"); + if (err < 0) + addf (str, "error: get_pk_algorithm: %s\n", gnutls_strerror (err)); + else + { + const char *name = gnutls_pk_algorithm_get_name (err); + if (name == NULL) + name = _("unknown"); - addf (str, _("\tPublic Key Algorithm: %s\n"), name); - switch (err) + addf (str, _("\tPublic Key Algorithm: %s\n"), name); + switch (err) + { + case GNUTLS_PK_RSA: { - case GNUTLS_PK_RSA: - { - gnutls_datum_t m, e; - - if (idx == -1) - err = gnutls_openpgp_crt_get_pk_rsa_raw (cert, &m, &e); - else - err = gnutls_openpgp_crt_get_subkey_pk_rsa_raw (cert, idx, &m, &e); - - if (err < 0) - addf (str, "error: get_pk_rsa_raw: %s\n", - gnutls_strerror (err)); - else - { - addf (str, _("\t\tModulus (bits %d):\n"), bits); - hexdump (str, m.data, m.size, "\t\t\t"); - addf (str, _("\t\tExponent:\n")); - hexdump (str, e.data, e.size, "\t\t\t"); - - gnutls_free (m.data); - gnutls_free (e.data); - } - - } - break; - - case GNUTLS_PK_DSA: - { - gnutls_datum_t p, q, g, y; - - if (idx == -1) - err = gnutls_openpgp_crt_get_pk_dsa_raw (cert, &p, &q, &g, &y); - else - err = gnutls_openpgp_crt_get_subkey_pk_dsa_raw (cert, idx, &p, &q, &g, &y); - if (err < 0) - addf (str, "error: get_pk_dsa_raw: %s\n", - gnutls_strerror (err)); - else - { - addf (str, _("\t\tPublic key (bits %d):\n"), bits); - hexdump (str, y.data, y.size, "\t\t\t"); - addf (str, _("\t\tP:\n")); - hexdump (str, p.data, p.size, "\t\t\t"); - addf (str, _("\t\tQ:\n")); - hexdump (str, q.data, q.size, "\t\t\t"); - addf (str, _("\t\tG:\n")); - hexdump (str, g.data, g.size, "\t\t\t"); - - gnutls_free (p.data); - gnutls_free (q.data); - gnutls_free (g.data); - gnutls_free (y.data); - } - } - break; - - default: - break; + gnutls_datum_t m, e; + + if (idx == -1) + err = gnutls_openpgp_crt_get_pk_rsa_raw (cert, &m, &e); + else + err = + gnutls_openpgp_crt_get_subkey_pk_rsa_raw (cert, idx, &m, &e); + + if (err < 0) + addf (str, "error: get_pk_rsa_raw: %s\n", + gnutls_strerror (err)); + else + { + addf (str, _("\t\tModulus (bits %d):\n"), bits); + hexdump (str, m.data, m.size, "\t\t\t"); + addf (str, _("\t\tExponent:\n")); + hexdump (str, e.data, e.size, "\t\t\t"); + + gnutls_free (m.data); + gnutls_free (e.data); + } + } - } + break; + + case GNUTLS_PK_DSA: + { + gnutls_datum_t p, q, g, y; + + if (idx == -1) + err = gnutls_openpgp_crt_get_pk_dsa_raw (cert, &p, &q, &g, &y); + else + err = + gnutls_openpgp_crt_get_subkey_pk_dsa_raw (cert, idx, &p, &q, + &g, &y); + if (err < 0) + addf (str, "error: get_pk_dsa_raw: %s\n", + gnutls_strerror (err)); + else + { + addf (str, _("\t\tPublic key (bits %d):\n"), bits); + hexdump (str, y.data, y.size, "\t\t\t"); + addf (str, _("\t\tP:\n")); + hexdump (str, p.data, p.size, "\t\t\t"); + addf (str, _("\t\tQ:\n")); + hexdump (str, q.data, q.size, "\t\t\t"); + addf (str, _("\t\tG:\n")); + hexdump (str, g.data, g.size, "\t\t\t"); + + gnutls_free (p.data); + gnutls_free (q.data); + gnutls_free (g.data); + gnutls_free (y.data); + } + } + break; + + default: + break; + } + } } static void -print_cert (gnutls_string * str, gnutls_openpgp_crt_t cert, unsigned int format) +print_cert (gnutls_string * str, gnutls_openpgp_crt_t cert, + unsigned int format) { -int i, subkeys; -int err; -char dn[1024]; -size_t dn_size; + int i, subkeys; + int err; + char dn[1024]; + size_t dn_size; - print_key_revoked( str, cert, -1); + print_key_revoked (str, cert, -1); /* Version. */ { @@ -322,14 +327,15 @@ size_t dn_size; } /* ID. */ - print_key_id( str, cert, -1); + print_key_id (str, cert, -1); - print_key_fingerprint( str, cert); + print_key_fingerprint (str, cert); /* Names. */ i = 0; - do { - dn_size = sizeof(dn); + do + { + dn_size = sizeof (dn); err = gnutls_openpgp_crt_get_name (cert, i++, dn, &dn_size); if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE && @@ -340,31 +346,34 @@ size_t dn_size; } if (err >= 0) - addf (str, _("\tName[%d]: %s\n"), i-1, dn); - else if (err == GNUTLS_E_OPENPGP_UID_REVOKED) { - addf (str, _("\tRevoked Name[%d]: %s\n"), i-1, dn); - } + addf (str, _("\tName[%d]: %s\n"), i - 1, dn); + else if (err == GNUTLS_E_OPENPGP_UID_REVOKED) + { + addf (str, _("\tRevoked Name[%d]: %s\n"), i - 1, dn); + } - } while( err >= 0); + } + while (err >= 0); - print_key_times( str, cert, -1); + print_key_times (str, cert, -1); - print_key_info( str, cert, -1); - print_key_usage( str, cert, -1); + print_key_info (str, cert, -1); + print_key_usage (str, cert, -1); - subkeys = gnutls_openpgp_crt_get_subkey_count( cert); + subkeys = gnutls_openpgp_crt_get_subkey_count (cert); if (subkeys < 0) return; - for (i=0;i<subkeys;i++) { - addf( str, _("\n\tSubkey[%d]:\n"), i); + for (i = 0; i < subkeys; i++) + { + addf (str, _("\n\tSubkey[%d]:\n"), i); - print_key_revoked( str, cert, i); - print_key_id( str, cert, i); - print_key_times( str, cert, i); - print_key_info( str, cert, i); - print_key_usage( str, cert, i); - } + print_key_revoked (str, cert, i); + print_key_id (str, cert, i); + print_key_times (str, cert, i); + print_key_info (str, cert, i); + print_key_usage (str, cert, i); + } } @@ -385,8 +394,8 @@ size_t dn_size; **/ int gnutls_openpgp_crt_print (gnutls_openpgp_crt_t cert, - gnutls_certificate_print_formats_t format, - gnutls_datum_t *out) + gnutls_certificate_print_formats_t format, + gnutls_datum_t * out) { gnutls_string str; @@ -402,4 +411,3 @@ gnutls_openpgp_crt_print (gnutls_openpgp_crt_t cert, return 0; } - |