summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--lib/gnutls_ui.h3
-rw-r--r--lib/x509_b64.c64
3 files changed, 67 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 215a9b3acc..73d479bc6c 100644
--- 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
diff --git a/lib/gnutls_ui.h b/lib/gnutls_ui.h
index 1dd4dc1ea0..237de35d25 100644
--- a/lib/gnutls_ui.h
+++ b/lib/gnutls_ui.h
@@ -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 */
diff --git a/lib/x509_b64.c b/lib/x509_b64.c
index 4ca3e8c3dc..899f57ca3a 100644
--- a/lib/x509_b64.c
+++ b/lib/x509_b64.c
@@ -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
*/