Background
I'm a procrastinator. Where others see an obstacle to surmount, I see an opportunity to put something away for later. Which is exactly what I did for my Erlang wrapper around the Windows Azure a few days ago. I discovered that Erlang didn't support SHA 256 out of the box, necessary for the HMAC-SHA256 needed for authenticating storage requests, I threw up my hands in a mediocre blog post, filed away my code for a later date when either Erlang added SHA 256 support to the crypto module (likely) or when I got around to implementing SHA 256 myself (not likely).
However, my procrastination this time was short lived. Steve Vinoski showed up in the comments and to my astonishment, whipped together a SHA-256 implementation. Having run out of excuses, I spent some time and finished up my client. Along the way, I wrote a HMAC-SHA256 module in Erlang which was an interesting exercise as well. You can find the GitHub project here. It's in its infancy and can only deal with blobs at the moment. But I am taking feature requests so holler if you need something.
Sample
I'm still unsure of the right idiomatic way to do most things in Erlang. I've created it using the gen_server OTP framework though in retrospect, a simple module would have sufficed. Here's some sample test code which accesses storage (the key and account for the local development storage which runs on my machine).
-module(winazuretest).
-export([test/0]).
test() ->
winazure:start({"",
"",
true}),
winazure:create_container("test",true),
winazure:put_blob("test","blob1","Hello!","text/plain"),
"Hello!" = winazure:get_blob("test","blob1"),
winazure:delete_blob("test","blob1"),
winazure:delete_container("test").
Observations
- I'm still learning the 'Erlang way' to do things. This is evident in my HMAC implementation and in my storage client. In some places, I have some ugly unspeakable hacks because I couldn't figure out 'the right way' to do it. I would love some feedback on how to 'Erlang-ize' my code.
- When implementing HMAC based on Wikipedia pseudocode, don't assume 'block size' is 256 just because your hash algorithm is 'SHA-256'. An assumption like could just lead to you staring at random strings of numbers for long periods of time on New Year's eve.
- There is some issue with either Erlang's HTTP 1.1 support or Windows Azure's HTTP 1.1 support or the combination of the two. The client keeps dying after a few calls. I couldn't figure it out so I switched to using HTTP 1.0.
- Erlang's bit syntax seems to be the equivalent of cryptic Perl one-liners. Something that a seasoned programmer can crank out with elan but a newbie scratches their head at. My 'bit-syntax-fu' is as weak as my 'regex-fu' and my nightmares now have double angle brackets in them.
- Distel and Erlang's emacs mode are the best way to code Erlang right now. I tried using TextMate's Erlang bundle for a few days but hitting "C-c C-k' to compile the current buffer and be thrown into a Erlang buffer is too good to give up.
- I now need to find some meaty project to do in Erlang which would need me to make use of Erlang's concurrency support.