added stdout store support

This commit is contained in:
Kevin Froman 2020-12-29 07:35:26 +00:00
parent cce0989c08
commit abc4709420
1 changed files with 14 additions and 1 deletions

View File

@ -24,7 +24,7 @@ namespace rinseoffcli
{ {
class Program class Program
{ {
public static string version = "0.0.0"; public static string version = "1.0.0";
enum ErrorCode : byte enum ErrorCode : byte
{ {
// Exit error codes indexed from 1 // Exit error codes indexed from 1
@ -44,6 +44,7 @@ namespace rinseoffcli
static void showHelp(ErrorCode exitCode = ErrorCode.InvaildArgs){ static void showHelp(ErrorCode exitCode = ErrorCode.InvaildArgs){
Console.WriteLine("RinseOff " + version + " High level secure-erasure utility"); Console.WriteLine("RinseOff " + version + " High level secure-erasure utility");
Console.WriteLine("For stdout output, specify 'stdout' as the data file for the store command");
Console.WriteLine("Must specify keygen <key path> or store/load, then a file name followed by a key file.\nFormat: <verb> <data file> <key file>"); Console.WriteLine("Must specify keygen <key path> or store/load, then a file name followed by a key file.\nFormat: <verb> <data file> <key file>");
Environment.Exit((int) exitCode); Environment.Exit((int) exitCode);
} }
@ -107,6 +108,14 @@ namespace rinseoffcli
static void storeData(string filepath, string keypath){ static void storeData(string filepath, string keypath){
byte[] encryptedInput = new byte[0]; byte[] encryptedInput = new byte[0];
void writeStdoutBytes(byte[] data){
var stdout = Console.OpenStandardOutput();
foreach (byte b in data){
stdout.WriteByte(b);
}
stdout.Flush();
}
byte[] readUntilClose(){ byte[] readUntilClose(){
// Read binary from STDIN until close // Read binary from STDIN until close
var readData = new List<byte>(); var readData = new List<byte>();
@ -138,6 +147,10 @@ namespace rinseoffcli
stderrWrite("Failed to read key file " + keypath); stderrWrite("Failed to read key file " + keypath);
Environment.Exit((int)ErrorCode.FailedToReadKeyFile); Environment.Exit((int)ErrorCode.FailedToReadKeyFile);
} }
if (filepath == "stdout"){
writeStdoutBytes(encryptedInput);
return;
}
try{ try{
File.WriteAllBytes(filepath, encryptedInput); File.WriteAllBytes(filepath, encryptedInput);
} }