added dialog box to import existing keyrings when starting the new pgp version for the first time

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5210 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-06-09 21:01:22 +00:00
parent 2e05d0ef01
commit a91e859b66
6 changed files with 145 additions and 28 deletions

View file

@ -81,10 +81,27 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring)
_pubring = allocateOPSKeyring() ;
_secring = allocateOPSKeyring() ;
// Check that the file exists. If not, create a void keyring.
FILE *ftest ;
ftest = fopen(pubring.c_str(),"rb") ;
bool pubring_exist = (ftest != NULL) ;
if(ftest != NULL)
fclose(ftest) ;
ftest = fopen(secring.c_str(),"rb") ;
bool secring_exist = (ftest != NULL) ;
if(ftest != NULL)
fclose(ftest) ;
// Read public and secret keyrings from supplied files.
//
if(ops_false == ops_keyring_read_from_file(_pubring, false, pubring.c_str()))
throw std::runtime_error("PGPHandler::readKeyRing(): cannot read pubring.") ;
if(pubring_exist)
{
if(ops_false == ops_keyring_read_from_file(_pubring, false, pubring.c_str()))
throw std::runtime_error("PGPHandler::readKeyRing(): cannot read pubring. File corrupted.") ;
}
else
std::cerr << "pubring file \"" << pubring << "\" not found. Creating a void keyring." << std::endl;
const ops_keydata_t *keydata ;
int i=0 ;
@ -104,8 +121,13 @@ PGPHandler::PGPHandler(const std::string& pubring, const std::string& secring)
}
std::cerr << "Pubring read successfully." << std::endl;
if(ops_false == ops_keyring_read_from_file(_secring, false, secring.c_str()))
throw std::runtime_error("PGPHandler::readKeyRing(): cannot read secring.") ;
if(secring_exist)
{
if(ops_false == ops_keyring_read_from_file(_secring, false, secring.c_str()))
throw std::runtime_error("PGPHandler::readKeyRing(): cannot read secring. File corrupted.") ;
}
else
std::cerr << "secring file \"" << secring << "\" not found. Creating a void keyring." << std::endl;
i=0 ;
while( (keydata = ops_keyring_get_key_by_index(_secring,i)) != NULL )