1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-29 18:33:10 +00:00

keyring: squash opening and loading into one func

This commit is contained in:
Mirek Kratochvil 2013-09-12 12:14:58 +02:00
parent 7e32564119
commit 93cd8f377f
3 changed files with 30 additions and 44 deletions

@ -377,41 +377,6 @@ static bool file_put_sencode (const std::string&fn, sencode*in)
return true; return true;
} }
bool keyring::load()
{
std::string dir = get_user_dir();
std::string fn;
bool res;
/*
* pubkeys loading
*/
fn = dir + PUBKEYS_FILENAME;
sencode* pubkeys = file_get_sencode (fn);
if (!pubkeys) return false;
res = parse_pubkeys (pubkeys, pubs);
sencode_destroy (pubkeys);
if (!res) return false;
/*
* keypairs loading
*/
fn = dir + SECRETS_FILENAME;
sencode*keypairs = file_get_sencode (fn);
if (!keypairs) return false;
res = parse_keypairs (keypairs, pairs);
sencode_destroy (keypairs);
if (!res) return false;
//all okay
return true;
}
bool keyring::save() bool keyring::save()
{ {
std::string dir, fn; std::string dir, fn;
@ -457,7 +422,35 @@ bool keyring::open()
return false; return false;
} }
//load the public keys
fn = dir + PUBKEYS_FILENAME;
sencode *pubkeys, *keypairs;
bool res;
pubkeys = file_get_sencode (fn);
if (!pubkeys) goto close_and_fail;
res = parse_pubkeys (pubkeys, pubs);
sencode_destroy (pubkeys);
if (!res) goto close_and_fail;
//load keypairs
fn = dir + SECRETS_FILENAME;
keypairs = file_get_sencode (fn);
if (!keypairs) goto close_and_fail;
res = parse_keypairs (keypairs, pairs);
sencode_destroy (keypairs);
if (!res) goto close_and_fail;
//all okay
return true; return true;
close_and_fail:
close();
return false;
} }
bool keyring::close() bool keyring::close()

@ -83,7 +83,6 @@ public:
bool open(); bool open();
bool close(); bool close();
bool load();
bool save(); bool save();
static std::string get_keyid (const std::string& pubkey); static std::string get_keyid (const std::string& pubkey);

@ -392,14 +392,6 @@ int main (int argc, char**argv)
return 1; return 1;
} }
int exitval = 0;
if (!KR.load() ) {
err ("could not load keyring!");
exitval = 1;
goto exit;
}
//register all available algorithms //register all available algorithms
fill_algorithm_suite (AS); fill_algorithm_suite (AS);
@ -407,6 +399,8 @@ int main (int argc, char**argv)
* cin/cout redirection * cin/cout redirection
*/ */
int exitval = 0;
if (input.length() && !redirect_cin (input) ) { if (input.length() && !redirect_cin (input) ) {
progerr ("could not open input file"); progerr ("could not open input file");
exitval = 1; exitval = 1;