It would be nice if it were possible to interface to CryptoJS using Javascript Typed Arrays.
A fairly low effort solution would be to allow WordArray to accept an ArrayBuffer as input and provide a conversion to ArrayBuffer as output. Would there be support for this addition if a patch were supplied to implement it?
Comment #1
Posted on Aug 22, 2012 by Happy HorseTo do that, I would probably extend WordArray to create a new TypedWordArray type that we could customize. And I'd probably keep that definition in a separate component file rather than in the core since it wouldn't be cross-browser.
In fact, since JavaScript is loosely typed, you should be able to pass WordArray a typed array, and it would just use it and continue on as normal. You may run into problems, however, when the library tries to use the standard array methods, such as push, slice and splice. Something to keep in mind if you decide to toy with the idea.
Comment #2
Posted on Aug 22, 2012 by Happy Horse(No comment was entered for this change.)
Comment #3
Posted on Aug 22, 2012 by Happy Horse(No comment was entered for this change.)
Comment #4
Posted on Aug 22, 2012 by Happy Horse(No comment was entered for this change.)
Comment #5
Posted on Aug 23, 2012 by Massive HorseI like the second idea of just having WordArray be able to accept an ArrayBuffer. That seems like the most natural fit for users of the library.
However, my thinking was to actually extract the data out of the ArrayBuffer, into the WordArray words member. Since this member is accessed directly in the library, this seems like the only real option without significant surgery.
Doing the ArrayBuffer <-> WordArray.words conversions won't be particularly fast, but they'll at least be convenient for users of the service.
Thoughts?
Comment #6
Posted on Jan 7, 2013 by Happy HorseThe latest release includes the ability to create WordArrays from typed arrays. You'll need to include an additional component -- lib-typedarrays.
var wordArray = CryptoJS.lib.WordArray.create(uint8View);You can create a WordArray from any of the typed array views -- Int8Array, Int16Array, etc. -- or from an ArrayBuffer, or from a DataView.
Comment #7
Posted on Jan 7, 2013 by Massive HorseThis is awesome! Thank you.
Status: Fixed
Labels:
Type-Enhancement
Priority-Medium