Skip to content

Commit cdc7ca1

Browse files
authored
change disable logic
1 parent 1f40aee commit cdc7ca1

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

Diff for: libraries/Update/src/Updater.cpp

+28-28
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include "spi_flash_mmap.h"
1010
#include "esp_ota_ops.h"
1111
#include "esp_image_format.h"
12-
#ifdef UPDATE_CRYPT
12+
#ifndef UPDATE_NOCRYPT
1313
#include "mbedtls/aes.h"
14-
#endif /* UPDATE_CRYPT */
14+
#endif /* UPDATE_NOCRYPT */
1515

1616
static const char *_err2str(uint8_t _error) {
1717
if (_error == UPDATE_ERROR_OK) {
@@ -40,10 +40,10 @@ static const char *_err2str(uint8_t _error) {
4040
return ("Bad Argument");
4141
} else if (_error == UPDATE_ERROR_ABORT) {
4242
return ("Aborted");
43-
#ifdef UPDATE_CRYPT
43+
#ifndef UPDATE_NOCRYPT
4444
} else if (_error == UPDATE_ERROR_DECRYPT) {
4545
return ("Decryption error");
46-
#endif /* UPDATE_CRYPT */
46+
#endif /* UPDATE_NOCRYPT */
4747
}
4848
return ("UNKNOWN");
4949
}
@@ -72,13 +72,13 @@ bool UpdateClass::_enablePartition(const esp_partition_t *partition) {
7272

7373
UpdateClass::UpdateClass()
7474
: _error(0),
75-
#ifdef UPDATE_CRYPT
75+
#ifndef UPDATE_NOCRYPT
7676
_cryptKey(0), _cryptBuffer(0),
77-
#endif /* UPDATE_CRYPT */
77+
#endif /* UPDATE_NOCRYPT */
7878
_buffer(0), _skipBuffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _paroffset(0), _command(U_FLASH), _partition(NULL)
79-
#ifdef UPDATE_CRYPT
79+
#ifndef UPDATE_NOCRYPT
8080
, _cryptMode(U_AES_DECRYPT_AUTO), _cryptAddress(0), _cryptCfg(0xf)
81-
#endif /* UPDATE_CRYPT */
81+
#endif /* UPDATE_NOCRYPT */
8282
{}
8383

8484
UpdateClass &UpdateClass::onProgress(THandlerFunction_Progress fn) {
@@ -94,9 +94,9 @@ void UpdateClass::_reset() {
9494
delete[] _skipBuffer;
9595
}
9696

97-
#ifdef UPDATE_CRYPT
97+
#ifndef UPDATE_NOCRYPT
9898
_cryptBuffer = nullptr;
99-
#endif /* UPDATE_CRYPT */
99+
#endif /* UPDATE_NOCRYPT */
100100
_buffer = nullptr;
101101
_skipBuffer = nullptr;
102102
_bufferLen = 0;
@@ -188,7 +188,7 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con
188188
return true;
189189
}
190190

191-
#ifdef UPDATE_CRYPT
191+
#ifndef UPDATE_NOCRYPT
192192
bool UpdateClass::setupCrypt(const uint8_t *cryptKey, size_t cryptAddress, uint8_t cryptConfig, int cryptMode) {
193193
if (setCryptKey(cryptKey)) {
194194
if (setCryptMode(cryptMode)) {
@@ -230,7 +230,7 @@ bool UpdateClass::setCryptMode(const int cryptMode) {
230230
}
231231
return true;
232232
}
233-
#endif /* UPDATE_CRYPT */
233+
#endif /* UPDATE_NOCRYPT */
234234

235235
void UpdateClass::_abort(uint8_t err) {
236236
_reset();
@@ -241,7 +241,7 @@ void UpdateClass::abort() {
241241
_abort(UPDATE_ERROR_ABORT);
242242
}
243243

244-
#ifdef UPDATE_CRYPT
244+
#ifndef UPDATE_NOCRYPT
245245
void UpdateClass::_cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key) {
246246
memcpy(tweaked_key, _cryptKey, ENCRYPTED_KEY_SIZE);
247247
if (_cryptCfg == 0) {
@@ -354,10 +354,10 @@ bool UpdateClass::_decryptBuffer() {
354354
}
355355
return true;
356356
}
357-
#endif /* UPDATE_CRYPT */
357+
#endif /* UPDATE_NOCRYPT */
358358

359359
bool UpdateClass::_writeBuffer() {
360-
#ifdef UPDATE_CRYPT
360+
#ifndef UPDATE_NOCRYPT
361361
//first bytes of loading image, check to see if loading image needs decrypting
362362
if (!_progress) {
363363
_cryptMode &= U_AES_DECRYPT_MODE_MASK;
@@ -378,7 +378,7 @@ bool UpdateClass::_writeBuffer() {
378378
return false;
379379
}
380380
}
381-
#endif /* UPDATE_CRYPT */
381+
#endif /* UPDATE_NOCRYPT */
382382
//first bytes of new firmware
383383
uint8_t skip = 0;
384384
if (!_progress && _command == U_FLASH) {
@@ -428,13 +428,13 @@ bool UpdateClass::_writeBuffer() {
428428
if (!_progress && _command == U_FLASH) {
429429
_buffer[0] = ESP_IMAGE_HEADER_MAGIC;
430430
}
431-
#ifdef UPDATE_CRYPT
431+
#ifndef UPDATE_NOCRYPT
432432
if (_target_md5_decrypted) {
433-
#endif /* UPDATE_CRYPT */
433+
#endif /* UPDATE_NOCRYPT */
434434
_md5.add(_buffer, _bufferLen);
435-
#ifdef UPDATE_CRYPT
435+
#ifndef UPDATE_NOCRYPT
436436
}
437-
#endif /* UPDATE_CRYPT */
437+
#endif /* UPDATE_NOCRYPT */
438438
_progress += _bufferLen;
439439
_bufferLen = 0;
440440
if (_progress_callback) {
@@ -477,18 +477,18 @@ bool UpdateClass::_verifyEnd() {
477477
}
478478

479479
bool UpdateClass::setMD5(const char *expected_md5
480-
#ifdef UPDATE_CRYPT
480+
#ifndef UPDATE_NOCRYPT
481481
,bool calc_post_decryption
482-
#endif /* UPDATE_CRYPT */
482+
#endif /* UPDATE_NOCRYPT */
483483
) {
484484
if (strlen(expected_md5) != 32) {
485485
return false;
486486
}
487487
_target_md5 = expected_md5;
488488
_target_md5.toLowerCase();
489-
#ifdef UPDATE_CRYPT
489+
#ifndef UPDATE_NOCRYPT
490490
_target_md5_decrypted = calc_post_decryption;
491-
#endif /* UPDATE_CRYPT */
491+
#endif /* UPDATE_NOCRYPT */
492492
return true;
493493
}
494494

@@ -561,16 +561,16 @@ size_t UpdateClass::writeStream(Stream &data) {
561561
return 0;
562562
}
563563

564-
#ifdef UPDATE_CRYPT
564+
#ifndef UPDATE_NOCRYPT
565565
if (_command == U_FLASH && !_cryptMode) {
566-
#endif /* UPDATE_CRYPT */
566+
#endif /* UPDATE_NOCRYPT */
567567
if (!_verifyHeader(data.peek())) {
568568
_reset();
569569
return 0;
570570
}
571-
#ifdef UPDATE_CRYPT
571+
#ifndef UPDATE_NOCRYPT
572572
}
573-
#endif /* UPDATE_CRYPT */
573+
#endif /* UPDATE_NOCRYPT */
574574

575575
if (_ledPin != -1) {
576576
pinMode(_ledPin, OUTPUT);

0 commit comments

Comments
 (0)