Skip to content
Snippets Groups Projects
Commit a2cfe12f authored by Rafaël Carré's avatar Rafaël Carré
Browse files

AudioSrtpSession: simplify base64 encoding

parent 52eb9695
Branches
No related tags found
No related merge requests found
...@@ -188,7 +188,6 @@ void AudioSrtpSession::initializeLocalMasterSalt (void) ...@@ -188,7 +188,6 @@ void AudioSrtpSession::initializeLocalMasterSalt (void)
std::string AudioSrtpSession::getBase64ConcatenatedKeys() std::string AudioSrtpSession::getBase64ConcatenatedKeys()
{ {
_debug ("AudioSrtp: Get base64 concatenated keys"); _debug ("AudioSrtp: Get base64 concatenated keys");
// compute concatenated master and salt length // compute concatenated master and salt length
...@@ -203,14 +202,7 @@ std::string AudioSrtpSession::getBase64ConcatenatedKeys() ...@@ -203,14 +202,7 @@ std::string AudioSrtpSession::getBase64ConcatenatedKeys()
memcpy ( (void*) (concatKeys + _localMasterKeyLength), (void*) _localMasterSalt, _localMasterSaltLength); memcpy ( (void*) (concatKeys + _localMasterKeyLength), (void*) _localMasterSalt, _localMasterSaltLength);
// encode concatenated keys in base64 // encode concatenated keys in base64
char *output = encodeBase64 ( (unsigned char*) concatKeys, concatLength); return encodeBase64 ( (unsigned char*) concatKeys, concatLength);
// init string containing encoded data
std::string keys (output);
free (output);
return keys;
} }
...@@ -296,14 +288,11 @@ void AudioSrtpSession::restoreCryptoContext(ost::CryptoContext *localContext, os ...@@ -296,14 +288,11 @@ void AudioSrtpSession::restoreCryptoContext(ost::CryptoContext *localContext, os
setOutQueueCryptoContext (localContext); setOutQueueCryptoContext (localContext);
} }
char* AudioSrtpSession::encodeBase64 (unsigned char *input, int length) std::string AudioSrtpSession::encodeBase64 (unsigned char *input, int length)
{ {
BIO *b64, *bmem; BIO *b64, *bmem;
BUF_MEM *bptr ; BUF_MEM *bptr ;
char *buffer = (char *) malloc (2*length);
memset (buffer, 0, 2*length);
// init decoder // init decoder
b64 = BIO_new (BIO_f_base64()); b64 = BIO_new (BIO_f_base64());
BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL); BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL);
...@@ -320,12 +309,11 @@ char* AudioSrtpSession::encodeBase64 (unsigned char *input, int length) ...@@ -320,12 +309,11 @@ char* AudioSrtpSession::encodeBase64 (unsigned char *input, int length)
// get pointer to data // get pointer to data
BIO_get_mem_ptr (b64, &bptr); BIO_get_mem_ptr (b64, &bptr);
// copy result in output buffer (-1 since we do not want the EOF character) std::string output(bptr->data, bptr->length);
strncpy (buffer, (char*) (bptr->data), bptr->length);
BIO_free_all (bmem); BIO_free_all (bmem);
return buffer; return output;
} }
#pragma GCC diagnostic warning "-Wunused-value" #pragma GCC diagnostic warning "-Wunused-value"
......
...@@ -155,7 +155,7 @@ class AudioSrtpSession : public AudioRtpSession ...@@ -155,7 +155,7 @@ class AudioSrtpSession : public AudioRtpSession
/** /**
* Encode input data as base64 * Encode input data as base64
*/ */
char* encodeBase64 (unsigned char *input, int length); std::string encodeBase64 (unsigned char *input, int length);
/** /**
* Decode base64 data * Decode base64 data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment