moved tests to test directory

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5209 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-06-09 18:45:35 +00:00
parent af1fe976e2
commit 2e05d0ef01
3 changed files with 57 additions and 9 deletions

View File

@ -137,7 +137,7 @@ int AuthGPG::GPGInit(const std::string &ownId)
{
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId << std::endl;
mOwnGpgId = PGPIdType::fromUserId_hex(ownId);
mOwnGpgId = PGPIdType(ownId);
//force the validity of the private key. When set to unknown, it caused signature and text encryptions bugs
privateTrustCertificate(ownId, 5);
@ -571,7 +571,7 @@ bool AuthGPG::VerifySignature(const void *data, int datalen, const void *sig, un
return false ;
}
return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,PGPFingerprintType::fromFingerprint_hex(withfingerprint)) ;
return PGPHandler::VerifySignBin((unsigned char*)data,datalen,(unsigned char*)sig,siglen,PGPFingerprintType(withfingerprint)) ;
}
@ -607,7 +607,7 @@ std::string AuthGPG::getGPGName(const std::string &id)
}
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType::fromUserId_hex(id)) ;
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
if(info != NULL)
return info->_name ;
@ -619,7 +619,7 @@ std::string AuthGPG::getGPGName(const std::string &id)
std::string AuthGPG::getGPGEmail(const std::string &id)
{
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType::fromUserId_hex(id)) ;
const PGPCertificateInfo *info = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
if(info != NULL)
return info->_email ;
@ -703,7 +703,7 @@ bool AuthGPG::getGPGDetails(const std::string& id, RsPeerDetails &d)
return false ;
}
const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(PGPIdType::fromUserId_hex(id)) ;
const PGPCertificateInfo *pc = PGPHandler::getCertificateInfo(PGPIdType(id)) ;
if(pc == NULL)
return false ;
@ -764,7 +764,7 @@ bool AuthGPG::getGPGSignedList(std::list<std::string> &ids)
bool AuthGPG::getCachedGPGCertificate(const std::string &id, std::string &certificate)
{
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
certificate = PGPHandler::SaveCertificateToString(PGPIdType::fromUserId_hex(id),false) ;
certificate = PGPHandler::SaveCertificateToString(PGPIdType(id),false) ;
#ifdef LIMIT_CERTIFICATE_SIZE
std::string cleaned_key ;
@ -795,7 +795,7 @@ std::string AuthGPG::SaveCertificateToString(const std::string &id,bool include_
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
std::string tmp = PGPHandler::SaveCertificateToString(PGPIdType::fromUserId_hex(id),include_signatures) ;
std::string tmp = PGPHandler::SaveCertificateToString(PGPIdType(id),include_signatures) ;
// Try to remove signatures manually.
//
@ -843,7 +843,7 @@ bool AuthGPG::AllowConnection(const std::string &gpg_id, bool accept)
/* Was a "Reload Certificates" here -> be shouldn't be needed -> and very expensive, try without. */
{
RsStackMutex stack(gpgMtxData);
PGPHandler::setAcceptConnexion(PGPIdType::fromUserId_hex(gpg_id),accept) ;
PGPHandler::setAcceptConnexion(PGPIdType(gpg_id),accept) ;
}
IndicateConfigChanged();
@ -1661,7 +1661,7 @@ bool AuthGPG::loadList(std::list<RsItem*>& load)
std::list<RsTlvKeyValue>::iterator kit;
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++)
if (kit->key != mOwnGpgId.toStdString())
PGPHandler::setAcceptConnexion(PGPIdType::fromUserId_hex(kit->key), (kit->value == "TRUE"));
PGPHandler::setAcceptConnexion(PGPIdType(kit->key), (kit->value == "TRUE"));
}
delete (*it);
}

View File

@ -0,0 +1,48 @@
// COMPILE_LINE: g++ -o test_pgp_signature_parsing test_pgp_signature_parsing.cc -g -I../../../openpgpsdk/include -I../ -L../lib -lretroshare ../../../libbitdht/src/lib/libbitdht.a ../../../openpgpsdk/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2
//
#include <stdlib.h>
#include <iostream>
#include "pgphandler.h"
static std::string passphrase_callback(void *data,const char *uid_info,const char *what,int prev_was_bad)
{
return std::string(getpass(what)) ;
}
static std::string stringFromBytes(unsigned char *bytes,size_t len)
{
static const char out[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' } ;
std::string res ;
for(int j = 0; j < len; j++)
{
res += out[ (bytes[j]>>4) ] ;
res += out[ bytes[j] & 0xf ] ;
}
return res ;
}
int main(int argc,char *argv[])
{
// test pgp ids.
//
PGPIdType id = PGPIdType::fromUserId_hex("3e5b22140ef56abb") ;
std::cerr << "Id is : " << std::hex << id.toUInt64() << std::endl;
std::cerr << "Id st : " << id.toStdString() << std::endl;
// test PGPHandler
//
// 0 - init
static const std::string pubring = "globo.gpg" ;
static const std::string secring = "globo.gpg" ;
PGPHandler::setPassphraseCallback(&passphrase_callback) ;
PGPHandler pgph(pubring,secring) ;
pgph.printKeys() ;
}