debugging of pgpkey parser and radix output form openpgpsdk

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5061 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-03-29 21:51:37 +00:00
parent 51fa97ac59
commit 648555711c
5 changed files with 67 additions and 32 deletions

View file

@ -160,7 +160,7 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
ops_user_id_t uid ;
const char *s = strdup((name + " " + email + " (Generated by RetroShare)").c_str()) ;
uid.user_id = (unsigned char *)s ;
unsigned long int e = 44497 ; // some prime number
unsigned long int e = 17 ; // some prime number
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(KEY_NUMBITS,e,&uid) ;
@ -171,25 +171,44 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
// Now output the pubkey to a string.
//
std::string akey = makeRadixEncodedPGPKey(key) ;
std::cerr << "key: " << std::endl;
std::cerr << akey << std::endl;
ops_keydata_free(key) ;
return true ;
}
std::string PGPHandler::makeRadixEncodedPGPKey(const ops_keydata_t *key)
{
ops_boolean_t armoured=ops_true;
ops_boolean_t overwrite=ops_true;
ops_create_info_t* cinfo;
ops_memory_t *buf = NULL ;//(ops_memory_t*)ops_mallocz(1000) ;
ops_setup_memory_write(&cinfo, &buf, 0);
ops_writer_push_armoured(cinfo,OPS_PGP_PUBLIC_KEY_BLOCK) ;
//ops_writer_push_armoured(cinfo,OPS_PGP_SIGNATURE) ;
ops_write_transferable_public_key(key,armoured,cinfo);
//ops_writer_close(cinfo) ;
ops_writer_close(cinfo) ;
std::cerr << "Memory written: size = " << ops_memory_get_length(buf) << std::endl;
std::cerr << "String of key: " << std::endl;
std::cerr << std::string((char *)ops_memory_get_data(buf),ops_memory_get_length(buf)) << std::endl;
std::string akey((char *)ops_memory_get_data(buf),ops_memory_get_length(buf)) ;
//ops_teardown_memory_write(cinfo,buf);
ops_teardown_memory_write(cinfo,buf);
ops_keydata_free(key) ;
return true ;
return akey ;
}
std::string PGPHandler::SaveCertificateToString(const PGPIdType& id,bool include_signatures)
{
const ops_keydata_t *key = ops_keyring_find_key_by_id(_pubring,id.toByteArray());
if(key == NULL)
{
std::cerr << "Cannot output key " << id.toStdString() << ": not found in keyring." << std::endl;
return "" ;
}
return makeRadixEncodedPGPKey(key) ;
}