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