diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-06 18:09:14 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-07 10:55:17 +0200 |
commit | f971a1da022ef9cf0e5455780a790ff2ad287fbb (patch) | |
tree | e0a3f66e7e052f40cbded67ca9333dc4b78709b0 | |
parent | 9500890deeecfa32da53559f1afa6cbd985fa6d9 (diff) | |
download | gnutls-f971a1da022ef9cf0e5455780a790ff2ad287fbb.tar.gz |
gnutls_pem_base64_encode2: do raw base64 when msg is NULL
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r-- | lib/x509/output.c | 1 | ||||
-rw-r--r-- | lib/x509_b64.c | 50 |
2 files changed, 31 insertions, 20 deletions
diff --git a/lib/x509/output.c b/lib/x509/output.c index e006db233c..e071c14031 100644 --- a/lib/x509/output.c +++ b/lib/x509/output.c @@ -30,7 +30,6 @@ #include <x509_int.h> #include <num.h> #include "errors.h" -#include <extras/randomart.h> #include "extensions.h" #include "ip.h" diff --git a/lib/x509_b64.c b/lib/x509_b64.c index f60d4d08d0..e5a741a868 100644 --- a/lib/x509_b64.c +++ b/lib/x509_b64.c @@ -53,23 +53,25 @@ _gnutls_fbase64_encode(const char *msg, const uint8_t * data, char top[80]; char bottom[80]; size_t size, max, bytes; - int pos, top_len, bottom_len; + int pos, top_len = 0, bottom_len = 0; - if (msg == NULL || strlen(msg) > 50) { - gnutls_assert(); - return GNUTLS_E_BASE64_ENCODING_ERROR; - } + if (msg != NULL) { + if (strlen(msg) > 50) { + gnutls_assert(); + return GNUTLS_E_BASE64_ENCODING_ERROR; + } - _gnutls_str_cpy(top, sizeof(top), "-----BEGIN "); - _gnutls_str_cat(top, sizeof(top), msg); - _gnutls_str_cat(top, sizeof(top), "-----\n"); + _gnutls_str_cpy(top, sizeof(top), "-----BEGIN "); + _gnutls_str_cat(top, sizeof(top), msg); + _gnutls_str_cat(top, sizeof(top), "-----\n"); - _gnutls_str_cpy(bottom, sizeof(bottom), "-----END "); - _gnutls_str_cat(bottom, sizeof(bottom), msg); - _gnutls_str_cat(bottom, sizeof(bottom), "-----\n"); + _gnutls_str_cpy(bottom, sizeof(bottom), "-----END "); + _gnutls_str_cat(bottom, sizeof(bottom), msg); + _gnutls_str_cat(bottom, sizeof(bottom), "-----\n"); - top_len = strlen(top); - bottom_len = strlen(bottom); + top_len = strlen(top); + bottom_len = strlen(bottom); + } max = B64FSIZE(top_len + bottom_len, data_size); @@ -102,9 +104,13 @@ _gnutls_fbase64_encode(const char *msg, const uint8_t * data, memcpy(ptr, tmpres, size); ptr += size; - *ptr++ = '\n'; - - pos += size + 1; + pos += size; + if (msg != NULL) { + *ptr++ = '\n'; + pos++; + } else { + bytes--; + } } INCR(bytes, bottom_len, max); @@ -118,7 +124,7 @@ _gnutls_fbase64_encode(const char *msg, const uint8_t * data, /** * gnutls_pem_base64_encode: - * @msg: is a message to be put in the header + * @msg: is a message to be put in the header (may be %NULL) * @data: contain the raw data * @result: the place where base64 data will be copied * @result_size: holds the size of the result @@ -126,9 +132,12 @@ _gnutls_fbase64_encode(const char *msg, const uint8_t * data, * This function will convert the given data to printable data, using * the base64 encoding. This is the encoding used in PEM messages. * - * The output string will be null terminated, although the size will + * The output string will be null terminated, although the output size will * not include the terminating null. * + * Since GnuTLS 3.6.0 this function when provided a %NULL msg will + * provide a raw base64 output of the input data. + * * Returns: On success %GNUTLS_E_SUCCESS (0) is returned, * %GNUTLS_E_SHORT_MEMORY_BUFFER is returned if the buffer given is * not long enough, or 0 on success. @@ -159,7 +168,7 @@ gnutls_pem_base64_encode(const char *msg, const gnutls_datum_t * data, /** * gnutls_pem_base64_encode2: - * @msg: is a message to be put in the encoded header + * @msg: is a message to be put in the encoded header (may be %NULL) * @data: contains the raw data * @result: will hold the newly allocated encoded data * @@ -174,6 +183,9 @@ gnutls_pem_base64_encode(const char *msg, const gnutls_datum_t * data, * under the name gnutls_pem_base64_encode_alloc(). There is * compatibility macro pointing to this function. * + * Since GnuTLS 3.6.0 this function when provided a %NULL msg will + * provide a raw base64 output of the input data. + * * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise * an error code is returned. * |