diff --git a/cli/cli.csproj b/cli/cli.csproj
index aa96f51..bcdfb9e 100644
--- a/cli/cli.csproj
+++ b/cli/cli.csproj
@@ -7,7 +7,6 @@
-
diff --git a/cli/translations/spanish.cs b/cli/translations/spanish.cs
index 9b49155..efd79ec 100644
--- a/cli/translations/spanish.cs
+++ b/cli/translations/spanish.cs
@@ -19,6 +19,7 @@ namespace treasurechestCLI {
stringInst.ENCRYPT_MENU_USE_PASSPHRASE = "Usar frase de contraseña";
stringInst.ENCRYPT_MENU_USE_PUBKEY = "Usar clave pública";
stringInst.ENTER_MESSAGE_UNTIL_DONE = "Ingrese su mensaje y termine con -q en una nueva línea.";
+ stringInst.PASSPHRASE = "Frase de contraseña";
}
}
diff --git a/cli/translations/text.cs b/cli/translations/text.cs
index 821f42d..10e93ed 100644
--- a/cli/translations/text.cs
+++ b/cli/translations/text.cs
@@ -21,6 +21,7 @@ namespace treasurechestCLI {
public string ENCRYPT_MENU_USE_PASSPHRASE;
public string ENCRYPT_MENU_USE_PUBKEY;
public string ENTER_MESSAGE_UNTIL_DONE;
+ public string PASSPHRASE;
public Strings(){
@@ -44,6 +45,7 @@ namespace treasurechestCLI {
ENCRYPT_MENU_USE_PASSPHRASE = "Use passphrase";
ENCRYPT_MENU_USE_PUBKEY = "Use public key";
ENTER_MESSAGE_UNTIL_DONE = "Enter your message and finish with -q on a new line.";
+ PASSPHRASE = "Passphrase";
break;
}
diff --git a/cli/ui/getpass.cs b/cli/ui/getpass.cs
new file mode 100644
index 0000000..a738328
--- /dev/null
+++ b/cli/ui/getpass.cs
@@ -0,0 +1,21 @@
+using System.IO;
+using System;
+
+namespace getpass{
+
+ public class GetPass{
+ private static StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
+ public static string getPass(string message){
+ Console.Write(message + ": ");
+ Console.SetOut(StreamWriter.Null);
+ Console.SetError(StreamWriter.Null);
+ message = Console.ReadLine();
+ standardOutput.AutoFlush = true;
+ Console.SetOut(standardOutput);
+ Console.WriteLine();
+ return message;
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/cli/ui/interfaces/encrypt.cs b/cli/ui/interfaces/encrypt.cs
index b4a0a26..f9e2f1c 100644
--- a/cli/ui/interfaces/encrypt.cs
+++ b/cli/ui/interfaces/encrypt.cs
@@ -1,5 +1,7 @@
+using System.IO;
using System;
using treasurechest.STDIOWrapper;
+using getpass;
namespace treasurechestCLI{
@@ -7,6 +9,9 @@ namespace treasurechestCLI{
public static void EncryptMessage(){
int choice = 0;
int counter = 1;
+ string message;
+ string passphrase;
+
translations.Strings strings = new translations.Strings();
string[] encryptMenuOptions =
@@ -16,6 +21,7 @@ namespace treasurechestCLI{
strings.RETURN_TO_PREVIOUS_MENU
};
while(true){
+ counter = 1;
foreach(string option in encryptMenuOptions){
STDIO.O(counter.ToString() + ". " + option);
counter += 1;
@@ -39,12 +45,17 @@ namespace treasurechestCLI{
choice = encryptMenuOptions.Length;
}
if (choice == 1){
- GetMessage.getTypedMessage();
+ try {
+ message = GetMessage.getTypedMessage();
+ }
+ catch(System.NullReferenceException){
+ continue;
+ }
+ passphrase = GetPass.getPass(strings.PASSPHRASE);
}
else if (choice == encryptMenuOptions.Length){
break;
}
- counter = 1;
}
diff --git a/cli/ui/interfaces/getmessage.cs b/cli/ui/interfaces/getmessage.cs
index 3d818eb..aa1c4d0 100644
--- a/cli/ui/interfaces/getmessage.cs
+++ b/cli/ui/interfaces/getmessage.cs
@@ -13,7 +13,12 @@ namespace treasurechestCLI{
string line = "";
STDIO.O(strings.ENTER_MESSAGE_UNTIL_DONE);
while (true){
- line = Console.ReadLine();
+ try{
+ line = Console.ReadLine();
+ }
+ catch(System.ArgumentNullException){
+ line = "-q";
+ }
if (line.Equals("-q")){
break;
}
diff --git a/treasurechest/simplepack/pack.cs b/treasurechest/simplepack/pack.cs
index a6b3768..d2865fb 100644
--- a/treasurechest/simplepack/pack.cs
+++ b/treasurechest/simplepack/pack.cs
@@ -1,5 +1,4 @@
using Base58Check;
-using System;
namespace chestcrypto{
@@ -10,14 +9,15 @@ namespace chestcrypto{
private const string header = "CHEST-MESSAGE";
private const string footer = "END-CHEST-MESSAGE.";
+ // Test simplepackTest.TestPackUnpackBytes
public static string pack(byte[] data){
return header + Base58CheckEncoding.Encode(data) + footer;
}
-
+ // Test simplepackTest.TestPackUnpackString
public static string pack(string data){
return pack(System.Text.Encoding.UTF8.GetBytes(data));
}
-
+ // Test simplepackTest.TestPackUnpackBytes
public static byte[] unpack(string checkedBase58String){
if (! checkedBase58String.Contains(header) | ! checkedBase58String.Contains(footer)){
throw new exceptions.InvalidSimplePackMessage("Message does not have valid header and footer");