edits
[iotcloud.git] / version2 / src / C / CloudComm.cc
index c20488dd268d59632d09634068961b918a9a878c..2a7d233608d9498679c1348bbf3530324ebb73bb 100644 (file)
@@ -499,13 +499,10 @@ Array<char> *AESDecrypt(Array<char> *ivBytes, AESKey *key, Array<char> *data) {
 Array<char> *CloudComm::encryptSlotAndPrependIV(Array<char> *rawData, Array<char> *ivBytes) {
        try {
                Array<char> *encryptedBytes = AESEncrypt(ivBytes, key, rawData);
-               Array<char> *origBytes = AESDecrypt(ivBytes, key, encryptedBytes);
-               if (!rawData->equals(origBytes))
-                       throw new Error("BAD");
                Array<char> *chars = new Array<char>(encryptedBytes->length() + CloudComm_IV_SIZE);
                System_arraycopy(ivBytes, 0, chars, 0, ivBytes->length());
                System_arraycopy(encryptedBytes, 0, chars, CloudComm_IV_SIZE, encryptedBytes->length());
-
+               delete encryptedBytes;
                return chars;
        } catch (Exception *e) {
                throw new Error("Failed To Encrypt");
@@ -518,7 +515,10 @@ Array<char> *CloudComm::stripIVAndDecryptSlot(Array<char> *rawData) {
                Array<char> *encryptedBytes = new Array<char>(rawData->length() - CloudComm_IV_SIZE);
                System_arraycopy(rawData, 0, ivBytes, 0, CloudComm_IV_SIZE);
                System_arraycopy(rawData, CloudComm_IV_SIZE, encryptedBytes, 0, encryptedBytes->length());
-               return AESDecrypt(ivBytes, key, encryptedBytes);
+               Array<char> * data = AESDecrypt(ivBytes, key, encryptedBytes);
+               delete encryptedBytes;
+               delete ivBytes;
+               return data;
        } catch (Exception *e) {
                throw new Error("Failed To Decrypt");
        }
@@ -542,10 +542,12 @@ Array<Slot *> *CloudComm::putSlot(Slot *slot, int max) {
                int64_t sequencenumber = slot->getSequenceNumber();
                Array<char> *slotBytes = slot->encode(mac);
                Array<char> *chars = encryptSlotAndPrependIV(slotBytes, slot->getSlotCryptIV());
+               delete slotBytes;
                IoTString *url = buildRequest(true, sequencenumber, max);
                timer->startTime();
                wc = openURL(url);
                writeURLDataAndClose(&wc, chars);
+               delete chars;
                timer->endTime();
        } catch (ServerException *e) {
                timer->endTime();
@@ -652,7 +654,9 @@ Array<Slot *> *CloudComm::processSlots(WebConnection *wc) {
                Array<char> *rawData = new Array<char>(sizesofslots->get(i));
                readURLData(wc, rawData);
                Array<char> *data = stripIVAndDecryptSlot(rawData);
+               delete rawData;
                slots->set(i, Slot_decode(table, data, mac));
+               delete data;
        }
        return slots;
 }