Starting move to lib
[mnenc] / mnencd.hpp
index ba7e6a8..1dba0e7 100644 (file)
@@ -49,43 +49,41 @@ std::string make_filename(std::string user, std::string app) {
        name = getenv("USER");
        return "/home/" + name + "/.mnenc/" + remove_chars(app + user);
 }
-std::string get_password(std::string masterpasswd, std::string user, std::string app) {
-       mnenc menc = mnenc();
-       menc.genkey(masterpasswd);
-       std::string key = menc.get_key();
-       std::string enc, dec;
-       password pw = password("", "", key);
-       if(pw.from_file(make_filename(user, app))) {
-               enc = pw.get_enc();
-               dec = menc.decrypt(key, enc);
+std::string get_password(std::string user, std::string app) {
+       mnenc menc;
+       std::string dec;
+       if(menc.from_file(make_filename(user, app))) {
+               dec = menc.get_dec();
        } else {
                dec = "failure";
        }
        return dec;
 }
 
-void put_password(std::string masterpasswd, std::string passwd, std::string user, std::string app) {
-       mnenc menc = mnenc();
-       menc.genkey(masterpasswd);
-       std::string key = menc.get_key();
-       password pw = password(menc.encrypt(key, passwd ), "", key);
-       pw.to_file(make_filename(user, app));
+void put_password(std::string passwd, std::string user, std::string app) {
+       mnenc micke; //Declare a encryptor/decryptor
+       micke.encrypt(passwd); //Encrypt the password Blahonga
+       micke.to_file(make_filename(user, app)); //Save to file
+
+}
+
+std::string open_connection(std::string str) {
+       return "mhejj";
 }
+
+
 std::string do_something(std::string str) { //Handle requests for secure pipe
     pid_t proc = fork();
     std::string reply = "";
     if( proc == 0 ) { // child
         reply = open_connection( str );
-    } else if( p > 0 ) { // parent
-       // Store p somewhere
+    } else if( proc > 0 ) { // parent
     } else { // fork failed
     }
     
     return reply;
 }
-std::string open_connection(std::string str) {
 
-}
 std::string do_something_else(std::string str) { //Handle requests
 
        std::vector<std::string> request; //Incomming message stored here
@@ -106,7 +104,7 @@ std::string do_something_else(std::string str) { //Handle requests
                if(masterpasswd == "") { //If master password is not yet set
                        return "412_Precondition_Failed\n";
                } else { //If we have a master password to encrypt with
-                       put_password(masterpasswd, request[3], request[2], request[1]);
+                       put_password(request[3], request[2], request[1]);
                        return "201_Created\n";
                }
                
@@ -114,7 +112,7 @@ std::string do_something_else(std::string str) { //Handle requests
                if(masterpasswd == "") { //If master password is not yet set
                        return "412_Precondition_Failed\n";
                } else { //If we have a master password to encrypt with
-                       std::string pw = get_password(masterpasswd, request[2], request[1]);
+                       std::string pw = get_password(request[2], request[1]);
                        std::string message;
                        if(pw == "") {
                                message = "500_Internal_Server_Error\n";