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
|
||||
}
|
||||
|
||||
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));
|
||||
|
|
Loading…
Reference in a new issue