mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Add simple facility for storing secret in app-private storage on Android (other platforms not so good)
This commit is contained in:
parent
37fb3be4d5
commit
87846c5fcb
2 changed files with 23 additions and 0 deletions
|
@ -87,3 +87,6 @@ void NativeShutdownGraphics();
|
|||
void NativeShutdown();
|
||||
|
||||
void PostLoadConfig();
|
||||
|
||||
void NativeSaveSecret(const char *nameOfSecret, const std::string &data);
|
||||
std::string NativeLoadSecret(const char *nameOfSecret);
|
||||
|
|
|
@ -1419,3 +1419,23 @@ void NativeShutdown() {
|
|||
// Previously we did exit() here on Android but that makes it hard to do things like restart on backend change.
|
||||
// I think we handle most globals correctly or correct-enough now.
|
||||
}
|
||||
|
||||
Path GetSecretPath(const char *nameOfSecret) {
|
||||
return g_Config.internalDataDirectory / ("ppsspp_" + std::string(nameOfSecret) + ".dat");
|
||||
}
|
||||
|
||||
// name should be simple alphanumerics to avoid problems on Windows.
|
||||
void NativeSaveSecret(const char *nameOfSecret, const std::string &data) {
|
||||
// We'll simply store secrets in files under g_Config.internalDataDirectory.
|
||||
// On Android, that corresponds to the app private directory. On other platforms,
|
||||
// the location is less secure unfortunately - to be improved.
|
||||
Path path = GetSecretPath(nameOfSecret);
|
||||
File::WriteDataToFile(false, data.data(), data.size(), path);
|
||||
}
|
||||
|
||||
std::string NativeLoadSecret(const char *nameOfSecret) {
|
||||
Path path = GetSecretPath(nameOfSecret);
|
||||
std::string data;
|
||||
File::ReadFileToString(false, path, data);
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue