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)
Thu, Jun 20, 6:55 AM
Unknown Object (File)
Fri, Jun 14, 10:20 PM
Unknown Object (File)
Tue, Jun 11, 11:37 PM
Unknown Object (File)
Sun, May 26, 9:27 AM
Unknown Object (File)
Sun, May 26, 9:27 AM
Unknown Object (File)
Sun, May 26, 9:26 AM
Unknown Object (File)
Sun, May 26, 9:23 AM
Unknown Object (File)
Thu, May 23, 8:37 PM
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