]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added gnutls_b64_encode() and gnutls_b64_decode()
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 5 Jan 2002 13:40:44 +0000 (13:40 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 5 Jan 2002 13:40:44 +0000 (13:40 +0000)
NEWS
lib/gnutls_ui.h
lib/x509_b64.c

diff --git a/NEWS b/NEWS
index 215a9b3acca784fde7a719b0312d8204e02e9343..73d479bc6c5dd60e4dcee764a5162284c4270bc0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Version ?.?.?
 - Corrected bug which did not allow a client to accept multiple CA names
 - Added gnutls_fingerprint()
 - Added gnutls_x509pki_extract_certificate_serial()
+- Added gnutls_b64_encode() and gnutls_b64_decode()
 - Corrected behaviour in version advertizing
 - Updated documentation
 
index 1dd4dc1ea0465799b29666a58695667c42f187aa..237de35d25429ce13af35ff7e0e73b4594c717e8 100644 (file)
@@ -89,6 +89,9 @@ int gnutls_x509pki_get_peer_certificate_status( GNUTLS_STATE);
 #define gnutls_x509pki_client_get_peer_certificate_status gnutls_x509pki_get_peer_certificate_status
 #define gnutls_x509pki_client_get_peer_certificate_list gnutls_x509pki_get_peer_certificate_list
 
+int gnutls_b64_encode( const char* msg, const gnutls_datum *data, char* result, int* result_size);
+int gnutls_b64_decode( const gnutls_datum *b64_data, char* result, int* result_size);
+
 # endif /* LIBGNUTLS_VERSION */
 
 #endif /* GNUTLS_UI_H */
index 4ca3e8c3dc2afd1bb2828eb0c7fd6f722cf1b9d3..899f57ca3a7bfbbdd1af68aed118d30ee145e017 100644 (file)
@@ -160,10 +160,42 @@ int _gnutls_base64_encode(uint8 * data, int data_size, uint8 ** result)
        return ret;
 }
 
+/**
+  * gnutls_b64_encode - This function will convert DER data to Base64 encoded
+  * @msg: is a message to be put in the header
+  * @data: contain the DER data
+  * @result: the place where base64 data will be copied
+  * @result_size: holds the size of the result
+  *
+  * This function will convert the given data to printable data, using the base64 
+  * encoding.
+  * 
+  **/
+int gnutls_b64_encode( const char* msg, const gnutls_datum *data, char* result, int* result_size) {
+opaque* ret;
+int size;
+
+       size = _gnutls_fbase64_encode( msg, pem_data->data, pem_data->size, &ret);
+       if (size < 0)
+               return size;
+
+       if (result==NULL || *result_size < size) {
+               gnutls_free(ret);
+               *result_size = size;
+               return GNUTLS_E_INVALID_REQUEST;
+       } else {
+               memcpy( result, ret, size);
+               gnutls_free(ret);
+               *result_size = size;
+       }
+
+       return 0;
+}
+
 /* encodes data and puts the result into result (localy alocated)
  * The result_size is the return value
  */
-int _gnutls_fbase64_encode(char *msg, uint8 * data, int data_size,
+int _gnutls_fbase64_encode(const char *msg, const uint8 * data, int data_size,
                           uint8 ** result)
 {
        int i, ret, tmp, j;
@@ -294,6 +326,36 @@ inline static int cpydata(uint8 * data, int data_size, uint8 ** result)
        return j;
 }
 
+/**
+  * gnutls_b64_decode - This function will decode base64 encoded data
+  * @b64_data: contain the encoded data
+  * @result: the place where decoded data will be copied
+  * @result_size: holds the size of the result
+  *
+  * This function will decode the given encoded data.
+  * 
+  **/
+int gnutls_b64_decode( const gnutls_datum *b64_data, char* result, int* result_size) {
+opaque* ret;
+int size;
+
+       size = _gnutls_fbase64_decode( pem_data->data, pem_data->size, &ret);
+       if (size < 0)
+               return size;
+
+       if (result==NULL || *result_size < size) {
+               gnutls_free(ret);
+               *result_size = size;
+               return GNUTLS_E_INVALID_REQUEST;
+       } else {
+               memcpy( result, ret, size);
+               gnutls_free(ret);
+               *result_size = size;
+       }
+
+       return 0;
+}
+
 /* decodes data and puts the result into result (localy alocated)
  * The result_size is the return value
  */