generalized the test for valid strings to all methods in AuthGPG

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7050 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-01-21 21:01:22 +00:00
parent 1f4580304f
commit 11bc15b9cf
2 changed files with 40 additions and 32 deletions

View File

@ -383,7 +383,7 @@ std::string AuthGPG::getGPGName(const std::string &id,bool *success)
}
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
const PGPCertificateInfo *info = getCertInfoFromStdString(id) ;
if(info != NULL)
{
@ -401,7 +401,7 @@ std::string AuthGPG::getGPGName(const std::string &id,bool *success)
std::string AuthGPG::getGPGEmail(const std::string &id,bool *success)
{
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
const PGPCertificateInfo *info = getCertInfoFromStdString(id) ;
if(info != NULL)
{
@ -440,13 +440,25 @@ bool AuthGPG::getGPGAllList(std::list<std::string> &ids)
return true;
}
const PGPCertificateInfo *AuthGPG::getCertInfoFromStdString(const std::string& pgp_id) const
{
try
{
return PGPHandler::getCertificateInfo(PGPIdType(pgp_id)) ;
}
catch(std::exception& e)
{
std::cerr << "(EE) exception raised while constructing a PGP certificate from id \"" << pgp_id << "\": " << e.what() << std::endl;
return NULL ;
}
}
bool AuthGPG::haveSecretKey(const std::string& id) const
{
return PGPHandler::haveSecretKey(PGPIdType(id)) ;
}
bool AuthGPG::isKeySupported(const std::string& id) const
{
const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
const PGPCertificateInfo *pc = getCertInfoFromStdString(id) ;
if(pc == NULL)
return false ;
@ -470,9 +482,7 @@ bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d)
return false ;
}
try
{
const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
const PGPCertificateInfo *pc = getCertInfoFromStdString(id) ;
if(pc == NULL)
return false ;
@ -495,12 +505,6 @@ bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d)
d.fpr = cert._fpr.toStdString();
d.accept_connection = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_ACCEPT_CONNEXION;
d.hasSignedMe = cert._flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME;
}
catch(std::exception& e)
{
std::cerr << "(EE) exception raised while constructing a PGP certificate: " << e.what() << std::endl;
return false ;
}
return true;
}

View File

@ -249,6 +249,10 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
/*****************************************************************/
private:
// Gets the certificate pointer and returns NULL if the string is invalid, or the
// cert was not found.
//
const PGPCertificateInfo *getCertInfoFromStdString(const std::string& ) const;
/* SKTAN */
//void showData(gpgme_data_t dh);