Consider this code:
```
import std.digest.digest;
import std.stdio;
ubyte[] hmac_sha1(const(ubyte)[] key, const(ubyte)[] message)
{
import std.digest.sha;
enum block_size = 64;
if (key.length > block_size)
key = sha1Of(key);
if (key.length < block
On Sunday, 5 July 2015 at 18:57:46 UTC, sigod wrote:
Why does function return incorrect data? Using `.dup` in return
expression or using `ubyte[20]` as return type fixes problem,
but why?
Because sha1Of() returns ubyte[20], this is a stack-allocated
array, a value type. If you put correct ret
On Monday, 6 July 2015 at 05:30:46 UTC, thedeemon wrote:
On Sunday, 5 July 2015 at 18:57:46 UTC, sigod wrote:
Why does function return incorrect data? Using `.dup` in
return expression or using `ubyte[20]` as return type fixes
problem, but why?
Because sha1Of() returns ubyte[20], this is a st
On Monday, 6 July 2015 at 07:48:17 UTC, sigod wrote:
Aren't compiler smart enough to prevent it?
```
ubyte[] test1()
{
auto b = sha1Of("");
return b; // Error: escaping reference to local b
}
ubyte[] test2()
{
return sha1Of(""); // works, but returns incorrect data
}
``
On Monday, 6 July 2015 at 10:20:28 UTC, anonymous wrote:
dmd 2.068.0 catches this. You can get the beta here:
http://downloads.dlang.org/pre-releases/2.x/2.068.0/
... and it already contains a std.digest.hmac module :-)
On Monday, 6 July 2015 at 10:20:28 UTC, anonymous wrote:
On Monday, 6 July 2015 at 07:48:17 UTC, sigod wrote:
Aren't compiler smart enough to prevent it?
```
ubyte[] test1()
{
auto b = sha1Of("");
return b; // Error: escaping reference to local b
}
ubyte[] test2()
{
re
On Monday, 6 July 2015 at 14:56:38 UTC, Marc Schütz wrote:
On Monday, 6 July 2015 at 10:20:28 UTC, anonymous wrote:
dmd 2.068.0 catches this. You can get the beta here:
http://downloads.dlang.org/pre-releases/2.x/2.068.0/
... and it already contains a std.digest.hmac module :-)
Yes, thanks.