Skip to content

Commit

Permalink
Trivial: Simplify md5hash by removing support for DMD < v2.061
Browse files Browse the repository at this point in the history
This static if branch has been used for the last 11 years,
so it time to simplify it. Also slightly change the prototype
in the process to get rid of a safe/scope deprecation.
  • Loading branch information
Geod24 committed Jun 10, 2024
1 parent 85409d7 commit 1880c91
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions source/userman/db/controller.d
Original file line number Diff line number Diff line change
Expand Up @@ -353,23 +353,13 @@ unittest {
assert(validatePasswordHash(h, "foobar"));
}

private ubyte[16] md5hash(ubyte[] salt, string[] strs...)
private ubyte[16] md5hash(scope const(ubyte)[] salt, const string[] strs...)
@safe {
static if( __traits(compiles, {import std.digest.md;}) ){
import std.digest.md;
MD5 ctx;
ctx.start();
ctx.put(salt);
foreach( s; strs ) ctx.put(cast(const(ubyte)[])s);
return ctx.finish();
} else {
import std.md5;
ubyte[16] hash;
MD5_CTX ctx;
ctx.start();
ctx.update(salt);
foreach( s; strs ) ctx.update(s);
ctx.finish(hash);
return hash;
}
import std.digest.md;

MD5 ctx;
ctx.start();
ctx.put(salt);
foreach (s; strs) ctx.put(cast(const(ubyte)[])s);
return ctx.finish();
}

0 comments on commit 1880c91

Please sign in to comment.