[haiku-development] Re: Haiku "Crypto Kit"

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 11 Jan 2016 11:26:44 +0100

On 11.01.2016 03:51, Alexander von Gluck IV wrote:

Feedback *highly* welcome.
I've only invested a day or so into it... so if everyone hates the idea it's no
big deal :-)

When creating new Haiku APIs that already exist in mature tool kits, I can wholeheartedly recommend looking at and steal^Hborrowing ideas from those. In this case e.g. Java [1] and Qt [2]. Two issues are:

* You don't want to have a one-shot method only. When hashing a file or any kind of stream one usually processes the data iteratively. Therefore Java and Qt offer separate methods for processing data iteratively (update()/addData()) and computing the final hash (digest()/result()). Additional one-shot convenience methods (possibly even static ones) certainly don't harm, though.

* You don't want to return the hash as a hex string (only/by default). That is a representation mostly used for human consumption. Unfortunately lacking an appropriate Haiku API class there isn't a convenient way to return byte arrays of unknown size (I pre-allocated the array and added a method to return the size in headers/private/shared/SHA256.h). Obviously a method to convert a byte array to a BString is needed as well, but it would fit better as a (static) utility method in BString.

CU, Ingo

[1] https://docs.oracle.com/javase/7/docs/api/java/security/MessageDigest.html
[2] http://doc.qt.io/qt-5/qcryptographichash.html



Other related posts: