Page MenuHomePhabricator

[client-backup] implement C++ function for computing `BackupKey`
ClosedPublic

Authored by kamil on Aug 21 2023, 4:57 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Oct 27, 4:25 PM
Unknown Object (File)
Sep 28 2024, 4:47 AM
Unknown Object (File)
Sep 27 2024, 11:26 PM
Unknown Object (File)
Sep 27 2024, 11:26 PM
Unknown Object (File)
Sep 27 2024, 11:26 PM
Unknown Object (File)
Sep 27 2024, 11:20 PM
Unknown Object (File)
Sep 26 2024, 10:14 PM
Unknown Object (File)
Sep 26 2024, 5:54 AM
Subscribers

Details

Summary

ENG-4512.

Note:
This is call to Rust, but it's related to cryptography, so I believe it should be executed on cryptoThread which is spawned via CommCoreModule - this is why I placed this here, not in CommRustModule. In the future, we might want to introduce new module to crypto-related things.

Depends on D8885

Test Plan

Call commCoreModule.computeBackupKey.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.Aug 21 2023, 6:39 AM
kamil added a reviewer: varun.
kamil added a subscriber: varun.

@varun, could you confirm if this is the proper way of using native_rust_library in this use case?

native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
820 ↗(On Diff #30134)

32 is hardcoded, I don't think it's possible to use constant from Rust here, I checked this but it didn't work

marcin added inline comments.
native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
820 ↗(On Diff #30134)

Even if it is not possible to access this constant from Rust it should still be defined as a named-variables to avoid magic number anti pattern.

822 ↗(On Diff #30134)

Did you try to simulate the failure of the rust function to ensure that std::exception is actually thrown and caught or have some documentation that confirms this?

836 ↗(On Diff #30134)

Why double if backupKey is vector of integers?

This revision is now accepted and ready to land.Aug 22 2023, 1:42 AM
native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
820 ↗(On Diff #30134)

Right, I will update this before landing

822 ↗(On Diff #30134)

Yes, I tested it with too shoty backupID which cause throwing:
{"message": "Failed to compute backup key: salt is too short"}

836 ↗(On Diff #30134)

We use it in the codebase already (because JS numbers are represented as double in C++), but integer should also work, I can update this if you feel strongly it should be integer.

Would love to get @varun's approval on C++ <-> Rust integration

This revision now requires review to proceed.Aug 22 2023, 3:14 AM
This revision is now accepted and ready to land.Aug 29 2023, 9:54 AM
In D8886#265515, @varun wrote:

LGTM. I wonder if it's possible to simplify the type conversion logic with folly/dynamic

https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/jsi/jsi/JSIDynamic.h

Probably yes, but this approach I implemented is based on similar functions in the codebase so I will stick to the convention for now