Formating fixes

This commit is contained in:
Johannes Loher 2016-02-28 14:25:58 +01:00
parent 753a0cd366
commit 8c203bd412
6 changed files with 76 additions and 73 deletions

View file

@ -1,6 +1,6 @@
module actions; module actions;
import std.stdio; import std.stdio : File, stdin, stdout, writeln;
import std.base64 : Base64; import std.base64 : Base64;
import std.random : Random, uniform; import std.random : Random, uniform;
import std.algorithm : joiner; import std.algorithm : joiner;
@ -62,7 +62,8 @@ void generateKey(bool armor)
{ {
auto rng = Random(); auto rng = Random();
auto randomDevice = File(randomDeviceName, "r"); auto randomDevice = File(randomDeviceName, "r");
scope(exit) randomDevice.close(); scope (exit)
randomDevice.close();
uint[1] seed; uint[1] seed;
randomDevice.rawRead(seed); randomDevice.rawRead(seed);
rng.seed(seed[0]); rng.seed(seed[0]);
@ -86,6 +87,8 @@ private:
ubyte[32] loadKey(string filename, bool armor) ubyte[32] loadKey(string filename, bool armor)
{ {
auto keyFile = File(filename, "r"); auto keyFile = File(filename, "r");
scope (exit)
keyFile.close();
ubyte[32] key; ubyte[32] key;
if (armor) if (armor)
{ {

View file

@ -7,9 +7,7 @@ import actions;
int main(string[] args) int main(string[] args)
{ {
bool[string] actions = [ "genKey" : false, bool[string] actions = ["genKey" : false, "encrypt" : false, "decrypt" : false];
"encrypt" : false,
"decrypt" : false ];
Cipher cipher = Cipher.chacha20; Cipher cipher = Cipher.chacha20;
string keyFileName = "symkey.asc"; string keyFileName = "symkey.asc";
@ -18,8 +16,7 @@ int main(string[] args)
GetoptResult result; GetoptResult result;
try try
{ {
result = getopt( result = getopt(args,
args,
std.getopt.config.bundling, std.getopt.config.bundling,
"gen-key|g", "Generate a new 256 bit key.", &actions["genKey"], "gen-key|g", "Generate a new 256 bit key.", &actions["genKey"],
"encrypt|e", "Encrypt a message.", &actions["encrypt"], "encrypt|e", "Encrypt a message.", &actions["encrypt"],

View file

@ -3,7 +3,6 @@ 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.array; private import std.array;
private import std.traits : hasElaborateCopyConstructor;
private import bitmanip; private import bitmanip;
@ -223,8 +222,8 @@ out(result)
} }
body body
{ {
auto x00 = littleEndian(input[0..4]), x01 = littleEndian(input[4..8]), auto x00 = littleEndian(input[00..04]), x01 = littleEndian(input[04..08]),
x02 = littleEndian(input[8..12]), x03 = littleEndian(input[12..16]), x02 = littleEndian(input[08..12]), x03 = littleEndian(input[12..16]),
x04 = littleEndian(input[16..20]), x05 = littleEndian(input[20..24]), x04 = littleEndian(input[16..20]), x05 = littleEndian(input[20..24]),
x06 = littleEndian(input[24..28]), x07 = littleEndian(input[28..32]), x06 = littleEndian(input[24..28]), x07 = littleEndian(input[28..32]),
x08 = littleEndian(input[32..36]), x09 = littleEndian(input[36..40]), x08 = littleEndian(input[32..36]), x09 = littleEndian(input[36..40]),

View file

@ -1,6 +1,8 @@
module cipher; module cipher;
private import std.range : isInputRange, ElementType, InputRange, ForwardRange, inputRangeObject; private import std.range : isInputRange, isForwardRange, ElementType, InputRange, ForwardRange, inputRangeObject;
private import std.string : format;
private import salsa20; private import salsa20;
private import chacha20; private import chacha20;
@ -12,8 +14,11 @@ enum Cipher
chacha20 chacha20
} }
mixin(cipherFunctionString.format(q{InputRange}, q{isInputRange!R && !(isForwardRange!R)})); mixin(cipherFunctionString.format(q{InputRange},
mixin(cipherFunctionString.format(q{ForwardRange}, q{isForwardRange!R})); q{isInputRange!R && !(isForwardRange!R)}));
mixin(cipherFunctionString.format(q{ForwardRange},
q{isForwardRange!R}));
unittest unittest
{ {

View file

@ -3,7 +3,6 @@ module salsa20;
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 std.traits : hasElaborateCopyConstructor;
private import bitmanip; private import bitmanip;
@ -223,8 +222,8 @@ out(result)
} }
body body
{ {
auto x00 = littleEndian(input[0..4]), x01 = littleEndian(input[4..8]), auto x00 = littleEndian(input[00..04]), x01 = littleEndian(input[04..08]),
x02 = littleEndian(input[8..12]), x03 = littleEndian(input[12..16]), x02 = littleEndian(input[08..12]), x03 = littleEndian(input[12..16]),
x04 = littleEndian(input[16..20]), x05 = littleEndian(input[20..24]), x04 = littleEndian(input[16..20]), x05 = littleEndian(input[20..24]),
x06 = littleEndian(input[24..28]), x07 = littleEndian(input[28..32]), x06 = littleEndian(input[24..28]), x07 = littleEndian(input[28..32]),
x08 = littleEndian(input[32..36]), x09 = littleEndian(input[36..40]), x08 = littleEndian(input[32..36]), x09 = littleEndian(input[36..40]),