keyring: a little better structure

This commit is contained in:
Mirek Kratochvil 2013-04-15 16:00:26 +02:00
parent 5d4879a760
commit d3be589138
2 changed files with 48 additions and 5 deletions

View file

@ -95,14 +95,53 @@ std::string keyring::get_keyid (const std::string&pubkey)
*
*/
#include <stdlib.h>
static std::string get_user_dir()
{
const char*tmp = getenv ("CCR_DIR");
if (tmp) return tmp;
const char*home = getenv ("HOME");
if (home) return home + "/.ccr";
return "./.ccr"; //fallback for desolate systems
}
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
static bool prepare_user_dir (const string&dir)
{
//try to create the directory
mkdir (dir.c_str(), 0777);
//and no matter what, verify it's there
struct stat st;
if (stat (dir.c_str(), &st) )
return false;
if (!S_ISDIR (st.st_mode) )
return false;
return true; //seems m'kay
}
bool keyring::load()
{
return false;
}
bool keyring::save()
{
return false;
}
bool keyring::open()
{
}
bool keyring::close()
{
}

View file

@ -26,6 +26,7 @@
class keyring
{
int fd_priv, fd_pub;
public:
struct pubkey_entry {
sencode *key;
@ -64,18 +65,21 @@ public:
std::map<std::string, pubkey_entry> pubs;
std::map<std::string, keypair_entry> pairs;
explicit keyring() {
keyring() {
fd_priv = fd_pub = -1;
}
~keyring() {
clear();
}
void clear();
bool open();
bool close();
bool load();
bool save();
void clear();
static std::string get_keyid (const std::string& pubkey);
static std::string get_keyid (sencode* pubkey) {