fixed some small regressions and moved endian functions to a separate module
This commit is contained in:
parent
4fa22fa22a
commit
f497922618
5 changed files with 28 additions and 27 deletions
|
@ -66,7 +66,8 @@ int main(string[] args)
|
|||
result.helpWanted = true;
|
||||
}
|
||||
|
||||
printHelp(result.options);
|
||||
if(result.helpWanted)
|
||||
printHelp(result.options);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module bitmanip;
|
||||
|
||||
private import std.traits : isUnsigned;
|
||||
private import std.bitmanip : nativeToLittleEndian, littleEndianToNative;
|
||||
|
||||
UIntType rotateLeft(UIntType)(in UIntType val, in size_t len) nothrow @nogc pure @safe
|
||||
if(isUnsigned!UIntType)
|
||||
|
@ -36,26 +35,3 @@ unittest
|
|||
assert(test[2].rotateRight(1) == 64);
|
||||
assert(test[2].rotateRight(7) == 1);
|
||||
}
|
||||
|
||||
alias littleEndianInv = nativeToLittleEndian;
|
||||
|
||||
uint littleEndian(in ubyte[] input) @safe pure nothrow @nogc
|
||||
in
|
||||
{
|
||||
assert(input.length == uint.sizeof);
|
||||
}
|
||||
body
|
||||
{
|
||||
ubyte[uint.sizeof] buf = input;
|
||||
return littleEndianToNative!uint(buf);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
ubyte[] test0 = [0, 0, 0, 0];
|
||||
ubyte[] test1 = [86, 75, 30, 9];
|
||||
ubyte[] test2 = [255, 255, 255, 250];
|
||||
assert(littleEndian(test0) == 0x00000000);
|
||||
assert(littleEndian(test1) == 0x091e4b56);
|
||||
assert(littleEndian(test2) == 0xfaffffff);
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ module chacha20;
|
|||
|
||||
private import std.string : format;
|
||||
private import std.range : isInputRange, isForwardRange, ElementType;
|
||||
private import std.bitmanip : nativeToLittleEndian, littleEndianToNative;
|
||||
private import std.array;
|
||||
|
||||
private import bitmanip;
|
||||
private import endian;
|
||||
|
||||
public:
|
||||
|
||||
|
|
24
source/endian.d
Normal file
24
source/endian.d
Normal file
|
@ -0,0 +1,24 @@
|
|||
private import std.bitmanip : nativeToLittleEndian, littleEndianToNative;
|
||||
|
||||
alias littleEndianInv = nativeToLittleEndian;
|
||||
|
||||
uint littleEndian(in ubyte[] input) @safe pure nothrow @nogc
|
||||
in
|
||||
{
|
||||
assert(input.length == uint.sizeof);
|
||||
}
|
||||
body
|
||||
{
|
||||
ubyte[uint.sizeof] buf = input;
|
||||
return littleEndianToNative!uint(buf);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
ubyte[] test0 = [0, 0, 0, 0];
|
||||
ubyte[] test1 = [86, 75, 30, 9];
|
||||
ubyte[] test2 = [255, 255, 255, 250];
|
||||
assert(littleEndian(test0) == 0x00000000);
|
||||
assert(littleEndian(test1) == 0x091e4b56);
|
||||
assert(littleEndian(test2) == 0xfaffffff);
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
module salsa20;
|
||||
|
||||
private import std.traits : isUnsigned;
|
||||
private import std.string : format;
|
||||
private import std.range : isInputRange, isForwardRange, ElementType;
|
||||
private import std.array;
|
||||
|
||||
private import bitmanip;
|
||||
private import endian;
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in a new issue