From: Nikos Mavrogiannopoulos Date: Thu, 21 Jun 2012 19:24:16 +0000 (+0200) Subject: Added gnutls_load_file(). X-Git-Tag: gnutls_3_0_21~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0aaf3e813aaa010937297fa8b30856e7d04526d5;p=thirdparty%2Fgnutls.git Added gnutls_load_file(). --- diff --git a/NEWS b/NEWS index ae082e3c68..5977a21427 100644 --- 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 diff --git a/lib/gnutls_ui.c b/lib/gnutls_ui.c index ac822a56ff..e254d228f4 100644 --- a/lib/gnutls_ui.c +++ b/lib/gnutls_ui.c @@ -34,6 +34,7 @@ #include #include #include +#include /** * 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; +} diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in index 3885e56576..d0ff2d00c4 100644 --- a/lib/includes/gnutls/gnutls.h.in +++ b/lib/includes/gnutls/gnutls.h.in @@ -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.