Commit 78bffa6a authored by Johan Pascal's avatar Johan Pascal

Can call decrypt without cipherMessage parameter

parent 62f2ae2a
......@@ -180,11 +180,12 @@ namespace lime {
* it is not necessarily the sip:uri base of the GRUU as this could be a message from alice first device intended to bob being decrypted on alice second device
* @param[in] senderDeviceId Identify sender Device. This field shall be extracted from signaling data in transport protocol, is used to rebuild the authenticated data associated to the encrypted message
* @param[in] DRmessage Double Ratchet message targeted to current device
* @param[in] cipherMessage part of cipher routed to all recipient devices, may be empty
* @param[in] cipherMessage when present(depends on encryption policy) holds a common part of the encrypted message. Can be ignored or set to empty vector if not present.
* @param[out] plainMessage the output buffer
* @return true if the decryption is successfull, false otherwise
bool decrypt(const std::string &localDeviceId, const std::string &recipientUserId, const std::string &senderDeviceId, const std::vector<uint8_t> &DRmessage, std::vector<uint8_t> &plainMessage);
bool decrypt(const std::string &localDeviceId, const std::string &recipientUserId, const std::string &senderDeviceId, const std::vector<uint8_t> &DRmessage, const std::vector<uint8_t> &cipherMessage, std::vector<uint8_t> &plainMessage);
......@@ -99,6 +99,20 @@ namespace lime {
return user->decrypt(recipientUserId, senderDeviceId, DRmessage, cipherMessage, plainMessage);
// convenience definition, have a decrypt without cipherMessage input for the case we don't have it(DR message encryption policy)
// just use an create an empty cipherMessage to be able to call Lime::decrypt which needs the cipherMessage even if empty for code simplicity
bool LimeManager::decrypt(const std::string &localDeviceId, const std::string &recipientUserId, const std::string &senderDeviceId, const std::vector<uint8_t> &DRmessage, std::vector<uint8_t> &plainMessage) {
// Load user object
std::shared_ptr<LimeGeneric> user;
LimeManager::load_user(user, localDeviceId);
const std::vector<uint8_t> emptyCipherMessage(0);
// call the decryption function
return user->decrypt(recipientUserId, senderDeviceId, DRmessage, emptyCipherMessage, plainMessage);
/* This version use default settings */
void LimeManager::update(const limeCallback &callback) {
update(callback, lime::settings::OPk_serverLowLimit, lime::settings::OPk_batchSize);
......@@ -477,7 +477,12 @@ static void lime_encryptionPolicy_test(std::shared_ptr<LimeManager> aliceManager
// alice1 decrypt
std::vector<uint8_t> receivedMessage{};
BC_ASSERT_TRUE(aliceManager->decrypt(*aliceDevice1Id, "alice", *bobDeviceId, (*bobRecipients)[0].DRmessage, *bobCipherMessage, receivedMessage));
if (is_directEncryptionType) { // when having the message in DR message only, use the decrypt interface without cipherMessage
BC_ASSERT_TRUE(aliceManager->decrypt(*aliceDevice1Id, "alice", *bobDeviceId, (*bobRecipients)[0].DRmessage, receivedMessage));
} else {
BC_ASSERT_TRUE(aliceManager->decrypt(*aliceDevice1Id, "alice", *bobDeviceId, (*bobRecipients)[0].DRmessage, *bobCipherMessage, receivedMessage));
auto receivedMessageString1 = std::string{receivedMessage.begin(), receivedMessage.end()};
BC_ASSERT_TRUE(receivedMessageString1 == plainMessage);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment