On 03/10/15 4:11 PM, holo wrote:
Hello
I'm trying to contact AWS API with D according to documentation:
http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
there is written example in python which i want to rewrite to D:
http://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
I want to ask about such 2 things:
Is it equivalent in D:
hexDigest!SHA256("sometexttohash");
for such python method:
hashlib.sha256('sometexttohash').hexdigest()
?
Maybe is there some prettier solution in D eg:
toHexString(sha256Of("sometexttohash"));
or
SHA256 sha;
sha.start();
string data = "sometexttohash";
sha.put(data);
toHexString(sha.finish())
If those are equivalents to python method which should i choose?
Last but not least, how to write such function in D:
def sign(key, msg):
return hmac.new(key, msg.encode("utf-8"), hashlib.sha256).digest()
?
I can't find in standard libraryt hmac function, is it existing?
//holo
You could implement it yourself, (it looks pretty easy).
Or go the route of Botan:
https://github.com/etcimon/botan/blob/3bdc835d5b9bad7523deaa86fe98b1fbb2f09d6b/source/botan/mac/hmac.d