Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion std/digest/crc.d
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ unittest
{
//Let's use the template features:
//Note: When passing a CRC32 to a function, it must be passed by reference!
void doSomething(T)(ref T hash) if(isDigest!T)
void doSomething(T)(ref T hash) if (isDigest!T)
{
hash.put(cast(ubyte)0);
}
Expand Down
40 changes: 20 additions & 20 deletions std/digest/digest.d
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ unittest
import std.stdio;

// Digests a file and prints the result.
void digestFile(Hash)(string filename) if(isDigest!Hash)
void digestFile(Hash)(string filename) if (isDigest!Hash)
{
auto file = File(filename);
auto result = digest!Hash(file.byChunk(4096 * 1024));
Expand All @@ -116,7 +116,7 @@ unittest
import std.digest.crc, std.digest.sha, std.digest.md;
import std.stdio;
// Digests a file and prints the result.
void digestFile(Hash)(ref Hash hash, string filename) if(isDigest!Hash)
void digestFile(Hash)(ref Hash hash, string filename) if (isDigest!Hash)
{
File file = File(filename);

Expand Down Expand Up @@ -303,7 +303,7 @@ unittest
unittest
{
import std.digest.crc;
void myFunction(T)() if(isDigest!T)
void myFunction(T)() if (isDigest!T)
{
T dig;
dig.start();
Expand All @@ -317,7 +317,7 @@ unittest
*/
template DigestType(T)
{
static if(isDigest!T)
static if (isDigest!T)
{
alias DigestType =
ReturnType!(typeof(
Expand Down Expand Up @@ -377,7 +377,7 @@ unittest
unittest
{
import std.digest.crc;
void myFunction(T)() if(hasPeek!T)
void myFunction(T)() if (hasPeek!T)
{
T dig;
dig.start();
Expand Down Expand Up @@ -424,7 +424,7 @@ package template isDigestibleRange(Range)
* Params:
* range= an $(D InputRange) with $(D ElementType) $(D ubyte), $(D ubyte[]) or $(D ubyte[num])
*/
DigestType!Hash digest(Hash, Range)(auto ref Range range) if(!isArray!Range
DigestType!Hash digest(Hash, Range)(auto ref Range range) if (!isArray!Range
&& isDigestibleRange!Range)
{
import std.algorithm : copy;
Expand All @@ -449,11 +449,11 @@ unittest
* Params:
* data= one or more arrays of any type
*/
DigestType!Hash digest(Hash, T...)(scope const T data) if(allSatisfy!(isArray, typeof(data)))
DigestType!Hash digest(Hash, T...)(scope const T data) if (allSatisfy!(isArray, typeof(data)))
{
Hash hash;
hash.start();
foreach(datum; data)
foreach (datum; data)
hash.put(cast(const(ubyte[]))datum);
return hash.finish();
}
Expand Down Expand Up @@ -486,7 +486,7 @@ unittest
* range= an $(D InputRange) with $(D ElementType) $(D ubyte), $(D ubyte[]) or $(D ubyte[num])
*/
char[digestLength!(Hash)*2] hexDigest(Hash, Order order = Order.increasing, Range)(ref Range range)
if(!isArray!Range && isDigestibleRange!Range)
if (!isArray!Range && isDigestibleRange!Range)
{
return toHexString!order(digest!Hash(range));
}
Expand All @@ -508,7 +508,7 @@ unittest
* data= one or more arrays of any type
*/
char[digestLength!(Hash)*2] hexDigest(Hash, Order order = Order.increasing, T...)(scope const T data)
if(allSatisfy!(isArray, typeof(data)))
if (allSatisfy!(isArray, typeof(data)))
{
return toHexString!order(digest!Hash(data));
}
Expand Down Expand Up @@ -611,7 +611,7 @@ interface Digest
final @trusted nothrow ubyte[] digest(scope const(void[])[] data...)
{
this.reset();
foreach(datum; data)
foreach (datum; data)
this.put(cast(ubyte[])datum);
return this.finish();
}
Expand Down Expand Up @@ -713,9 +713,9 @@ char[num*2] toHexString(Order order = Order.increasing, size_t num, LetterCase l
char[num*2] result;
size_t i;

static if(order == Order.increasing)
static if (order == Order.increasing)
{
foreach(u; digest)
foreach (u; digest)
{
result[i++] = hexDigits[u >> 4];
result[i++] = hexDigits[u & 15];
Expand All @@ -724,7 +724,7 @@ char[num*2] toHexString(Order order = Order.increasing, size_t num, LetterCase l
else
{
size_t j = num - 1;
while(i < num*2)
while (i < num*2)
{
result[i++] = hexDigits[digest[j] >> 4];
result[i++] = hexDigits[digest[j] & 15];
Expand Down Expand Up @@ -756,9 +756,9 @@ string toHexString(Order order = Order.increasing, LetterCase letterCase = Lette
auto result = new char[digest.length*2];
size_t i;

static if(order == Order.increasing)
static if (order == Order.increasing)
{
foreach(u; digest)
foreach (u; digest)
{
result[i++] = hexDigits[u >> 4];
result[i++] = hexDigits[u & 15];
Expand All @@ -767,7 +767,7 @@ string toHexString(Order order = Order.increasing, LetterCase letterCase = Lette
else
{
import std.range : retro;
foreach(u; retro(digest))
foreach (u; retro(digest))
{
result[i++] = hexDigits[u >> 4];
result[i++] = hexDigits[u & 15];
Expand Down Expand Up @@ -838,7 +838,7 @@ ref T[N] asArray(size_t N, T)(ref T[] source, string errorMsg = "")
* useful for other purposes as well. It returns the length (in bytes) of the hash value
* produced by T.
*/
template digestLength(T) if(isDigest!T)
template digestLength(T) if (isDigest!T)
{
enum size_t digestLength = (ReturnType!(T.finish)).length;
}
Expand All @@ -848,7 +848,7 @@ template digestLength(T) if(isDigest!T)
* Modules providing digest implementations will usually provide
* an alias for this template (e.g. MD5Digest, SHA1Digest, ...).
*/
class WrapperDigest(T) if(isDigest!T) : Digest
class WrapperDigest(T) if (isDigest!T) : Digest
{
protected:
T _digest;
Expand Down Expand Up @@ -943,7 +943,7 @@ class WrapperDigest(T) if(isDigest!T) : Digest
///ditto
@trusted ubyte[] peek() const;
}
else static if(hasPeek!T)
else static if (hasPeek!T)
{
@trusted ubyte[] peek(scope ubyte[] buf) const
in
Expand Down
2 changes: 1 addition & 1 deletion std/digest/md.d
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ unittest
unittest
{
//Let's use the template features:
void doSomething(T)(ref T hash) if(isDigest!T)
void doSomething(T)(ref T hash) if (isDigest!T)
{
hash.put(cast(ubyte)0);
}
Expand Down
2 changes: 1 addition & 1 deletion std/digest/ripemd.d
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ unittest
unittest
{
//Let's use the template features:
void doSomething(T)(ref T hash) if(isDigest!T)
void doSomething(T)(ref T hash) if (isDigest!T)
{
hash.put(cast(ubyte)0);
}
Expand Down
38 changes: 19 additions & 19 deletions std/digest/sha.d
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
static assert(!(blockSize == 1024 && digestSize < 224),
"Invalid SHA digestSize for a blockSize of 1024. The digestSize must be 224, 256, 384 or 512.");

static if(digestSize==160) /* SHA-1 */
static if (digestSize==160) /* SHA-1 */
{
version(USE_SSSE3)
{
Expand All @@ -230,35 +230,35 @@ struct SHA(uint hashBlockSize, uint digestSize)
alias transform = transformX86;
}
}
else static if(blockSize == 512) /* SHA-224, SHA-256 */
else static if (blockSize == 512) /* SHA-224, SHA-256 */
alias transform = transformSHA2!uint;
else static if(blockSize == 1024) /* SHA-384, SHA-512, SHA-512/224, SHA-512/256 */
else static if (blockSize == 1024) /* SHA-384, SHA-512, SHA-512/224, SHA-512/256 */
alias transform = transformSHA2!ulong;
else
static assert(0);

private:
/* magic initialization constants - state (ABCDEFGH) */
static if(blockSize == 512 && digestSize == 160) /* SHA-1 */
static if (blockSize == 512 && digestSize == 160) /* SHA-1 */
{
uint[5] state =
[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0];
}
else static if(blockSize == 512 && digestSize == 224) /* SHA-224 */
else static if (blockSize == 512 && digestSize == 224) /* SHA-224 */
{
uint[8] state = [
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,
];
}
else static if(blockSize == 512 && digestSize == 256) /* SHA-256 */
else static if (blockSize == 512 && digestSize == 256) /* SHA-256 */
{
uint[8] state = [
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
];
}
else static if(blockSize == 1024 && digestSize == 224) /* SHA-512/224 */
else static if (blockSize == 1024 && digestSize == 224) /* SHA-512/224 */
{
ulong[8] state = [
0x8C3D37C8_19544DA2, 0x73E19966_89DCD4D6,
Expand All @@ -267,7 +267,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
0x3F9D85A8_6A1D36C8, 0x1112E6AD_91D692A1,
];
}
else static if(blockSize == 1024 && digestSize == 256) /* SHA-512/256 */
else static if (blockSize == 1024 && digestSize == 256) /* SHA-512/256 */
{
ulong[8] state = [
0x22312194_FC2BF72C, 0x9F555FA3_C84C64C2,
Expand All @@ -276,7 +276,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
0x2B0199FC_2C85B8AA, 0x0EB72DDC_81C52CA2,
];
}
else static if(blockSize == 1024 && digestSize == 384) /* SHA-384 */
else static if (blockSize == 1024 && digestSize == 384) /* SHA-384 */
{
ulong[8] state = [
0xcbbb9d5d_c1059ed8, 0x629a292a_367cd507,
Expand All @@ -285,7 +285,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
0xdb0c2e0d_64f98fa7, 0x47b5481d_befa4fa4,
];
}
else static if(blockSize == 1024 && digestSize == 512) /* SHA-512 */
else static if (blockSize == 1024 && digestSize == 512) /* SHA-512 */
{
ulong[8] state = [
0x6a09e667_f3bcc908, 0xbb67ae85_84caa73b,
Expand All @@ -298,7 +298,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
static assert(0);

/* constants */
static if(blockSize == 512)
static if (blockSize == 512)
{
static immutable uint[64] constants = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
Expand All @@ -311,7 +311,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
];
}
else static if(blockSize == 1024)
else static if (blockSize == 1024)
{
static immutable ulong[80] constants = [
0x428a2f98_d728ae22, 0x71374491_23ef65cd, 0xb5c0fbcf_ec4d3b2f, 0xe9b5dba5_8189dbbc,
Expand Down Expand Up @@ -632,7 +632,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
T_SHA2_16_79!Word(62, W, C, D, E, F, G, H, A, B, constants[62]);
T_SHA2_16_79!Word(63, W, B, C, D, E, F, G, H, A, constants[63]);

static if(is(Word==ulong))
static if (is(Word==ulong))
{
T_SHA2_16_79!Word(64, W, A, B, C, D, E, F, G, H, constants[64]);
T_SHA2_16_79!Word(65, W, H, A, B, C, D, E, F, G, constants[65]);
Expand Down Expand Up @@ -702,14 +702,14 @@ struct SHA(uint hashBlockSize, uint digestSize)
index = (cast(uint)count[0] >> 3) & (blockSizeInBytes - 1);

/* Update number of bits */
static if(blockSize==512)
static if (blockSize==512)
count[0] += inputLen * 8;
else static if(blockSize==1024)
else static if (blockSize==1024)
{
/* ugly hack to work around lack of ucent */
auto oldCount0 = count[0];
count[0] += inputLen * 8;
if(count[0] < oldCount0)
if (count[0] < oldCount0)
count[1]++;
}
else
Expand Down Expand Up @@ -752,7 +752,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
*/
ubyte[digestSize/8] finish() @trusted pure nothrow @nogc
{
static if(blockSize==512)
static if (blockSize==512)
{
ubyte[32] data = void;
uint index, padLen;
Expand All @@ -776,7 +776,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
start();
return data[0..digestSize/8];
}
else static if(blockSize==1024)
else static if (blockSize==1024)
{
ubyte[64] data = void;
uint index, padLen;
Expand Down Expand Up @@ -854,7 +854,7 @@ unittest
{
//Let's use the template features:
//Note: When passing a SHA1 to a function, it must be passed by reference!
void doSomething(T)(ref T hash) if(isDigest!T)
void doSomething(T)(ref T hash) if (isDigest!T)
{
hash.put(cast(ubyte)0);
}
Expand Down