mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-22 07:41:20 -04:00
- added new class for certificate handling. Has two input/output format: classical pgp armoured block (old) and
new pure radix format, which is easier to parse and much more robust. - added test program to load/parse certificates in both formats. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5403 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7009b46461
commit
bc07b16737
8 changed files with 567 additions and 24 deletions
|
@ -10,13 +10,16 @@ OPENPGP_INCLUDE_DIR = ../../../../openpgpsdk/src
|
|||
include $(RS_TOP_DIR)/tests/scripts/config.mk
|
||||
###############################################################
|
||||
|
||||
TESTOBJ = test_pgp_handler.o test_pgp_signature_parsing.o test_key_parsing.o
|
||||
TESTS = test_pgp_handler test_pgp_signature_parsing test_key_parsing
|
||||
TESTOBJ = test_pgp_handler.o test_pgp_signature_parsing.o test_key_parsing.o test_certificate.o
|
||||
TESTS = test_pgp_handler test_pgp_signature_parsing test_key_parsing test_certificate
|
||||
|
||||
#rsbaseitem_test
|
||||
|
||||
all: tests
|
||||
|
||||
test_certificate : test_certificate.o
|
||||
$(CC) $(CFLAGS) -o test_certificate test_certificate.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2
|
||||
|
||||
test_pgp_handler : test_pgp_handler.o
|
||||
$(CC) $(CFLAGS) -o test_pgp_handler test_pgp_handler.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2
|
||||
|
||||
|
|
54
libretroshare/src/tests/pgp/test_certificate.cc
Normal file
54
libretroshare/src/tests/pgp/test_certificate.cc
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <fstream>
|
||||
|
||||
#include "argstream.h"
|
||||
#include <pgp/rscertificate.h>
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
argstream as(argc,argv) ;
|
||||
std::string keyfile ;
|
||||
|
||||
as >> parameter('i',"input",keyfile,"input certificate file (old or new formats)",true)
|
||||
>> help() ;
|
||||
|
||||
as.defaultErrorHandling() ;
|
||||
|
||||
FILE *f = fopen(keyfile.c_str(),"rb") ;
|
||||
|
||||
if(f == NULL)
|
||||
throw std::runtime_error("Cannot open file. Sorry.") ;
|
||||
|
||||
std::string res ;
|
||||
char c ;
|
||||
|
||||
while( (c = fgetc(f)) != EOF)
|
||||
res += c ;
|
||||
|
||||
fclose(f) ;
|
||||
|
||||
std::cerr << "Read this string from the file:" << std::endl;
|
||||
std::cerr << "==========================================" << std::endl;
|
||||
std::cerr << res << std::endl;
|
||||
std::cerr << "==========================================" << std::endl;
|
||||
std::cerr << "Parsing..." << std::endl;
|
||||
|
||||
RsCertificate cert(res) ;
|
||||
|
||||
std::cerr << "Output from certificate:" << std::endl;
|
||||
|
||||
std::cerr << cert.toStdString_oldFormat() << std::endl ;
|
||||
|
||||
std::cerr << "Output from certificate (new format):" << std::endl;
|
||||
std::cerr << cert.toStdString() << std::endl ;
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception never handled: " << e.what() << std::endl;
|
||||
return 1 ;
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue