test_nvs_partition.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "catch.hpp"
  7. #include <algorithm>
  8. #include <cstring>
  9. #include "nvs_test_api.h"
  10. #include "nvs_handle_simple.hpp"
  11. #include "nvs_partition.hpp"
  12. #include "spi_flash_emulation.h"
  13. #include "test_fixtures.hpp"
  14. #include <iostream>
  15. TEST_CASE("encrypted partition read size must be item size", "[nvs]")
  16. {
  17. char foo [32] = { };
  18. nvs_sec_cfg_t xts_cfg;
  19. for (int count = 0; count < NVS_KEY_SIZE; count++) {
  20. xts_cfg.eky[count] = 0x11;
  21. xts_cfg.tky[count] = 0x22;
  22. }
  23. EncryptedPartitionFixture fix(&xts_cfg);
  24. CHECK(fix.part.read(0, foo, sizeof (foo) - 1) == ESP_ERR_INVALID_SIZE);
  25. }
  26. TEST_CASE("encrypted partition write size must be mod item size", "[nvs]")
  27. {
  28. char foo [64] = { };
  29. nvs_sec_cfg_t xts_cfg;
  30. for (int count = 0; count < NVS_KEY_SIZE; count++) {
  31. xts_cfg.eky[count] = 0x11;
  32. xts_cfg.tky[count] = 0x22;
  33. }
  34. EncryptedPartitionFixture fix(&xts_cfg);
  35. CHECK(fix.part.write(0, foo, sizeof (foo) - 1) == ESP_ERR_INVALID_SIZE);
  36. CHECK(fix.part.write(0, foo, sizeof (foo) / 2) == ESP_OK);
  37. CHECK(fix.part.write(sizeof(foo) / 2, foo, sizeof (foo)) == ESP_OK);
  38. }