c++ binding now supports vaults and encryption, added test program

This commit is contained in:
TLINDEN
2013-12-01 16:16:53 +01:00
parent dc5f74e9be
commit aa140ed1c8
9 changed files with 465 additions and 109 deletions

57
tests/cpptest.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include <pcp++.h>
#include <string>
using namespace pcp;
using namespace std;
void pr(string name, unsigned char *data, size_t len) {
int i;
cout << name << ": ";
for ( i = 0;i < len;++i)
printf("%02x", (unsigned int) data[i]);
cout << endl;
}
int main() {
try {
Key A = Key("a", "alicia", "alicia@local");
Key B = Key("b", "bobby", "bobby@local");
PubKey PA = A.get_public();
PubKey PB = B.get_public();
A.decrypt("a");
B.decrypt("b");
pr("A secret", A.K->secret, 32);
pr("A public", A.K->pub, 32);
pr("B secret", B.K->secret, 32);
pr("B public", B.K->pub, 32);
string cipher = A.encrypt(PB, "Hallo");
ResultSet res = B.decrypt(PA, cipher);
cout << " Input: Hallo" << endl;
cout << "Cipher: " << cipher << endl;
cout << " Clear: " << res.String << endl;
Vault vault = Vault("vcpp");
vault.key_add(A);
vault.pubkey_add(PB);
KeyMap m = vault.keys();
for(KeyIterator it=m.begin(); it != m.end(); ++it) {
cout << "id: " << it->first << endl;
}
PubKeyMap p = vault.pubkeys();
for(PubKeyIterator it=p.begin(); it != p.end(); ++it) {
cout << "id: " << it->first << endl;
}
}
catch (pcp::exception &E) {
cerr << "Catched exception: " << E.what() << endl;
}
return 0;
}