Skip to content

Commit

Permalink
Escape/unescape only when saving/loading
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed May 4, 2017
1 parent efa30de commit 3215451
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/credentials.cpp
Expand Up @@ -138,7 +138,7 @@ namespace preferences
if(cred == credentials.end()) {
return "";
}
return decrypt(unescape(cred->key), build_key(server, login));
return decrypt(cred->key, build_key(server, login));
}

void set_password(const std::string& server, const std::string& login, const std::string& key)
Expand All @@ -155,7 +155,7 @@ namespace preferences
// This is equivalent to emplace_back, but also returns the iterator to the new element
cred = credentials.emplace(credentials.end(), login, server, "");
}
cred->key = escape(encrypt(key, build_key(server, login)));
cred->key = encrypt(key, build_key(server, login));
}

void load_credentials()
Expand All @@ -181,7 +181,7 @@ namespace preferences
size_t at = elem.find_last_of('@');
size_t eq = elem.find_first_of('=', at + 1);
if(at != std::string::npos && eq != std::string::npos) {
credentials.emplace_back(elem.substr(0, at), elem.substr(at + 1, eq - at - 1), elem.substr(eq + 1));
credentials.emplace_back(elem.substr(0, at), elem.substr(at + 1, eq - at - 1), unescape(elem.substr(eq + 1)));
}
}
std::fill(data.begin(), data.end(), '\0');
Expand All @@ -200,7 +200,8 @@ namespace preferences
credentials_data.put('@');
std::copy(cred.server.begin(), cred.server.end(), std::ostreambuf_iterator<char>(credentials_data));
credentials_data.put('=');
std::copy(cred.key.begin(), cred.key.end(), std::ostreambuf_iterator<char>(credentials_data));
std::string key_escaped = escape(cred.key);
std::copy(key_escaped.begin(), key_escaped.end(), std::ostreambuf_iterator<char>(credentials_data));
}
credentials_data.put(CREDENTIAL_SEPARATOR);
try {
Expand Down

0 comments on commit 3215451

Please sign in to comment.