When opening an encrypted partition via src/nvs.rs, it tries to find the partition by name. However, the code seems not to work. I have created a minimal viable sample in https://github.com/MartinBroers/rust_c_ffi (don't mind the naming there; it is all about the code). The way the Option<&str> is parsed into an CString object somewhere goes awry, maybe because references are dropped in the meantime?
Run the code in the linked repo by running cargo run and the expected output is found it, But it prints garbage in the puts call as well. Can imagine the strcmp call also fails.... The rust code converts a &str to CString which is used in calling 2 separate C functions, just as esp-idf-svc does when calling esp_partition_find_first.
NvsEncrypted::init called via new takes an key_partition: Option<&str>, and converts this into a CString or core::ptr::null when the option is None. The code works when the key_partition name is not provided, but that hinges on only having a single key partition, which may not cover all use cases.
When opening an encrypted partition via src/nvs.rs, it tries to find the partition by name. However, the code seems not to work. I have created a minimal viable sample in https://github.com/MartinBroers/rust_c_ffi (don't mind the naming there; it is all about the code). The way the Option<&str> is parsed into an CString object somewhere goes awry, maybe because references are dropped in the meantime?
Run the code in the linked repo by running
cargo run
and the expected output isfound it
, But it prints garbage in theputs
call as well. Can imagine thestrcmp
call also fails.... The rust code converts a &str to CString which is used in calling 2 separate C functions, just as esp-idf-svc does when callingesp_partition_find_first
.NvsEncrypted::init
called vianew
takes ankey_partition: Option<&str>,
and converts this into a CString orcore::ptr::null
when the option is None. The code works when the key_partition name is not provided, but that hinges on only having a single key partition, which may not cover all use cases.