Modified cipher.d to be more tidied up.
This commit is contained in:
parent
8c203bd412
commit
4452bd6b0a
1 changed files with 10 additions and 8 deletions
|
@ -14,11 +14,8 @@ enum Cipher
|
||||||
chacha20
|
chacha20
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin(cipherFunctionString.format(q{InputRange},
|
mixin(cipherFunctionString!(InputRange, isOnlyInputRange));
|
||||||
q{isInputRange!R && !(isForwardRange!R)}));
|
mixin(cipherFunctionString!(ForwardRange, isForwardRange));
|
||||||
|
|
||||||
mixin(cipherFunctionString.format(q{ForwardRange},
|
|
||||||
q{isForwardRange!R}));
|
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
|
@ -37,9 +34,14 @@ unittest
|
||||||
|
|
||||||
private:
|
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)
|
%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)
|
final switch (cipher)
|
||||||
{
|
{
|
||||||
|
@ -49,4 +51,4 @@ enum cipherFunctionString = q{
|
||||||
return range.chacha20Cipher(key, nonce).inputRangeObject;
|
return range.chacha20Cipher(key, nonce).inputRangeObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}.format(__traits(identifier, ReturnType), __traits(identifier, Constraint));
|
||||||
|
|
Loading…
Reference in a new issue