Skip to content

Commit

Permalink
[CommCoreModule] make sure backupID is URL-safe string
Browse files Browse the repository at this point in the history
Summary:
[ENG-9728](https://linear.app/comm/issue/ENG-9728/update-backupid-to-be-b64-url-safe-string).

Not sure if we need any additional conversion, this should be enough.

Test Plan: Test uploading backup

Reviewers: varun, bartek

Reviewed By: varun

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D13894
  • Loading branch information
xsanm committed Nov 12, 2024
1 parent 632514f commit a2b0d2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions native/cpp/CommonCpp/CryptoTools/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ std::string Tools::generateRandomHexString(size_t size) {
return Tools::generateRandomString(size, hexSigns);
}

std::string Tools::generateRandomURLSafeString(size_t size) {
static std::string urlSafeSigns =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
return Tools::generateRandomString(size, urlSafeSigns);
}

} // namespace crypto
} // namespace comm
1 change: 1 addition & 0 deletions native/cpp/CommonCpp/CryptoTools/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Tools {
public:
static std::string generateRandomString(size_t size);
static std::string generateRandomHexString(size_t size);
static std::string generateRandomURLSafeString(size_t size);
};

} // namespace crypto
Expand Down
2 changes: 1 addition & 1 deletion native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2502,7 +2502,7 @@ jsi::Value CommCoreModule::createNewBackupInternal(

std::string backupID;
try {
backupID = crypto::Tools::generateRandomString(32);
backupID = crypto::Tools::generateRandomURLSafeString(32);
} catch (const std::exception &e) {
error = "Failed to generate backupID";
}
Expand Down

0 comments on commit a2b0d2a

Please sign in to comment.