1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-28 18:03:36 +00:00

actions: gen_key

This commit is contained in:
Mirek Kratochvil 2013-04-21 10:00:51 +02:00
parent 2fb0392bb1
commit 03cd5abd73
2 changed files with 84 additions and 18 deletions

@ -18,9 +18,75 @@
#include "actions.h"
#include "iohelpers.h"
#include "generator.h"
#include "str_match.h"
int action_gen_key (const std::string& algspec, const std::string&name,
keyring&, algorithm_suite&)
keyring&KR, algorithm_suite&AS)
{
if (algspec == "help") {
//provide overview of algorithms available
err ("available algorithms:");
std::string tag = " ";
for (algorithm_suite::iterator i = AS.begin(), e = AS.end();
i != e; ++i) {
tag[1] = i->second->provides_signatures() ? 'S' : '-';
tag[3] = i->second->provides_encryption() ? 'E' : '-';
out (tag << i->first);
}
return 0;
}
algorithm*alg = NULL;
std::string algname;
for (algorithm_suite::iterator i = AS.begin(), e = AS.end();
i != e; ++i) {
if (algorithm_name_matches (algspec, i->first) ) {
if (!alg) {
algname = i->first;
alg = i->second;
} else {
err ("error: algorithm name `" << algspec
<< "' matches multiple algorithms");
return 1;
}
}
}
if (!alg) {
err ("error: no such algorithm");
return 1;
}
if (!name.length() ) {
err ("error: no key name provided");
return 1;
}
sencode *pub, *priv;
arcfour_rng r;
err ("Gathering random seed bits from kernel...");
err ("If nothing happens, move mouse, type random stuff on keyboard,");
err ("or just wait longer.");
r.seed (512, false);
err ("Seeding done, generating the key...");
if (alg->create_keypair (&pub, &priv, r) ) {
err ("error: key generator failed");
return 1;
}
KR.store_keypair (keyring::get_keyid (pub), name, algname, pub, priv);
if (!KR.save() ) {
err ("error: couldn't save keyring");
return 1;
}
return 0;
}
@ -29,41 +95,41 @@ int action_gen_key (const std::string& algspec, const std::string&name,
*/
int action_encrypt (const std::string&recipient, bool armor,
keyring&, algorithm_suite&)
keyring&KR, algorithm_suite&AS)
{
return 0;
}
int action_decrypt (bool armor,
keyring&, algorithm_suite&)
keyring&KR, algorithm_suite&AS)
{
return 0;
}
int action_sign (const std::string&user, bool armor, const std::string&detach,
keyring&, algorithm_suite&)
keyring&KR, algorithm_suite&AS)
{
return 0;
}
int action_verify (bool armor, const std::string&detach,
keyring&, algorithm_suite&)
keyring&KR, algorithm_suite&AS)
{
return 0;
}
int action_sign_encrypt (const std::string&user, const std::string&recipient,
bool armor, keyring&, algorithm_suite&)
bool armor, keyring&KR, algorithm_suite&AS)
{
return 0;
}
int action_decrypt_verify (bool armor, keyring&, algorithm_suite&)
int action_decrypt_verify (bool armor, keyring&KR, algorithm_suite&AS)
{
return 0;
}
@ -74,7 +140,7 @@ int action_decrypt_verify (bool armor, keyring&, algorithm_suite&)
*/
int action_list (bool nice_fingerprint, const std::string&filter,
keyring&)
keyring&KR)
{
return 0;
}
@ -82,7 +148,7 @@ int action_list (bool nice_fingerprint, const std::string&filter,
int action_import (bool armor, bool no_action, bool yes,
const std::string&filter, const std::string&name,
keyring&)
keyring&KR)
{
return 0;
}
@ -90,13 +156,13 @@ int action_import (bool armor, bool no_action, bool yes,
int action_export (bool armor,
const std::string&filter, const std::string&name,
keyring&)
keyring&KR)
{
return 0;
}
int action_delete (bool yes, const std::string&filter, keyring&)
int action_delete (bool yes, const std::string&filter, keyring&KR)
{
return 0;
}
@ -104,7 +170,7 @@ int action_delete (bool yes, const std::string&filter, keyring&)
int action_rename (bool yes,
const std::string&filter, const std::string&name,
keyring&)
keyring&KR)
{
return 0;
}
@ -112,7 +178,7 @@ int action_rename (bool yes,
int action_list_sec (bool nice_fingerprint, const std::string&filter,
keyring&)
keyring&KR)
{
return 0;
}
@ -120,7 +186,7 @@ int action_list_sec (bool nice_fingerprint, const std::string&filter,
int action_import_sec (bool armor, bool no_action, bool yes,
const std::string&filter, const std::string&name,
keyring&)
keyring&KR)
{
return 0;
}
@ -128,13 +194,13 @@ int action_import_sec (bool armor, bool no_action, bool yes,
int action_export_sec (bool armor,
const std::string&filter, const std::string&name,
keyring&)
keyring&KR)
{
return 0;
}
int action_delete_sec (bool yes, const std::string&filter, keyring&)
int action_delete_sec (bool yes, const std::string&filter, keyring&KR)
{
return 0;
}
@ -142,7 +208,7 @@ int action_delete_sec (bool yes, const std::string&filter, keyring&)
int action_rename_sec (bool yes,
const std::string&filter, const std::string&name,
keyring&)
keyring&KR)
{
return 0;
}

@ -57,7 +57,7 @@ void print_help (char*pname)
out (" -b, --detach-sign specify detached signature file");
outeol;
out ("Key management:");
out (" -g, --gen-key generate specified keypair");
out (" -g, --gen-key generate specified keypair, `help' lists algorithms");
out (" -k, --list list matching keys");
out (" -K, --list-secret");
out (" -i, --import import keys (optionally rename them)");