fixed some small regressions and moved endian functions to a separate module

This commit is contained in:
Johannes Loher 2016-02-16 19:47:17 +01:00
parent 4fa22fa22a
commit f497922618
5 changed files with 28 additions and 27 deletions

View file

@ -66,6 +66,7 @@ int main(string[] args)
result.helpWanted = true; result.helpWanted = true;
} }
if(result.helpWanted)
printHelp(result.options); printHelp(result.options);
return 0; return 0;

View file

@ -1,7 +1,6 @@
module bitmanip; module bitmanip;
private import std.traits : isUnsigned; 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 UIntType rotateLeft(UIntType)(in UIntType val, in size_t len) nothrow @nogc pure @safe
if(isUnsigned!UIntType) if(isUnsigned!UIntType)
@ -36,26 +35,3 @@ unittest
assert(test[2].rotateRight(1) == 64); assert(test[2].rotateRight(1) == 64);
assert(test[2].rotateRight(7) == 1); 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);
}

View file

@ -2,10 +2,10 @@ module chacha20;
private import std.string : format; private import std.string : format;
private import std.range : isInputRange, isForwardRange, ElementType; private import std.range : isInputRange, isForwardRange, ElementType;
private import std.bitmanip : nativeToLittleEndian, littleEndianToNative;
private import std.array; private import std.array;
private import bitmanip; private import bitmanip;
private import endian;
public: public:

24
source/endian.d Normal file
View 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);
}

View file

@ -1,11 +1,11 @@
module salsa20; module salsa20;
private import std.traits : isUnsigned;
private import std.string : format; private import std.string : format;
private import std.range : isInputRange, isForwardRange, ElementType; private import std.range : isInputRange, isForwardRange, ElementType;
private import std.array; private import std.array;
private import bitmanip; private import bitmanip;
private import endian;
public: public: