diff --git a/bindings/cpp/crypto++.h b/bindings/cpp/crypto++.h index f9a897f..6471353 100644 --- a/bindings/cpp/crypto++.h +++ b/bindings/cpp/crypto++.h @@ -44,8 +44,8 @@ namespace pcp { Vault vault; // constructors - Crypto(PcpContext C, Key &skey, PubKey &pkey); - Crypto(PcpContext C, Vault &v, Key &skey, PubKey &pkey); + Crypto(PcpContext &C, Key &skey, PubKey &pkey); + Crypto(PcpContext &C, Vault &v, Key &skey, PubKey &pkey); // PK encryption methods // sender pubkey is P diff --git a/bindings/cpp/crypto.cpp b/bindings/cpp/crypto.cpp index 784cc36..e07b5f6 100644 --- a/bindings/cpp/crypto.cpp +++ b/bindings/cpp/crypto.cpp @@ -25,7 +25,7 @@ using namespace std; using namespace pcp; -Crypto::Crypto(PcpContext C, Key &skey, PubKey &pkey) { +Crypto::Crypto(PcpContext &C, Key &skey, PubKey &pkey) { P = pkey; S = skey; PTX = C; @@ -33,7 +33,7 @@ Crypto::Crypto(PcpContext C, Key &skey, PubKey &pkey) { pcphash_add(PTX.ptx, P.K, PCP_KEY_TYPE_PUBLIC); } -Crypto::Crypto(PcpContext C, Vault &v, Key &skey, PubKey &pkey) { +Crypto::Crypto(PcpContext &C, Vault &v, Key &skey, PubKey &pkey) { P = pkey; S = skey; PTX = C; @@ -47,6 +47,7 @@ bool Crypto::encrypt(FILE *in, FILE *out, bool sign) { //HASH_ADD_STR( pubhash, id, P.K); Pcpstream *pin = ps_new_file(in); Pcpstream *pout = ps_new_file(out); + ptx_dump(PTX.ptx); size_t clen = pcp_encrypt_stream(PTX.ptx, pin, pout, S.K, pubhash, sign); if(clen <= 0) throw exception(PTX); @@ -58,6 +59,7 @@ bool Crypto::encrypt(FILE *in, FILE *out, bool sign) { bool Crypto::decrypt(FILE *in, FILE *out, bool verify) { Pcpstream *pin = ps_new_file(in); Pcpstream *pout = ps_new_file(out); + ptx_dump(PTX.ptx); if(pcp_decrypt_stream(PTX.ptx, pin, pout, S.K, NULL, verify) <= 0) throw exception(PTX); ps_close(pin); diff --git a/bindings/cpp/helpers++.h b/bindings/cpp/helpers++.h index 9644396..c418070 100644 --- a/bindings/cpp/helpers++.h +++ b/bindings/cpp/helpers++.h @@ -37,8 +37,9 @@ namespace pcp { class exception : public std::runtime_error { private: PCPCTX *ptx; - std::string getfatals() { + std::string getfatals(PcpContext &P) { std::string msg; + PCPCTX *ptx = P.ptx; if(ptx->pcp_errset == 1) { msg = ptx->pcp_err; } @@ -50,8 +51,8 @@ namespace pcp { return msg; } public: - exception(PcpContext P, const std::string & msg) : runtime_error(msg) { ptx = P.ptx; } - exception(PcpContext P) : runtime_error(getfatals()) { ptx = P.ptx; } + exception(PcpContext &P, const std::string & msg) : runtime_error(msg) { ptx = P.ptx; } + exception(PcpContext &P) : runtime_error(getfatals(P)) { } }; diff --git a/bindings/cpp/key++.h b/bindings/cpp/key++.h index 16dfbb3..c63a65c 100644 --- a/bindings/cpp/key++.h +++ b/bindings/cpp/key++.h @@ -43,11 +43,11 @@ namespace pcp { PcpContext PTX; // constructors - PubKey(PcpContext P); + PubKey(PcpContext &P); PubKey(); - PubKey(PcpContext P, pcp_pubkey_t *k); - PubKey(PcpContext P, pcp_pubkey_t *k, bool store); - PubKey(PcpContext P, std::string &z85encoded); + PubKey(PcpContext &P, pcp_pubkey_t *k); + PubKey(PcpContext &P, pcp_pubkey_t *k, bool store); + PubKey(PcpContext &P, std::string &z85encoded); // destructors ~PubKey(); @@ -79,15 +79,15 @@ namespace pcp { // constructors Key(); - Key(PcpContext P); - Key(PcpContext P, bool generate); - Key(PcpContext P, const std::string& passphrase); - Key(PcpContext P, const std::string& passphrase, + Key(PcpContext &P); + Key(PcpContext &P, bool generate); + Key(PcpContext &P, const std::string& passphrase); + Key(PcpContext &P, const std::string& passphrase, const std::string& owner, const std::string& mail); - Key(PcpContext P, pcp_key_t *k); - Key(PcpContext P, pcp_key_t *k, bool store); - Key(PcpContext P, std::string &z85encoded, std::string& passphrase); + Key(PcpContext &P, pcp_key_t *k); + Key(PcpContext &P, pcp_key_t *k, bool store); + Key(PcpContext &P, std::string &z85encoded, std::string& passphrase); // destructor ~Key(); diff --git a/bindings/cpp/key.cpp b/bindings/cpp/key.cpp index e2e6375..e7d51e2 100644 --- a/bindings/cpp/key.cpp +++ b/bindings/cpp/key.cpp @@ -30,13 +30,13 @@ Key::Key() { K = NULL; } -Key::Key(PcpContext P) { +Key::Key(PcpContext &P) { stored = false; K = NULL; PTX = P; } -Key::Key(PcpContext P, bool generate) { +Key::Key(PcpContext &P, bool generate) { stored = false; if(generate) K = pcpkey_new(); @@ -45,14 +45,14 @@ Key::Key(PcpContext P, bool generate) { PTX = P; } -Key::Key(PcpContext P, const string& passphrase) { +Key::Key(PcpContext &P, const string& passphrase) { stored = false; K = pcpkey_new(); K = pcpkey_encrypt(PTX.ptx, K, (char *)passphrase.c_str()); PTX = P; } -Key::Key(PcpContext P, const string& passphrase, +Key::Key(PcpContext &P, const string& passphrase, const string& owner, const string& mail) { stored = false; @@ -64,19 +64,19 @@ Key::Key(PcpContext P, const string& passphrase, PTX = P; } -Key::Key(PcpContext P, pcp_key_t *k) { +Key::Key(PcpContext &P, pcp_key_t *k) { stored = false; K = k; PTX = P; } -Key::Key(PcpContext P, pcp_key_t *k, bool store) { +Key::Key(PcpContext &P, pcp_key_t *k, bool store) { stored = new bool(store); K = k; PTX = P; } -Key::Key(PcpContext P, string &z85encoded, string &passphrase) { +Key::Key(PcpContext &P, string &z85encoded, string &passphrase) { stored = false; PTX = P; @@ -214,26 +214,26 @@ PubKey::PubKey() { K = NULL; } -PubKey::PubKey(PcpContext P) { +PubKey::PubKey(PcpContext &P) { stored = false; K = NULL; PTX = P; } -PubKey::PubKey(PcpContext P, pcp_pubkey_t *k) { +PubKey::PubKey(PcpContext &P, pcp_pubkey_t *k) { stored = false; K = k; PTX = P; } -PubKey::PubKey(PcpContext P, pcp_pubkey_t *k, bool store) { +PubKey::PubKey(PcpContext &P, pcp_pubkey_t *k, bool store) { stored = store; K = k; PTX = P; } -PubKey::PubKey(PcpContext P, string &z85encoded) { +PubKey::PubKey(PcpContext &P, string &z85encoded) { stored = false; PTX = P; diff --git a/bindings/cpp/ptx++.h b/bindings/cpp/ptx++.h index 88dca3b..99b28cc 100644 --- a/bindings/cpp/ptx++.h +++ b/bindings/cpp/ptx++.h @@ -39,8 +39,9 @@ namespace pcp { // constructors PcpContext(); - // destructors - ~PcpContext(); + // clean up, wo don't do it in the destructor, + // since it will be called multiple times otherwise + void done(); }; }; diff --git a/bindings/cpp/ptx.cpp b/bindings/cpp/ptx.cpp index de30aa9..5657e85 100644 --- a/bindings/cpp/ptx.cpp +++ b/bindings/cpp/ptx.cpp @@ -28,7 +28,7 @@ PcpContext::PcpContext() { ptx = ptx_new(); } -PcpContext::~PcpContext() { +void PcpContext::done() { ptx_clean(ptx); } diff --git a/bindings/cpp/sign++.h b/bindings/cpp/sign++.h index b7a47da..a62da3f 100644 --- a/bindings/cpp/sign++.h +++ b/bindings/cpp/sign++.h @@ -48,10 +48,10 @@ namespace pcp { PcpContext PTX; // constructors - Signature(PcpContext P, Key &skey); // sign only - Signature(PcpContext P,PubKey &pkey); // verify only - Signature(PcpContext P,Key &skey, PubKey &pkey); // both/bulk - Signature(PcpContext P,Vault &v); + Signature(PcpContext &P, Key &skey); // sign only + Signature(PcpContext &P,PubKey &pkey); // verify only + Signature(PcpContext &P,Key &skey, PubKey &pkey); // both/bulk + Signature(PcpContext &P,Vault &v); // destructor ~Signature(); diff --git a/bindings/cpp/sign.cpp b/bindings/cpp/sign.cpp index b0aa2b6..a71b79f 100644 --- a/bindings/cpp/sign.cpp +++ b/bindings/cpp/sign.cpp @@ -24,26 +24,26 @@ using namespace std; using namespace pcp; -Signature::Signature(PcpContext P, Key &skey) { +Signature::Signature(PcpContext &P, Key &skey) { S = skey; PTX = P; havevault = false; } -Signature::Signature(PcpContext C,PubKey &pkey) { +Signature::Signature(PcpContext &C,PubKey &pkey) { P = pkey; PTX = C; havevault = false; } -Signature::Signature(PcpContext C,Key &skey, PubKey &pkey) { +Signature::Signature(PcpContext &C,Key &skey, PubKey &pkey) { P = pkey; S = skey; PTX = C; havevault = false; } -Signature::Signature(PcpContext P,Vault &v) { +Signature::Signature(PcpContext &P,Vault &v) { vault = v; havevault = true; PTX = P; diff --git a/bindings/cpp/vault++.h b/bindings/cpp/vault++.h index b74bcb5..7829815 100644 --- a/bindings/cpp/vault++.h +++ b/bindings/cpp/vault++.h @@ -51,8 +51,8 @@ namespace pcp { public: // constructors Vault(); - Vault(PcpContext P); - Vault(PcpContext P, std::string filename); + Vault(PcpContext &P); + Vault(PcpContext &P, std::string filename); // destructor ~Vault(); diff --git a/bindings/cpp/vault.cpp b/bindings/cpp/vault.cpp index ba5ca5a..aa07a15 100644 --- a/bindings/cpp/vault.cpp +++ b/bindings/cpp/vault.cpp @@ -28,12 +28,12 @@ Vault::Vault() { V = NULL; } -Vault::Vault(PcpContext P) { +Vault::Vault(PcpContext &P) { V = NULL; PTX = P; } -Vault::Vault(PcpContext P, string filename) { +Vault::Vault(PcpContext &P, string filename) { PTX = P; V = pcpvault_init(PTX.ptx, (char *)filename.c_str()); if (V == NULL)