AWS API Dlang, hmac sha256 function.
holo via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Oct 3 05:49:12 PDT 2015
On Saturday, 3 October 2015 at 12:22:11 UTC, Rikki Cattermole
wrote:
> On 04/10/15 1:09 AM, holo wrote:
>> On Saturday, 3 October 2015 at 05:02:58 UTC, Rikki Cattermole
>> wrote:
>>> On 03/10/15 6:01 PM, Rikki Cattermole wrote:
>>>> On 03/10/15 4:54 PM, holo wrote:
>>>>> [...]
>>>>
>>>> By the looks of that error message with paths, botan isn't
>>>> actually
>>>> added as a dependency. Can you please paste the dub file?
>>>
>>> Ohhhh wait nevermind.
>>> Use dub to compile/run your program. You are using the
>>> shebang line!
>>>
>>> $ dub run
>>>
>>>>> [...]
>>>>
>>>> I can't say for certain if it is not exact. The reason I did
>>>> not answer
>>>> it is because I am not familiar with environment or any of
>>>> what you are
>>>> doing.
>>>> I can unfortunately only point you in the right direction.
>>
>> Thank you for explaining how to use dub.
>>
>> I find out in master branch of phobos on git hub is included
>> hmac.d
>> module which will be added in next release of phobos so i
>> think that
>> will be best solution for me to stick with standard library
>> for beginning.
>>
>> https://github.com/D-Programming-Language/phobos/tree/master/std
>>
>> I downloaded hmac.d and new version of digest.d file and place
>> them in
>> my phobos library. I think it exactly contains what i need but
>> when im
>> trying to test it i have such error:
>>
>> $ ./app.d
>> ./app.d(9): Error: template std.digest.hmac.hmac cannot deduce
>> function
>> from argument types !(SHA!(512, 256))(immutable(ubyte)[]),
>> candidates are:
>> /usr/include/dlang/dmd/std/digest/hmac.d(202):
>> std.digest.hmac.hmac(H)
>> if (isDigest!H && hasBlockSize!H)
>> /usr/include/dlang/dmd/std/digest/hmac.d(208):
>> std.digest.hmac.hmac(H,
>> ulong blockSize)(scope const(ubyte)[] secret) if (isDigest!H)
>> Failed: ["dmd", "-v", "-o-", "./app.d", "-I."]
>>
>>
>>
>> My test code (based on unint test from module) looks like that:
>>
>> #!/usr/bin/rdmd
>>
>> import std.stdio;
>> import std.digest.sha, std.digest.hmac;
>> import std.string : representation;
>>
>> void main()
>> {
>> auto hmac = hmac!SHA256("secretkey".representation);
>> auto digest =
>> hmac.put("texttohash".representation).finish;
>> writeln(digest);
>> }
>>
>> Am i using it correctly?
>
> By the looks of things the problem is with SHA256, I'm guessing
> it doesn't have its block size defined.
> https://github.com/D-Programming-Language/phobos/blob/master/std/digest/digest.d#L394
> You'll also need to update sha.d as well. Otherwise it looks
> good.
I updated sha.d and now im getting following error:
$ ./app.d
/usr/include/dlang/dmd/std/digest/sha.d(225): Error: pure
function 'std.digest.sha.SHA!(512u, 160u).SHA.transform' cannot
call impure function 'core.cpuid.ssse3'
/usr/include/dlang/dmd/std/digest/digest.d(285): Error: template
instance std.range.primitives.isOutputRange!(SHA!(512u, 160u),
const(ubyte)[]) error instantiating
/usr/include/dlang/dmd/std/digest/digest.d(851):
instantiated from here: isDigest!(SHA!(512u, 160u))
/usr/include/dlang/dmd/std/digest/sha.d(1179): while
looking for match for WrapperDigest!(SHA!(512u, 160u))
Failed: ["dmd", "-v", "-o-", "./app.d", "-I."]
More information about the Digitalmars-d-learn
mailing list