Modified cipher.d to be more tidied up.

This commit is contained in:
Johannes Loher 2016-02-28 14:45:47 +01:00
parent 8c203bd412
commit 4452bd6b0a

View file

@ -14,11 +14,8 @@ enum Cipher
chacha20
}
mixin(cipherFunctionString.format(q{InputRange},
q{isInputRange!R && !(isForwardRange!R)}));
mixin(cipherFunctionString.format(q{ForwardRange},
q{isForwardRange!R}));
mixin(cipherFunctionString!(InputRange, isOnlyInputRange));
mixin(cipherFunctionString!(ForwardRange, isForwardRange));
unittest
{
@ -37,9 +34,14 @@ unittest
private:
enum cipherFunctionString = q{
template isOnlyInputRange(R)
{
enum isOnlyInputRange = isInputRange!R && !(isForwardRange!R);
}
enum cipherFunctionString(alias ReturnType, alias Constraint) = q{
%s!(ElementType!R) cipherFunction(R)(R range, ubyte[32] key, ubyte[8] nonce, Cipher cipher)
if (is(ElementType!R : ubyte) && %s)
if (is(ElementType!R : ubyte) && %s!R)
{
final switch (cipher)
{
@ -49,4 +51,4 @@ enum cipherFunctionString = q{
return range.chacha20Cipher(key, nonce).inputRangeObject;
}
}
};
}.format(__traits(identifier, ReturnType), __traits(identifier, Constraint));