aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2014-12-08 19:40:50 +0100
committerLars Magne Ingebrigtsen2014-12-08 19:40:50 +0100
commitc498441ee63747386e0055717d79b09f6d8a7209 (patch)
tree363623a36f4f2ebf73c3188420d487a296c344a6 /src
parent172bcf6f9f9ed99e59fba2c2e6c46f18a24d2ab4 (diff)
downloademacs-c498441ee63747386e0055717d79b09f6d8a7209.tar.gz
emacs-c498441ee63747386e0055717d79b09f6d8a7209.zip
(gnutls_certificate_details): Clean up whitespace slightly.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog1
-rw-r--r--src/gnutls.c182
2 files changed, 83 insertions, 100 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 0ed30a89dfa..70b1bb001a9 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -2,6 +2,7 @@
2 2
3 * gnutls.c (gnutls_certificate_details): The :signature isn't 3 * gnutls.c (gnutls_certificate_details): The :signature isn't
4 that useful, so remove it. 4 that useful, so remove it.
5 (gnutls_certificate_details): Clean up whitespace slightly.
5 6
62014-12-07 Jan Djärv <jan.h.d@swipnet.se> 72014-12-07 Jan Djärv <jan.h.d@swipnet.se>
7 8
diff --git a/src/gnutls.c b/src/gnutls.c
index 13730bd7a19..c4d85a2030e 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -797,6 +797,7 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
797{ 797{
798 Lisp_Object res = Qnil; 798 Lisp_Object res = Qnil;
799 int err; 799 int err;
800 size_t buf_size;
800 801
801 /* Version. */ 802 /* Version. */
802 { 803 {
@@ -807,37 +808,30 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
807 } 808 }
808 809
809 /* Serial. */ 810 /* Serial. */
810 { 811 buf_size = 0;
811 size_t serial_size = 0; 812 err = fn_gnutls_x509_crt_get_serial (cert, NULL, &buf_size);
812 813 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
813 err = fn_gnutls_x509_crt_get_serial (cert, NULL, &serial_size); 814 {
814 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 815 char *serial = malloc (buf_size);
815 { 816 err = fn_gnutls_x509_crt_get_serial (cert, serial, &buf_size);
816 char *serial = malloc (serial_size); 817 if (err >= GNUTLS_E_SUCCESS)
817 err = fn_gnutls_x509_crt_get_serial (cert, serial, &serial_size); 818 res = nconc2 (res, list2 (intern (":serial-number"),
818 if (err >= GNUTLS_E_SUCCESS) 819 gnutls_hex_string (serial, buf_size, "")));
819 res = nconc2 (res, list2 (intern (":serial-number"), 820 free (serial);
820 gnutls_hex_string (serial, serial_size, 821 }
821 "")));
822 free (serial);
823 }
824 }
825 822
826 /* Issuer. */ 823 /* Issuer. */
827 { 824 buf_size = 0;
828 size_t dn_size = 0; 825 err = fn_gnutls_x509_crt_get_issuer_dn (cert, NULL, &buf_size);
829 826 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
830 err = fn_gnutls_x509_crt_get_issuer_dn (cert, NULL, &dn_size); 827 {
831 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 828 char *dn = malloc (buf_size);
832 { 829 err = fn_gnutls_x509_crt_get_issuer_dn (cert, dn, &buf_size);
833 char *dn = malloc (dn_size); 830 if (err >= GNUTLS_E_SUCCESS)
834 err = fn_gnutls_x509_crt_get_issuer_dn (cert, dn, &dn_size); 831 res = nconc2 (res, list2 (intern (":issuer"),
835 if (err >= GNUTLS_E_SUCCESS) 832 make_string (dn, buf_size)));
836 res = nconc2 (res, list2 (intern (":issuer"), 833 free (dn);
837 make_string (dn, dn_size))); 834 }
838 free (dn);
839 }
840 }
841 835
842 /* Validity. */ 836 /* Validity. */
843 { 837 {
@@ -857,20 +851,17 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
857 } 851 }
858 852
859 /* Subject. */ 853 /* Subject. */
860 { 854 buf_size = 0;
861 size_t dn_size = 0; 855 err = fn_gnutls_x509_crt_get_dn (cert, NULL, &buf_size);
862 856 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
863 err = fn_gnutls_x509_crt_get_dn (cert, NULL, &dn_size); 857 {
864 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 858 char *dn = malloc (buf_size);
865 { 859 err = fn_gnutls_x509_crt_get_dn (cert, dn, &buf_size);
866 char *dn = malloc (dn_size); 860 if (err >= GNUTLS_E_SUCCESS)
867 err = fn_gnutls_x509_crt_get_dn (cert, dn, &dn_size); 861 res = nconc2 (res, list2 (intern (":subject"),
868 if (err >= GNUTLS_E_SUCCESS) 862 make_string (dn, buf_size)));
869 res = nconc2 (res, list2 (intern (":subject"), 863 free (dn);
870 make_string (dn, dn_size))); 864 }
871 free (dn);
872 }
873 }
874 865
875 /* Versions older than 2.11 doesn't have these four functions. */ 866 /* Versions older than 2.11 doesn't have these four functions. */
876#if GNUTLS_VERSION_NUMBER >= 0x020b00 867#if GNUTLS_VERSION_NUMBER >= 0x020b00
@@ -894,69 +885,60 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
894 } 885 }
895 886
896 /* Unique IDs. */ 887 /* Unique IDs. */
897 { 888 buf_size = 0;
898 size_t buf_size = 0; 889 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, NULL, &buf_size);
899 890 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
900 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, NULL, &buf_size); 891 {
901 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 892 char *buf = malloc (buf_size);
902 { 893 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, buf, &buf_size);
903 char *buf = malloc (buf_size); 894 if (err >= GNUTLS_E_SUCCESS)
904 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, buf, &buf_size); 895 res = nconc2 (res, list2 (intern (":issuer-unique-id"),
905 if (err >= GNUTLS_E_SUCCESS) 896 make_string (buf, buf_size)));
906 res = nconc2 (res, list2 (intern (":issuer-unique-id"), 897 free (buf);
907 make_string (buf, buf_size))); 898 }
908 free (buf);
909 }
910 899
911 buf_size = 0; 900 buf_size = 0;
912 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, NULL, &buf_size); 901 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, NULL, &buf_size);
913 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 902 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
914 { 903 {
915 char *buf = malloc (buf_size); 904 char *buf = malloc (buf_size);
916 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, buf, &buf_size); 905 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, buf, &buf_size);
917 if (err >= GNUTLS_E_SUCCESS) 906 if (err >= GNUTLS_E_SUCCESS)
918 res = nconc2 (res, list2 (intern (":subject-unique-id"), 907 res = nconc2 (res, list2 (intern (":subject-unique-id"),
919 make_string (buf, buf_size))); 908 make_string (buf, buf_size)));
920 free (buf); 909 free (buf);
921 } 910 }
922 }
923#endif 911#endif
924 912
925 /* Public key ID. */ 913 /* Public key ID. */
926 { 914 buf_size = 0;
927 size_t buf_size = 0; 915 err = fn_gnutls_x509_crt_get_key_id (cert, 0, NULL, &buf_size);
928 916 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
929 err = fn_gnutls_x509_crt_get_key_id (cert, 0, NULL, &buf_size); 917 {
930 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 918 unsigned char *buf = malloc (buf_size);
931 { 919 err = fn_gnutls_x509_crt_get_key_id (cert, 0, buf, &buf_size);
932 unsigned char *buf = malloc (buf_size); 920 if (err >= GNUTLS_E_SUCCESS)
933 err = fn_gnutls_x509_crt_get_key_id (cert, 0, buf, &buf_size); 921 res = nconc2 (res, list2 (intern (":public-key-id"),
934 if (err >= GNUTLS_E_SUCCESS) 922 gnutls_hex_string ((char *)buf,
935 res = nconc2 (res, list2 (intern (":public-key-id"), 923 buf_size, "sha1:")));
936 gnutls_hex_string ((char *)buf, 924 free (buf);
937 buf_size, "sha1:"))); 925 }
938 free (buf);
939 }
940 }
941 926
942 /* Certificate fingerprint. */ 927 /* Certificate fingerprint. */
943 { 928 buf_size = 0;
944 size_t buf_size = 0; 929 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1,
945 930 NULL, &buf_size);
946 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, 931 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
947 NULL, &buf_size); 932 {
948 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) 933 unsigned char *buf = malloc (buf_size);
949 { 934 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1,
950 unsigned char *buf = malloc (buf_size); 935 buf, &buf_size);
951 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, 936 if (err >= GNUTLS_E_SUCCESS)
952 buf, &buf_size); 937 res = nconc2 (res, list2 (intern (":certificate-id"),
953 if (err >= GNUTLS_E_SUCCESS) 938 gnutls_hex_string ((char *)buf,
954 res = nconc2 (res, list2 (intern (":certificate-id"), 939 buf_size, "sha1:")));
955 gnutls_hex_string ((char *)buf, 940 free (buf);
956 buf_size, "sha1:"))); 941 }
957 free (buf);
958 }
959 }
960 942
961 return res; 943 return res;
962} 944}