how to print ubyte*

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 30 00:53:24 PDT 2014


brad clawsie:

>       auto digest = HMAC(EVP_sha1(),
>                          cast(void *) key,

Better to attach the * to void.


>                          cast(int) key.length,
>                          cast(ubyte*) s,

Here you are casting a struct of pointer to immutable plus length 
to a mutable ubyte pointer.


>                          cast(int) s.length,
>                          null,null);

This whole function call is quite bug-prone.


> "digest" should be of type ubyte*
>
> does anyone know how to print this out as ascii?

Do you mean in hex? Perhaps something like this? But hardcodes 
the hash function output length:

writefln("%-(%02x%)", digest[0 .. 40])

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list