]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added gnutls_pkcs7_get_crl_raw2
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 2 Jun 2015 09:13:41 +0000 (11:13 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 2 Jun 2015 09:13:41 +0000 (11:13 +0200)
lib/includes/gnutls/pkcs7.h
lib/libgnutls.map
lib/x509/pkcs7.c

index 7955dd601a2c1726cca711992cc8417207012d6d..fdf61df26a9a218d00665efd5781d53675028e1f 100644 (file)
@@ -94,6 +94,9 @@ int gnutls_pkcs7_verify(gnutls_pkcs7_t pkcs7, gnutls_x509_trust_list_t tl,
 int
 gnutls_pkcs7_get_crt_raw2(gnutls_pkcs7_t pkcs7,
                         int indx, gnutls_datum_t *cert);
+int
+gnutls_pkcs7_get_crl_raw2(gnutls_pkcs7_t pkcs7,
+                         int indx, gnutls_datum_t *crl);
 
 
 /* *INDENT-OFF* */
index 2c5a645ad247a3ea77bf0deb063313afca596e18..6f8d97ffca01ccb6f80b7f0b17326309cf003ff3 100644 (file)
@@ -1032,6 +1032,7 @@ GNUTLS_3_4
        gnutls_pkcs7_get_signature_info;
        gnutls_pkcs7_verify_direct;
        gnutls_pkcs7_verify;
+       gnutls_pkcs7_get_crl_raw2;
  local:
        *;
 };
index 781d21b3506231555334819f17a38d58ca9f7858..a25a4c649ba8fb1939d7d7b2891a2efb381b40a9 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2003-2012 Free Software Foundation, Inc.
+ * Copyright (C) 2003-2015 Free Software Foundation, Inc.
+ * Copyright (C) 2015 Red Hat, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -1346,23 +1347,20 @@ int gnutls_pkcs7_delete_crt(gnutls_pkcs7_t pkcs7, int indx)
  */
 
 /**
- * gnutls_pkcs7_get_crl_raw:
+ * gnutls_pkcs7_get_crl_raw2:
  * @pkcs7: The pkcs7 type
  * @indx: contains the index of the crl to extract
- * @crl: the contents of the crl will be copied there (may be null)
- * @crl_size: should hold the size of the crl
+ * @crl: will contain the contents of the CRL in an allocated buffer
  *
- * This function will return a crl of the PKCS7 or RFC2630 crl set.
+ * This function will return a DER encoded CRL of the PKCS7 or RFC2630 crl set.
  *
  * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
- *   negative error value.  If the provided buffer is not long enough,
- *   then @crl_size is updated and %GNUTLS_E_SHORT_MEMORY_BUFFER is
- *   returned.  After the last crl has been read
+ *   negative error value.  After the last crl has been read
  *   %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.
  **/
 int
-gnutls_pkcs7_get_crl_raw(gnutls_pkcs7_t pkcs7,
-                        int indx, void *crl, size_t * crl_size)
+gnutls_pkcs7_get_crl_raw2(gnutls_pkcs7_t pkcs7,
+                         int indx, gnutls_datum_t *crl)
 {
        int result;
        char root2[ASN1_MAX_NAME_SIZE];
@@ -1396,22 +1394,52 @@ gnutls_pkcs7_get_crl_raw(gnutls_pkcs7_t pkcs7,
 
        end = end - start + 1;
 
-       if ((unsigned) end > *crl_size) {
-               *crl_size = end;
-               result = GNUTLS_E_SHORT_MEMORY_BUFFER;
+       result = _gnutls_set_datum(crl, &tmp.data[start], end);
+
+      cleanup:
+       _gnutls_free_datum(&tmp);
+       return result;
+}
+
+/**
+ * gnutls_pkcs7_get_crl_raw:
+ * @pkcs7: The pkcs7 type
+ * @indx: contains the index of the crl to extract
+ * @crl: the contents of the crl will be copied there (may be null)
+ * @crl_size: should hold the size of the crl
+ *
+ * This function will return a crl of the PKCS7 or RFC2630 crl set.
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
+ *   negative error value.  If the provided buffer is not long enough,
+ *   then @crl_size is updated and %GNUTLS_E_SHORT_MEMORY_BUFFER is
+ *   returned.  After the last crl has been read
+ *   %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.
+ **/
+int
+gnutls_pkcs7_get_crl_raw(gnutls_pkcs7_t pkcs7,
+                        int indx, void *crl, size_t * crl_size)
+{
+       int ret;
+       gnutls_datum_t tmp = {NULL, 0};
+
+       ret = gnutls_pkcs7_get_crl_raw2(pkcs7, indx, &tmp);
+       if (ret < 0)
+               return gnutls_assert_val(ret);
+
+       if ((unsigned) tmp.size > *crl_size) {
+               *crl_size = tmp.size;
+               ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
                goto cleanup;
        }
 
+       *crl_size = tmp.size;
        if (crl)
-               memcpy(crl, &tmp.data[start], end);
-
-       *crl_size = end;
-
-       result = 0;
+               memcpy(crl, tmp.data, tmp.size);
 
       cleanup:
        _gnutls_free_datum(&tmp);
-       return result;
+       return ret;
 }
 
 /**