-
Notifications
You must be signed in to change notification settings - Fork 769
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
Convert APIs to always use forge ByteBuffer or a new forge buffer class #146
Comments
@dlongley I saw that code. Was about to start implementing something myself. What isn't done? I'd happily keep working on this if you could point out which areas are still "experimental". I think the general idea of implementing an "interface" of sorts (sorry, I come from OO land) is a good idea. Having a generic |
Here's what needs to be done:
IIRC, I tried to mark the experimental stuff as "Experimental" in the docs in the code, so hopefully you can search for functions marked as such.
Agreed, this is a good use case for an interface. But, never go full-OO :). A better way to put it -- OO is a useful paradigm... for exactly this kind of problem. I find it troubling when it is used as a panacea because, in general, the end result is that people end up writing a lot of code that does nothing (it's all abstraction code) and that leaves far less time for actually useful code.
Yeah, we just want forge to be using an interface for the (Byte)(Something)(Buffer). This is probably the best first step -- getting the APIs to be consistently using this interface for inputs and outputs. Then we can focus on getting the TypedArray/DataView version fixed up (I see you mentioned it in another issue). This would also aid in letting us get some performance tests written so we can swap them out and see how things perform in various browsers and in node. We can then set some sane defaults based on platform -- but allow the user to configure which underlying implementation they want to use if they really want to. There's probably more I could brain dump in here, but I'll respond to some other issues now. Btw, @jduncanator, it would be awesome if you want to contribute! |
We also need more unit tests and I'd like to have some decent performance tests that could be run to check for regressions, etc. It would be nice to have those before making changes to establish some base lines, but if that's not possible, I can accept that. |
@dlongley The reason I'm here is to contribute 😉 I'd be more than willing to work on this considering this is an area I actually know what I'm doing 😛 The "design" of the interface is really what needs to be decided on here, not so much the implementation. Ideally we'd do an audit of the code base and single out which parts of the API don't accept ForgeBuffers and change it so they do. To keep things backwards compatible I think we should employ something Node.js has. Return binary strings by default, but allow the user to specify an "output" encoding as well. For example I think the name shouldn't really matter. Ideally we would try and maintain the current ForgeBuffer API and simply implement it in a different way internally. That way the user doesn't even need to care that things changed, they just see a more performant ForgeBuffer (by ForgeBuffer I'm referring to the existing Buffer implementation). Personally, I think that the ForgeBuffer should be completely transparent and should be the only thing consumers should ever have to create and interface with, with the library managing the "backing" store internally. I'll start working on a unified buffer implementation that tries to be as much backwards compatible as possible based around the current string-backed buffers. Once that's done it should be trivial to implement TypedArrays. Regarding performance and unit tests, I agree. We should most certainly be writing unit tests as we develop the new code, as well as develop regression tests for anything that breaks during the development. You can never have too many tests! |
We should also try and get a decent encoding implementation developed too! Rather than have the code directly in the buffer implementation, modularize it and keep it separate. Helps with fixing issues. I'd be more than happy to port the Node.js implementations over to forge! |
Great! Also note that some work was started on this in js/util.js, for instance the ArrayBuffer-backed implementation: https://github.com/digitalbazaar/forge/blob/master/js/util.js#L630. In general, search for "Experimental" in that file. Just want to make sure you know there's something to work off of already. You may have just been giving an example, but regarding changing I think the order of priorities ought to be:
Obviously, getting all three is optimal -- and there may have to be exceptions in certain cases. I agree that we ought to do an audit on existing functions and categorize things like so: Buffers as inputs:
Buffers as outputs (return values):
|
@dlongley Introducing some new methods on top of the buffer is actually a really good idea. We would have almost zero issues with backwards compatibility and we can make the API a lot more sane (currently the method names are, lets say, a little odd...)! |
Some thoughts, suggestions:
|
Some of the buffer-centric API changes have begun on this branch: https://github.com/digitalbazaar/forge/tree/buffer-based-api The plan is to just go ahead and break the API as needed to support requiring buffers as inputs and outputs and release a new minor version (we're still under 1.0 so it won't be a major change) so we'll be pushing out 0.7 with a changelog entry that indicates the breakages. |
See #200 for some potential encoding optimizations. |
Where are we at with this? |
We've made pretty decent progress. There's still more to do, but most of the work has been completed in the buffer-based-api branch. For a comparison to master see: https://github.com/digitalbazaar/forge/compare/buffer-based-api We still need to:
That branch will also become the 0.7.x branch as it encompasses a few more features from the roadmap than just buffer-related fixes/changes. |
any updates on |
I'd say forge 0.7.x is about 80-90% done (which is where the TypedArray support has been added), but we've been spread a bit thin lately on a number of different higher-priority projects. As time frees up, we'll shift back and finish up. |
@dlongley thanks for the update! |
👍 |
What happened to this issue? |
In making forge APIs more consistent and to better take advantage of the features available on various platforms (eg: TypedArrays), the forge APIs should be changed to work with forge ByteBuffers or a new forge *Buffer class (name TBD) instead of binary-encoded strings where applicable. The general approach should always be to accept a forge *Buffer and output a forge *Buffer, but APIs can be more flexible as needed; however, if a string can be accepted, then an encoding parameter should be given or a default should be spelled out clearly in the documentation.
Work has begun on a TypedArray-based ByteBuffer vs. the binary-encoded string-based ByteBuffer -- and this should be advanced along-side work to convert APIs to *Buffer inputs/outputs. Some of this new work started returning TypedArrays but it should be changed to return *Buffers by default.
The text was updated successfully, but these errors were encountered: