mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-28 08:07:31 -04:00
added test to read and display key from file
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5270 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d5675a0d59
commit
b3b7fc3475
3 changed files with 876 additions and 5 deletions
54
libretroshare/src/tests/pgp/test_key_parsing.cc
Normal file
54
libretroshare/src/tests/pgp/test_key_parsing.cc
Normal file
|
@ -0,0 +1,54 @@
|
|||
// COMPILE_LINE: g++ -o test_key_parsing test_key_parsing.cc -g -I../../../openpgpsdk/include -I../ -L../lib ../../../openpgpsdk/src/lib/libops.a -lssl -lcrypto -lbz2
|
||||
//
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <openpgpsdk/std_print.h>
|
||||
#include <openpgpsdk/keyring_local.h>
|
||||
#include <openpgpsdk/util.h>
|
||||
}
|
||||
|
||||
#include "argstream.h"
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// test PGPHandler
|
||||
//
|
||||
// 0 - init
|
||||
|
||||
bool armoured = false ;
|
||||
std::string keyfile ;
|
||||
|
||||
argstream as(argc,argv) ;
|
||||
|
||||
as >> parameter('i',"input-key",keyfile,"input key file.",true)
|
||||
>> option('a',"armoured",armoured,"input is armoured")
|
||||
>> help() ;
|
||||
|
||||
as.defaultErrorHandling() ;
|
||||
|
||||
ops_keyring_t *kr = (ops_keyring_t*)malloc(sizeof(ops_keyring_t)) ;
|
||||
kr->nkeys = 0 ;
|
||||
kr->nkeys_allocated = 0 ;
|
||||
kr->keys = 0 ;
|
||||
|
||||
if(ops_false == ops_keyring_read_from_file(kr,armoured, keyfile.c_str()))
|
||||
throw std::runtime_error("PGPHandler::readKeyRing(): cannot read key file. File corrupted, or missing/superfluous armour parameter.") ;
|
||||
|
||||
for(int i=0;i<kr->nkeys;++i)
|
||||
ops_print_public_keydata_verbose(&kr->keys[i]) ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Caught exception: " << e.what() << std::endl;
|
||||
return 1 ;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue