test_nvs_partition.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "catch.hpp"
  14. #include <algorithm>
  15. #include <cstring>
  16. #include "nvs_test_api.h"
  17. #include "nvs_handle_simple.hpp"
  18. #include "nvs_partition.hpp"
  19. #include "spi_flash_emulation.h"
  20. #include "test_fixtures.hpp"
  21. #include <iostream>
  22. using namespace std;
  23. using namespace nvs;
  24. TEST_CASE("encrypted partition read size must be item size", "[nvs]")
  25. {
  26. char foo [32] = { };
  27. nvs_sec_cfg_t xts_cfg;
  28. for(int count = 0; count < NVS_KEY_SIZE; count++) {
  29. xts_cfg.eky[count] = 0x11;
  30. xts_cfg.tky[count] = 0x22;
  31. }
  32. EncryptedPartitionFixture fix(&xts_cfg);
  33. CHECK(fix.part.read(0, foo, sizeof (foo) -1) == ESP_ERR_INVALID_SIZE);
  34. }
  35. TEST_CASE("encrypted partition write size must be mod item size", "[nvs]")
  36. {
  37. char foo [64] = { };
  38. nvs_sec_cfg_t xts_cfg;
  39. for(int count = 0; count < NVS_KEY_SIZE; count++) {
  40. xts_cfg.eky[count] = 0x11;
  41. xts_cfg.tky[count] = 0x22;
  42. }
  43. EncryptedPartitionFixture fix(&xts_cfg);
  44. CHECK(fix.part.write(0, foo, sizeof (foo) -1) == ESP_ERR_INVALID_SIZE);
  45. CHECK(fix.part.write(0, foo, sizeof (foo)) == ESP_OK);
  46. CHECK(fix.part.write(0, foo, sizeof (foo) * 2) == ESP_OK);
  47. }