diff --git a/src/c-wrapper/api/c-content.cpp b/src/c-wrapper/api/c-content.cpp index c0d939126..0671204ff 100644 --- a/src/c-wrapper/api/c-content.cpp +++ b/src/c-wrapper/api/c-content.cpp @@ -40,7 +40,6 @@ L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(Content, void *cryptoContext; // Used to encrypt file for RCS file transfer. mutable size_t size; - mutable char *key; struct Cache { string name; @@ -213,15 +212,12 @@ const char *linphone_content_get_custom_header (const LinphoneContent *content, } const char *linphone_content_get_key (const LinphoneContent *content) { - if (content->key) bctbx_free(content->key); - const LinphonePrivate::Content *c = L_GET_CPP_PTR_FROM_C_OBJECT(content); if (c->isFileTransfer()) { const LinphonePrivate::FileTransferContent *ftc = static_cast(c); - content->key = bctbx_strdup(ftc->getFileKeyAsString()); + return ftc->getFileKey().data(); } - - return content->key; + return nullptr; } size_t linphone_content_get_key_size (const LinphoneContent *content) { diff --git a/src/chat/modifier/file-transfer-chat-message-modifier.cpp b/src/chat/modifier/file-transfer-chat-message-modifier.cpp index ad17cfff7..f73581c6b 100644 --- a/src/chat/modifier/file-transfer-chat-message-modifier.cpp +++ b/src/chat/modifier/file-transfer-chat-message-modifier.cpp @@ -318,9 +318,9 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h const char *body = belle_sip_message_get_body((belle_sip_message_t *)event->response); if (body && strlen(body) > 0) { // if we have an encryption key for the file, we must insert it into the msg and restore the correct filename - const char *content_key = fileTransferContent->getFileKeyAsString(); - size_t content_key_size = fileTransferContent->getFileKey().size(); - if (content_key_size > 0) { + const unsigned char *contentKey = reinterpret_cast(fileTransferContent->getFileKey().data()); + size_t contentKeySize = fileTransferContent->getFileKeySize(); + if (contentKeySize > 0) { // parse the msg body xmlDocPtr xmlMessageBody = xmlParseDoc((const xmlChar *)body); @@ -337,11 +337,11 @@ void FileTransferChatMessageModifier::processResponseFromPostFile (const belle_h xmlNodePtr fileInfoNodeChildren = cur->xmlChildrenNode; // convert key to base64 size_t b64Size; - bctbx_base64_encode(nullptr, &b64Size, (unsigned char *)content_key, content_key_size); + bctbx_base64_encode(nullptr, &b64Size, contentKey, contentKeySize); unsigned char *keyb64 = (unsigned char *)ms_malloc0(b64Size + 1); int xmlStringLength; - bctbx_base64_encode(keyb64, &b64Size, (unsigned char *)content_key, content_key_size); + bctbx_base64_encode(keyb64, &b64Size, contentKey, contentKeySize); keyb64[b64Size] = '\0'; // libxml need a null terminated string // add the node containing the key to the file-info node diff --git a/src/content/file-transfer-content.cpp b/src/content/file-transfer-content.cpp index 2b8e228bb..8bf22f7a0 100644 --- a/src/content/file-transfer-content.cpp +++ b/src/content/file-transfer-content.cpp @@ -164,11 +164,6 @@ const vector &FileTransferContent::getFileKey () const { return d->fileKey; } -const char *FileTransferContent::getFileKeyAsString() const { - L_D(); - return d->fileKey.data(); -} - size_t FileTransferContent::getFileKeySize() const { L_D(); return d->fileKey.size(); diff --git a/src/content/file-transfer-content.h b/src/content/file-transfer-content.h index 1904e11c5..4ae07867b 100644 --- a/src/content/file-transfer-content.h +++ b/src/content/file-transfer-content.h @@ -59,7 +59,6 @@ public: void setFileKey (const char *key, size_t size); const std::vector &getFileKey () const; - const char *getFileKeyAsString () const; size_t getFileKeySize() const; bool isFile () const override;