bcgit / pc-dart

Pointy Castle - Dart Derived Bouncy Castle APIs
MIT License
237 stars 122 forks source link

Use fixnum instead of rolling custom solution #25

Closed AKushWarrior closed 4 years ago

AKushWarrior commented 4 years ago

https://pub.dev/packages/fixnum is written by the Dart team. Right now, we manually roll a solution for doing 32 bit ops in dart (which only has signed 64 bit ints). This is located in src/utils/ufixnum.dart. This WORKS, but doing 32 bit ops on 64 bit ints is syntactically confusing and doesn't make very good use of the type system. Further, Java has 32 AND 64 bit ints, which means that transcribing classes from Java to Dart is a pain.

By using fixnum's 32 bit class for any new development, we can probably increase runtime speed, as well as maybe making a more natural transcribing process from BouncyCastle -> PointyCastle.

AKushWarrior commented 4 years ago

This is important for other reasons, as well. Technically, integers in Dart are of an arbitrary precision, so behaviour of this library is unpredictable when compiled to Javascript. By using fixnum's integers, behaviour when compiled is guaranteed to match behaviour when run on the dart VM.

AKushWarrior commented 4 years ago

@mwcw can you comment? I can do this, but there will be nontrivial overhead.

mwcw commented 4 years ago

Hi,

The thing that needs to be watched out for is that crypto libraries tend to be become infrastructure components and if infrastructure components start to bring with them a tree of dependencies those dependencies can cause issues for library users.

I'll speak to @dghgit about it.

MW

AKushWarrior commented 4 years ago

Hi,

The thing that needs to be watched out for is that crypto libraries tend to be become infrastructure components and if infrastructure components start to bring with them a tree of dependencies those dependencies can cause issues for library users.

I'll speak to @dghgit about it.

MW

I understand the issue you're referencing. On the other hand, fixnum is provided by the Dart team itself; some of those issues may be mitigated by the fact that the package is pretty conservative in releasing new versions.

mwcw commented 4 years ago

Hi,

I think we may as well go with this given which team is maintaining it, it will pin the project to whatever their minimum is but we can deal with that if and when it occurs.

So after the release #8 we should start using it.

MW