Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] MMKV.exists(..) API #1346

Open
mrousavy opened this issue Jul 10, 2024 · 10 comments
Open

[ENHANCEMENT] MMKV.exists(..) API #1346

mrousavy opened this issue Jul 10, 2024 · 10 comments

Comments

@mrousavy
Copy link
Contributor

mrousavy commented Jul 10, 2024

Hey!

I was wondering if there's a way to find out if an MMKV instance with the given id exists or not?

Something like

auto id = "my-instance";
bool exists = MMKV::exists(id);
if (exists) {
  // load it, start app
} else {
  // show login page
}

This would maybe also open up other scenarios for e.g. crypto wallets, where we can check if an encrypted MMKV instance exists without knowing the encryption key.

@lingol
Copy link
Collaborator

lingol commented Jul 10, 2024

No there isn't one yet. Will you be kindly enough to make a PR to add one?

@mrousavy
Copy link
Contributor Author

Sure, can you give me some pointers on how I can find out if an instance exists? Try loading it? Looking for the file path? Some code pointers would be appreciated!

@lingol
Copy link
Collaborator

lingol commented Jul 10, 2024

You can follow the logic in removeStorage(). Checking the existence of the file and meta file should be enough.

@mrousavy
Copy link
Contributor Author

Created a draft PR here; #1347

Did not test yet, I'm still on the airport. Will test & finish it later.

@mrousavy
Copy link
Contributor Author

Hey @lingol sorry this is a bit unrelated but I didn't want to create a separate issue for my question; when I create an instance with an encryption key and write some data to it, and then try to open it again later with a different encryption key (or no encryption key at all), it will erase all data of that instance.

Is that intended behaviour? I would've expected it to throw some kind of error if the encryption key does not match..

@lingol
Copy link
Collaborator

lingol commented Jul 11, 2024

MMKV doesn't record the encryption key. So there's no way for MMKV to tell if the key is correct.
Image that if MMKV does provide such functionality, doesn't that leave space for brute force encryption key cracking?

@mrousavy
Copy link
Contributor Author

Okay valid. Got it.

@lingol
Copy link
Collaborator

lingol commented Jul 24, 2024

Hey, is there any chance you can provide this feature this week?
I'm considering a new release due to the encryption bug. I hope you can make it.

@mrousavy
Copy link
Contributor Author

Hey - sorry I got stuck up with some other work related to my camera library. I think I won't be able to finish it this week, I might be able to dedicated the time for that next week or the week after that.

@lingol
Copy link
Collaborator

lingol commented Jul 24, 2024

Of cause, take your time. We will release LTS version instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants