]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added gnutls_load_file().
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 21 Jun 2012 19:24:16 +0000 (21:24 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 21 Jun 2012 19:24:16 +0000 (21:24 +0200)
NEWS
lib/gnutls_ui.c
lib/includes/gnutls/gnutls.h.in

diff --git a/NEWS b/NEWS
index ae082e3c68992e6e35fdf023c602cda92ddbcde5..5977a21427c9d8fa787f7b331b6f56962c38bf3c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,7 @@ by Alexandre Bique.
 
 ** API and ABI modifications:
 GNUTLS_CERT_SIGNATURE_FAILURE: Added
+gnutls_load_file: Added
 gnutls_pubkey_verify_hash2: Added
 gnutls_pkcs12_simple_parse: Added
 gnutls_certificate_set_x509_system_trust: Added
index ac822a56ffc360a6d230952b6f3ad78b8d17698c..e254d228f4fc2538f85700af0f67195b42d6274d 100644 (file)
@@ -34,6 +34,7 @@
 #include <gnutls_state.h>
 #include <gnutls_datum.h>
 #include <extras/randomart.h>
+#include <read-file.h>
 
 /**
  * gnutls_random_art:
@@ -735,3 +736,37 @@ gnutls_anon_set_params_function (gnutls_anon_server_credentials_t res,
 {
   res->params_func = func;
 }
+
+/**
+ * gnutls_load_file:
+ * @filename: the name of the file to load
+ * @data: Where the file will be stored
+ *
+ * This function will load a file into a datum.
+ * The returned data are allocated using gnutls_malloc().
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
+ *   an error code is returned.
+ *
+ **/
+int gnutls_load_file(const char* filename, gnutls_datum_t * data)
+{
+size_t len;
+
+  data->data = (void*)read_binary_file(filename, &len);
+  if (data->data == NULL)
+    return GNUTLS_E_FILE_ERROR;
+  
+  if (malloc != gnutls_malloc)
+    {
+      void* tmp = gnutls_malloc(len);
+      
+      memcpy(tmp, data->data, len);
+      free(data->data);
+      data->data = tmp;
+    }
+  
+  data->size = len;
+  
+  return 0;
+}
index 3885e565760321f7a318c107fd4d92172e2fa451..d0ff2d00c4619d2e4ef0bcf1a3a017f97f6a44ea 100644 (file)
@@ -1735,6 +1735,8 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t session);
                           time_t expiration,
                           unsigned int flags);
 
+  /* Other help functions */
+int gnutls_load_file(const char* filename, gnutls_datum_t * data);
 
   /* Gnutls error codes. The mapping to a TLS alert is also shown in
    * comments.