jerryscript-project / iotjs

Platform for Internet of Things with JavaScript http://www.iotjs.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crypto module

DanielBallaSZTE opened this issue · comments

Currently the WebSocket implementation relies on mbedTLS's hashing algorithms, namely base64 and sha1.

At the implementation steps of the WebSocket module, I was already thinking about creating a minimized crypto module that could grow out as we need more and more functions, however didn't feel like doing it for only one module.

Now, that we would also need some sort of crypto for HTTP Request Signature, I have already started making it.
However, there is one question that arises:
Do we:

  • strictly follow Node.js's crypto API
  • create our own minimized module ?

For me, I would vote for the latter, since from my personal standpoint Node's implementation would be a heavy overkill for such a task.

With that said, I am all open for any suggestions about the question.

For comparison:
Creating an sha1 hash in Node.js:

var hash = crypto.createHash('sha1');

hash.update('my string to hash');
console.log(hash.digest('hex'));

While we could have something as simple as:

console.log(crypto.sha1_encode('my string to hash', hexOrBinary));

I totally agree with the approach to creating a minimized crypto module that could grow out for more needs. However, meeting nodejs style APIs seems better, IMO.

Their api looks to have a single responsibility (creating instances/updating contents)/calculating digests). Such a design could flexibly cope with many unexpected demands and could reduce code complexity for any case.

I don't object to the idea of providing additional handy apis along with them.

I'm closing this issue, thank you for your answer!