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

feat: improve BinaryWriter API #986

Merged
merged 2 commits into from
Jul 19, 2022
Merged

feat: improve BinaryWriter API #986

merged 2 commits into from
Jul 19, 2022

Conversation

TheOneWithTheBraid
Copy link

  • extend default buffer size (thanks to @nico-famedly)
  • allow HiveCipher to asynchronously perform crypto
  • implement HiveAesThreadedCipher for Hive Flutter
  • fix missing file in .gitignore

In theory, no public API should be made incompatible here as HIveCipher
was simply converted from T Function() to FutureOr<T> Function().

The idea behind the asynchronous operation is

a) multithreading using e.g. the compute() function in Flutter or
b) platform-native implementations making use of hardware-accelerated
cryptographic implementations.

CC: @nico-famedly maybe you like to try out this?

Signed-off-by: TheOneWithTheBraid [email protected]

@TheOneWithTheBraid TheOneWithTheBraid force-pushed the braid/crypto branch 2 times, most recently from 92abbcb to 7766c73 Compare May 31, 2022 07:22
@TheOneWithTheBraid TheOneWithTheBraid changed the title feat: improve BinaryWriter API Draft: feat: improve BinaryWriter API May 31, 2022
@TheOneWithTheBraid TheOneWithTheBraid force-pushed the braid/crypto branch 4 times, most recently from 025fcab to 4470355 Compare June 2, 2022 07:47
@TheOneWithTheBraid TheOneWithTheBraid changed the title Draft: feat: improve BinaryWriter API feat: improve BinaryWriter API Jun 2, 2022
@TheOneWithTheBraid
Copy link
Author

@nico-famedly: Can you try out the HiveAesNativeCipher()?

@TheOneWithTheBraid TheOneWithTheBraid force-pushed the braid/crypto branch 3 times, most recently from f51ea31 to 74d6835 Compare June 3, 2022 10:34
@TheOneWithTheBraid
Copy link
Author

I parallelized the binary writer API in a way that the hive cipher now only needs to immediately return the pretended length of the encrypted data while the actual encryption can happen in background - also several crypto operations at once.

That's what the _pendingOperations cache is for.

When the native implementation is told to write to disk (e.g. by flush() or close()), the FutureOr<Uint8List> toBytes() is called.

There, the binary writer checks whether there are running operations in background and correspondingly waits for them to complete. Afterwards, the buffer is returned.

https://github.com/hivedb/hive/pull/986/files#diff-86c49de9691825b1989a3d306e00d9b3e270eec23690e7e4c5d6236f11ad5ac9R455

For some reason, at this place, the returned buffer is always an empty buffer filled with 0 only, even though

https://github.com/hivedb/hive/pull/986/files#diff-86c49de9691825b1989a3d306e00d9b3e270eec23690e7e4c5d6236f11ad5ac9R435

exactly before, a print of the buffer shows the correct bytes inside.

https://github.com/hivedb/hive/pull/986/files#diff-86c49de9691825b1989a3d306e00d9b3e270eec23690e7e4c5d6236f11ad5ac9R456

Also, this here ensures the cache of pending operations is empty before returning the buffer.

Any idea?

@TheOneWithTheBraid TheOneWithTheBraid changed the title feat: improve BinaryWriter API Draft: feat: improve BinaryWriter API Jun 7, 2022
@TheOneWithTheBraid TheOneWithTheBraid force-pushed the braid/crypto branch 6 times, most recently from c1a214e to aa0ef45 Compare June 10, 2022 05:48
- extend default buffer size
- allow HiveCipher to asynchronously perform crypto
- implement HiveAesThreadedCipher for Hive Flutter
- fix missing file in .gitignore

In theory, no public API should be made incompatible here as HIveCipher
was simply converted from `T Function()` to `FutureOr<T> Function()`.

The idea behind the asynchronous operation is

a) multithreading using e.g. the `compute()` function in Flutter or
b) platform-native implementations making use of hardware-accelerated
cryptographic implementations.

Signed-off-by: TheOneWithTheBraid <[email protected]>
Signed-off-by: TheOneWithTheBraid <[email protected]>
@TheOneWithTheBraid TheOneWithTheBraid changed the title Draft: feat: improve BinaryWriter API feat: improve BinaryWriter API Jul 19, 2022
@TheOneWithTheBraid TheOneWithTheBraid merged commit 335b79f into master Jul 19, 2022
@TheOneWithTheBraid TheOneWithTheBraid deleted the braid/crypto branch July 19, 2022 08:20
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

Successfully merging this pull request may close these issues.

1 participant